Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
refreshstrategy.php
1<?php
2
3namespace Bitrix\Sale\Basket;
4
10
12{
19 protected function applyRefreshResult(BasketItemBase $item, $fields)
20 {
21 $bundleItemList = array();
22 if (isset($fields['ITEMS']))
23 {
24 $bundleItemList = $fields['ITEMS'];
25 unset($fields['ITEMS']);
26 }
27
31 if (isset($fields['QUANTITY']))
32 {
33 $delta = $item->getQuantity() - $item->getNotPurchasedQuantity();
34 $fields['QUANTITY'] += max($delta, 0);
35 }
36
37 $result = parent::applyRefreshResult($item, $fields);
38 if ($result->isSuccess())
39 {
40 if ($bundleItemList)
41 {
42 $r = $this->applyBundleRefreshResult($item, $bundleItemList);
43 if (!$r->isSuccess())
44 {
45 $result->addErrors($r->getErrors());
46 }
47 }
48 }
49
50 return $result;
51 }
52
59 protected function applyBundleRefreshResult(BasketItemBase $item, $bundleItemList)
60 {
62 $result = new Result();
63
66 $basketItemClassName = $registry->getBasketItemClassName();
67
69 $bundleCollection = $item->getBundleCollection();
70 $bundleIndexList = array();
72 foreach ($bundleCollection as $bundleItem)
73 {
74 $bundleIndexList[$bundleItem->getBasketCode()] = $bundleItem;
75 }
76
78 foreach ($bundleItemList as $bundleBasketItemData)
79 {
80 if (empty($bundleBasketItemData['MODULE']) || empty($bundleBasketItemData['PRODUCT_ID']))
81 return null;
82
83 $props = array();
84 if (!empty($bundleBasketItemData['PROPS']) && is_array($bundleBasketItemData['PROPS']))
85 {
86 $props = $bundleBasketItemData['PROPS'];
87 }
88
90 $bundleItem = $bundleCollection->getExistsItem($bundleBasketItemData['MODULE'], $bundleBasketItemData['PRODUCT_ID'], $props);
91 if (!$bundleItem)
92 {
93 $bundleItem = $basketItemClassName::create($bundleCollection, $bundleBasketItemData['MODULE'], $bundleBasketItemData['PRODUCT_ID']);
94 }
95
96 $fields = array_intersect_key($bundleBasketItemData, $basketItemClassName::getSettableFieldsMap());
97 $r = $this->applyRefreshResult($item, $fields);
98 if (!$r->isSuccess())
99 {
100 $result->addErrors($r->getErrors());
101 }
102
103 unset($bundleIndexList[$bundleItem->getBasketCode()]);
104 }
105
106 if ($bundleIndexList)
107 {
109 foreach ($bundleIndexList as $bundleItem)
110 {
111 $bundleItem->delete();
112 }
113 }
114
115 return $result;
116 }
117}
applyRefreshResult(BasketItemBase $item, $fields)
static getInstance($type)
Definition registry.php:183