Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basketbuilderexist.php
1<?
3
5
7{
9 protected $builder = null;
10
12 {
13 $this->builder = $builder;
14 }
15
29 public function getItemFromBasket($basketCode, $productData)
30 {
31 $item = $this->builder->getBasket()->getItemByBasketCode($basketCode);
32
33 //sku was changed
34 if($item == null && $basketCode != BasketBuilder::BASKET_CODE_NEW)
35 {
36 if($item = $this->builder->getBasket()->getItemByBasketCode($basketCode))
37 {
38 $res = $item->delete();
39
40 if(!$res->isSuccess())
41 {
42 $this->builder->getErrorsContainer()->addErrors($res->getErrors());
43 throw new BuildingException();
44 }
45
46 $item = null;
47 }
48 }
49
50 return $item;
51 }
52
58 public function setItemData($basketCode, &$productData, &$item)
59 {
60 if ($basketCode != $productData["BASKET_CODE"])
61 $productData["BASKET_CODE"] = $item->getBasketCode();
62
63 if(isset($productData["OFFER_ID"]) && intval($productData["OFFER_ID"]) > 0)
64 $productData["PRODUCT_ID"] = $productData["OFFER_ID"];
65
66 $itemFields = array_intersect_key($productData, array_flip($item::getAvailableFields()));
67
68 if(isset($itemFields["MEASURE_CODE"]) && $itemFields["MEASURE_CODE"] <> '')
69 {
70 $measures = $this->builder->getCatalogMeasures();
71
72 if(isset($measures[$itemFields["MEASURE_CODE"]]) && $measures[$itemFields["MEASURE_CODE"]] <> '')
73 $itemFields["MEASURE_NAME"] = $measures[$itemFields["MEASURE_CODE"]];
74 }
75
76 $providerData = [];
77
78 if(!empty($productData["PROVIDER_DATA"]) && !$this->builder->isNeedUpdateNewProductPrice() && CheckSerializedData($productData["PROVIDER_DATA"]))
79 {
80 $providerData = unserialize($productData["PROVIDER_DATA"], ['allowed_classes' => false]);
81 }
82
83 if (is_array($providerData) && !empty($providerData))
84 {
85 $this->builder->sendProductCachedDataToProvider($item, $this->builder->getOrder(), $providerData);
86 }
87
88 if(!empty($productData["SET_ITEMS_DATA"]) && CheckSerializedData($productData["SET_ITEMS_DATA"]))
89 $productData["SET_ITEMS"] = unserialize($productData["SET_ITEMS_DATA"], ['allowed_classes' => false]);
90
91 $this->builder->setBasketItemFields($item, $itemFields);
92 }
93
94 public function finalActions()
95 {
96 if($this->builder->isProductAdded())
97 {
98 $res = $this->builder->getBasket()->refreshData(array('PRICE', 'COUPONS'));
99
100 if (!$res->isSuccess())
101 {
102 $this->builder->getErrorsContainer()->addErrors($res->getErrors());
103 }
104 }
105 }
106}