Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basketbuilderrest.php
1<?php
2
3
9
16{
17 protected function getDelegate($orderId)
18 {
19 return (int)$orderId > 0 ? new BasketBuildeRestExist($this) : new BasketBuilderNew($this);
20 }
21
22 public static function isBasketItemNew($basketCode)
23 {
24 return (mb_strpos($basketCode, 'n') === 0);
25 }
26 // ,
27 // ..
28 protected function getExistsItem($moduleId, $productId, array $properties = array())
29 {
30 return null;
31 }
32
34 {
35 return $this;
36 }
37
38 public function itemsDataPreparation()
39 {
40 foreach($this->formData["PRODUCT"] as $basketCode => $productData)
41 {
42 if($productData["IS_SET_ITEM"] == "Y")
43 continue;
44
45 if(!isset($productData["PROPS"]) || !is_array($productData["PROPS"]))
46 $productData["PROPS"] = array();
47
48 if(self::isBasketItemNew($basketCode) == true)
49 {
50 $item = $this->createItem($basketCode, $productData);
51 }
52 else
53 {
55 $item = $this->getItemFromBasket($basketCode, $productData);
56
57 if(is_null($item))
58 {
59 $this->builder->getErrorsContainer()->addError(new Error('basketItem - is not exists ['.$basketCode.']'));
60 throw new BuildingException();
61 }
62 }
63
64 foreach ($productData["PROPS"] as &$prop)
65 {
66 unset($prop['BASKET_ID']); // bug \Bitrix\Sale\BasketPropertiesCollectionBase::redefine()
67 }
68
69 if(!empty($productData["PROPS"]) && is_array($productData["PROPS"]))
70 {
72 $property = $item->getPropertyCollection();
73
74 if(!$property->isPropertyAlreadyExists($productData["PROPS"]))
75 $property->setProperty($productData["PROPS"]);
76 }
77 }
78
79 return $this;
80 }
81
82 public function basketCodeMap()
83 {
84 return $this;
85 }
86
87 public function setItemsFields()
88 {
89 $basket = $this->getBasket();
90
92 foreach ($basket as $basketItem)
93 {
94 $basketCode = $basketItem->getBasketCode();
95 if(isset($this->formData['PRODUCT'][$basketCode]))
96 {
97 $itemFields = $this->formData['PRODUCT'][$basketCode];
98
99 if(isset($itemFields['OFFER_ID']))
100 {
101 $itemFields['PRODUCT_ID'] = $itemFields['OFFER_ID'];
102 }
103
104 if(isset($itemFields['PRICE']))
105 {
106 $itemFields['CUSTOM_PRICE'] = 'Y';
107 }
108
109 $fields = array_intersect_key($itemFields, array_flip($basketItem::getAvailableFields()));
110
111 $r = $basketItem->setFields($fields);
112 if($r->isSuccess() == false)
113 {
114 $this->getErrorsContainer()->addErrors($r->getErrors());
115 throw new BuildingException();
116 }
117 }
118 }
119
120 return $this;
121 }
122
123 public function finalActions()
124 {
125 $basket = $this->getBasket();
126
128 foreach ($basket as $basketItem)
129 {
130 if(self::isBasketItemNew($basketItem->getBasketCode()))
131 {
132 $strategy = RefreshFactory::createSingle($basketItem->getBasketCode());
133 $basket->refresh($strategy);
134 }
135 }
136 return $this;
137 }
138}
getExistsItem($moduleId, $productId, array $properties=array())