Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basketbuildernew.php
1<?
3
7
9{
10 protected $builder = null;
11
12 public function __construct(BasketBuilder $builder)
13 {
14 $this->builder = $builder;
15
16 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
17
19 $basketClass = $registry->getBasketClassName();
20
21 $basket = $basketClass::create($this->builder->getOrder()->getSiteId());
22 $res = $this->builder->getOrder()->setBasket($basket);
23 if(!$res->isSuccess())
24 {
25 $this->builder->getErrorsContainer()->addErrors($res->getErrors());
26 throw new BuildingException();
27 }
28 $fUserId = null;
29
30 if ($this->builder->getOrder()->getUserId() > 0)
31 {
32 $fUserId = Fuser::getIdByUserId($this->builder->getOrder()->getUserId());
33 }
34
35 $basket->setFUserId($fUserId);
36 }
37
47 public function getItemFromBasket($basketCode, $productData)
48 {
49 return $this->builder->getBasket()->getItemByBasketCode($basketCode);
50 }
51
57 public function setItemData($basketCode, &$productData, &$item)
58 {
59 //Let's extract cached provider product data from field
60 if(!empty($productData["PROVIDER_DATA"]) && CheckSerializedData($productData["PROVIDER_DATA"]))
61 {
62 if($providerData = unserialize($productData["PROVIDER_DATA"], ['allowed_classes' => false]))
63 {
64 $this->builder->sendProductCachedDataToProvider($item, $this->builder->getOrder(), $providerData);
65 }
66 }
67
68 if(!empty($productData["SET_ITEMS_DATA"]) && CheckSerializedData($productData["SET_ITEMS_DATA"]))
69 {
70 $productData["SET_ITEMS"] = unserialize($productData["SET_ITEMS_DATA"], ['allowed_classes' => false]);
71 }
72
73 $res = $item->setField("QUANTITY", $item->getField("QUANTITY")+$productData["QUANTITY"]);
74
75 if(!$res->isSuccess())
76 {
77 $this->builder->getErrorsContainer()->addErrors($res->getErrors());
78 throw new BuildingException();
79 }
80 }
81
82 public function finalActions()
83 {
84 //not needed yet for new orders
85 }
86}
static getIdByUserId($userId)
Definition fuser.php:151
setItemData($basketCode, &$productData, &$item)