21 Sale\BasketPropertyItem::class,
23 function($className, $id) {
27 $basketPropertyClass = $registry->getBasketPropertyItemClassName();
29 $b = $basketPropertyClass::getList([
30 'select'=>[
'BASKET_ID'],
34 if($bRow = $b->fetch())
37 $basketClass = $registry->getBasketClassName();
39 $r = $basketClass::getList([
40 'select'=>[
'ORDER_ID'],
41 'filter'=>[
'ID'=>$bRow[
'BASKET_ID']]
44 if($row = $r->fetch())
47 $orderClass = $registry->getOrderClassName();
49 $order = $orderClass::load($row[
'ORDER_ID']);
50 $basket = $order->getBasket()->getItemByBasketCode($bRow[
'BASKET_ID']);
53 $property = $basket->getPropertyCollection()->getItemById($id);
62 $this->
addError(
new Error(
'basket property is not exists', 200240400003));
71 $entity = new \Bitrix\Sale\Rest\Entity\BasketProperties();
72 return [
'BASKET_PROPERTIES'=>$entity->prepareFieldInfos(
79 $select = empty($select) ? [
'*'] : $select;
80 $order = empty($order) ? [
'ID' =>
'ASC'] : $order;
82 $items = \Bitrix\Sale\Internals\BasketPropertyTable::getList(
88 'limit' => $pageNavigation->
getLimit(),
92 return new Page(
'BASKET_PROPERTIES', $items,
function() use ($filter)
95 \
Bitrix\
Sale\Internals\BasketPropertyTable::getList([
'filter'=>$filter])->fetchAll()
102 return [
'BASKET_PROPERTY'=>$this->
get($basketProperty)];
105 public function addAction(array $fields)
109 $basketId = $fields[
'BASKET_ID'];
111 unset($fields[
'BASKET_ID']);
116 $basketClass = $registry->getBasketClassName();
118 $r = $basketClass::getList([
119 'select'=>[
'ORDER_ID'],
120 'filter'=>[
'ID'=>$basketId]
123 if($row = $r->fetch())
126 $orderClass = $registry->getOrderClassName();
128 $order = $orderClass::load($row[
'ORDER_ID']);
129 $basketItem = $order->getBasket()->getItemByBasketCode($basketId);
133 $propertyCollection = $basketItem->getPropertyCollection();
135 $basketProperty = $propertyCollection->createItem();
136 $result = $basketProperty->setFields($fields);
138 if($result->isSuccess() && $result->hasWarnings() ==
false)
140 $r = $this->save($basketProperty);
143 $result->addErrors($r->getErrors());
149 $result->addError(
new Error(
'basket item not exists', 200240400001));
154 $result->addError(
new Error(
'basket item not exists', 200240400002));
157 if(!$result->isSuccess())
162 elseif($result->hasWarnings())
164 $this->
addErrors($result->getWarnings());
169 return [
'BASKET_PROPERTY'=>$this->
get($basketProperty)];
175 $r = $basketProperty->setFields($fields);
177 if($r->isSuccess() ==
false)
182 elseif($r->hasWarnings())
189 $r = $this->save($basketProperty);
197 return [
'BASKET_PROPERTY'=>$this->
get($basketProperty)];
204 $r = $basketProperty->delete();
206 if($r->isSuccess() ==
false)
211 elseif($r->hasWarnings())
218 $r = $this->save($basketProperty);
235 $properties = $basketProperty->getCollection();
236 $basketItem = $properties->getBasketItem();
238 $basket = $basketItem->getCollection();
240 $order = $basket->getOrder();
242 $basketItems = $this->toArray($order, $fields)[
'ORDER'][
'BASKET_ITEMS'];
243 foreach ($basketItems as $item)
245 foreach ($item[
'PROPERTIES'] as $property)
247 if($property[
'ID']==$basketProperty->getId())
256 private function save(\
Bitrix\
Sale\BasketPropertyItem $basketProperty)
258 $result =
new Result();
260 $properties = $basketProperty->getCollection();
261 $basketItem = $properties->getBasketItem();
263 $basket = $basketItem->getCollection();
265 $order = $basket->getOrder();
270 $result->addErrors($r->getErrors());
272 elseif($r->hasWarnings())
274 $result->addErrors($r->getWarnings());
getPrimaryAutoWiredParameter()