21 Sale\BasketItem::class,
23 function($className, $id) {
27 $basketClass = $registry->getBasketClassName();
29 $r = $basketClass::getList([
30 'select'=>[
'ORDER_ID'],
34 if($row = $r->fetch())
37 $orderClass = $registry->getOrderClassName();
39 $order = $orderClass::load($row[
'ORDER_ID']);
40 $basket = $order->getBasket()->getItemByBasketCode($id);
48 $this->
addError(
new Error(
'basket item is not exists', 200140400001));
59 $entity = new \Bitrix\Sale\Rest\Entity\BasketItem();
60 return [
'BASKET_ITEM'=>$entity->prepareFieldInfos(
67 $entity = new \Bitrix\Sale\Rest\Entity\BasketItem();
68 return [
'BASKET_ITEM'=>$entity->prepareFieldInfos(
69 $entity->getFieldsCatalogProduct()
75 $builder = $this->getBuilder();
76 $builder->buildEntityBasket($fields);
78 if($builder->getErrorsContainer()->getErrorCollection()->count()>0)
80 $this->
addErrors($builder->getErrorsContainer()->getErrors());
84 $order = $builder->getOrder();
94 return [
'BASKET_ITEMS'=>$this->
toArray($order)[
'ORDER'][
'BASKET_ITEMS']];
97 public function addAction(array $fields)
101 $data[
'ORDER'][
'ID'] = $fields[
'ORDER_ID'];
102 $data[
'ORDER'][
'BASKET_ITEMS'] = [$fields];
104 $r = $this->addValidate($fields);
107 $builder = $this->getBuilder(
109 'deleteBasketItemsIfNotExists' =>
false
112 $builder->buildEntityBasket($data);
114 if($builder->getErrorsContainer()->getErrorCollection()->count()>0)
116 $this->addErrors($builder->getErrorsContainer()->getErrors());
120 $order = $builder->getOrder();
127 if($basketItem->getId() <= 0)
129 $idx = $basketItem->getInternalIndex();
144 $entity = $order->getBasket()->getItemByIndex($idx);
145 return new Page(
'BASKET_ITEM', $this->
get($entity), 1);
150 $fields[
'MODULE'] =
'catalog';
151 $fields[
'PRODUCT_PROVIDER_CLASS'] =
'\Bitrix\Catalog\Product\CatalogProvider';
153 return $this->addAction($fields);
160 $fields[
'ID'] = $basketItem->getBasketCode();
161 $fields[
'ORDER_ID'] = $basketItem->getCollection()->getOrderId();
163 $data[
'ORDER'][
'ID'] = $fields[
'ORDER_ID'];
164 $data[
'ORDER'][
'BASKET_ITEMS'] = [$fields];
166 $builder = $this->getBuilder(
168 'deleteBasketItemsIfNotExists' =>
false
172 $builder->buildEntityBasket($data);
174 if($builder->getErrorsContainer()->getErrorCollection()->count()>0)
176 $this->addErrors($builder->getErrorsContainer()->getErrors());
180 $order = $builder->getOrder();
185 $this->addErrors($r->getErrors());
190 $entity = $order->getBasket()->getItemById($basketItem->getId());
191 return new Page(
'BASKET_ITEM', $this->
get($entity), 1);
196 return $this->updateAction($basketItem, $fields);
202 return [
'BASKET_ITEM' => $this->
get($basketItem)];
208 $basketCollection = $basketItem->getCollection();
209 $order = $basketCollection->getOrder();
211 $r = $basketItem->delete();
216 $this->addErrors($r->getErrors());
218 return $r->isSuccess();
221 public function listAction(
PageNavigation $pageNavigation, array $select = [], array $filter = [], array $order = []): Page
223 $select = empty($select) ? [
'*'] : $select;
224 $order = empty($order)? [
'ID' =>
'ASC'] : $order;
229 $basketClass = $registry->getBasketClassName();
231 $items = $basketClass::getList(
236 'offset' => $pageNavigation->
getOffset(),
237 'limit' => $pageNavigation->
getLimit(),
241 return new Page(
'BASKET_ITEMS', $items,
function() use ($filter)
246 $basketClass = $registry->getBasketClassName();
249 $basketClass::getList([
'filter'=>$filter])->fetchAll()
256 return $basketItem->canBuy()?
'Y':
'N';
261 return $basketItem->getBasePrice();
266 return $basketItem->getBasePriceWithVat();
271 return $basketItem->getCurrency();
276 return $basketItem->getDefaultPrice();
281 return $basketItem->getDiscountPrice();
286 return $basketItem->getFinalPrice();
291 return $basketItem->getInitialPrice();
296 return $basketItem->getPrice();
301 return $basketItem->getPriceWithVat();
306 return $basketItem->getProductId();
311 return $basketItem->getQuantity();
316 return $basketItem->getReservedQuantity();
321 return $basketItem->getVat();
326 return $basketItem->getVatRate();
331 return $basketItem->getWeight();
336 return $basketItem->isBarcodeMulti()?
'Y':
'N';
341 return $basketItem->isCustom()?
'Y':
'N';
346 return $basketItem->isCustomPrice()?
'Y':
'N';
351 return $basketItem->isDelay()?
'Y':
'N';
356 return $basketItem->isVatInPrice()?
'Y':
'N';
381 $items = $this->
toArray($basketItem->getCollection()->getOrder(), $fields)[
'ORDER'][
'BASKET_ITEMS'];
382 foreach ($items as $item)
384 if($item[
'ID'] == $basketItem->getId())
395 Loader::includeModule(
'catalog');
397 if(isset($fields[
'BASKET_ITEMS']))
400 foreach ($fields[
'BASKET_ITEMS'] as $item)
402 if(isset($item[
'PRODUCT_ID']))
404 $item[
'OFFER_ID'] = $item[
'PRODUCT_ID'];
405 unset($item[
'PRODUCT_ID']);
417 $item[
'PROPS'] = isset($item[
'PROPERTIES'])? $item[
'PROPERTIES']:[];
418 unset($item[
'PROPERTIES']);
420 $basketCode = isset($item[
'ID'])? $item[
'ID']:
'n'.++$i;
421 if(isset($item[
'ID']))
424 $data[$basketCode] = $item;
426 unset($fields[
'BASKET_ITEMS']);
429 return is_array($data)?[
'PRODUCT'=>$data]:[];
435 || $name ==
'getbaseprice'
436 || $name ==
'getbasepricewithvat'
437 || $name ==
'getcurrency'
438 || $name ==
'getdefaultprice'
439 || $name ==
'getdiscountprice'
440 || $name ==
'getfinalprice'
441 || $name ==
'getinitialprice'
442 || $name ==
'getprice'
443 || $name ==
'getpricewithvat'
444 || $name ==
'getproductid'
445 || $name ==
'getquantity'
446 || $name ==
'getreservedquantity'
448 || $name ==
'getvatrate'
449 || $name ==
'getweight'
450 || $name ==
'isbarcodemulti'
451 || $name ==
'iscustommulti'
452 || $name ==
'iscustomprice'
453 || $name ==
'isdelay'
454 || $name ==
'isvatinprice'
455 || $name ==
'getfieldscatalogproduct'
458 $r = $this->checkReadPermissionEntity();
460 elseif ($name ==
'addcatalogproduct' || $name ==
'updatecatalogproduct')
462 $r = $this->checkCreatePermissionEntity();
466 $r = parent::checkPermissionEntity($name);
472 protected function addValidate($fields)
476 if(isset($fields[
'ORDER_ID']) ==
false || intval($fields[
'ORDER_ID'])<=0)
478 $result->addError(
new Error(
'Required fields: fields[ORDER_ID]'));
484 $orderClass = $registry->getOrderClassName();
486 $order = $orderClass::load($fields[
'ORDER_ID']);
487 if($order->getCurrency() <> $fields[
'CURRENCY'])
489 $result->addError(
new Error(
'Currency must be the currency of the order'));
getPrimaryAutoWiredParameter()