23 Sale\ShipmentItem::class,
25 function($className, $id) {
30 $shipmentItemClass = $registry->getShipmentItemClassName();
32 $si = $shipmentItemClass::getList([
33 'select'=>[
'ORDER_DELIVERY_ID'],
37 if($siRow = $si->fetch())
40 $shipmentClass = $registry->getShipmentClassName();
42 $r = $shipmentClass::getList([
43 'select'=>[
'ORDER_ID'],
44 'filter'=>[
'ID'=>$siRow[
'ORDER_DELIVERY_ID']]
47 if($row = $r->fetch())
50 $orderClass = $registry->getOrderClassName();
52 $order = $orderClass::load($row[
'ORDER_ID']);
54 $shipment = $order->getShipmentCollection()->getItemById($siRow[
'ORDER_DELIVERY_ID']);
55 $shipmentItem = $shipment->getShipmentItemCollection()->getItemById($id);
64 $this->
addError(
new Error(
'shipment item is not exists', 201240400001));
73 $entity = new \Bitrix\Sale\Rest\Entity\ShipmentItem();
74 return [
'SHIPMENT_ITEM'=>$entity->prepareFieldInfos(
81 return [
'SHIPMENT_ITEM'=>$this->
get($shipmentItem)];
86 $select = empty($select) ? [
'*'] : $select;
87 $order = empty($order) ? [
'ID' =>
'ASC'] : $order;
89 $shipmentItems = \Bitrix\Sale\ShipmentItem::getList(
95 'limit' => $pageNavigation->
getLimit(),
99 return new Page(
'SHIPMENT_ITEMS', $shipmentItems,
function() use ($filter)
111 public function addAction(array $fields)
118 $basketId = $fields[
'BASKET_ID'];
119 $shipmentId = $fields[
'ORDER_DELIVERY_ID'];
121 unset($fields[
'ORDER_DELIVERY_ID'], $fields[
'BASKET_ID']);
124 $basketClass = $registry->getBasketClassName();
126 $r = $basketClass::getList([
127 'select'=>[
'ORDER_ID'],
128 'filter'=>[
'ID'=>$basketId]
131 if($row = $r->fetch())
134 $orderClass = $registry->getOrderClassName();
136 $order = $orderClass::load($row[
'ORDER_ID']);
137 $basketItem = $order->getBasket()->getItemByBasketCode($basketId);
141 $collection = $order->getShipmentCollection();
142 $shipment = $collection->getItemById($shipmentId);
145 $shipmentItemCollection = $shipment->getShipmentItemCollection();
146 if($shipmentItemCollection->isExistBasketItem($basketItem) ==
false)
149 $shipmentItem = $shipmentItemCollection->createItem($basketItem);
150 $result = $shipmentItem->setFields($fields);
151 if($result->isSuccess() && $result->hasWarnings() ==
false)
153 $r = $this->save($shipmentItem);
156 $result->addErrors($r->getErrors());
162 $result->addError(
new Error(
'Duplicate entry for key [basketId, orderDeliveryId]', 201250000001));
167 $result->addError(
new Error(
'shipment not exists', 201240400002));
173 $result->addError(
new Error(
'shipment not exists', 201240400003));
176 if(!$result->isSuccess())
181 elseif($result->hasWarnings())
183 $this->
addErrors($result->getWarnings());
188 return [
'SHIPMENT_ITEM'=>$this->
get($shipmentItem)];
194 $r = $shipmentItem->setFields($fields);
196 if($r->isSuccess() ==
false)
201 elseif($r->hasWarnings())
208 $r = $this->save($shipmentItem);
216 return [
'SHIPMENT_ITEM'=>$this->
get($shipmentItem)];
223 $r = $shipmentItem->delete();
225 if($r->isSuccess() ==
false)
230 elseif($r->hasWarnings())
237 $r = $this->save($shipmentItem);
254 $collectionShipmentItems = $shipmentItem->getCollection();
256 $shipment = $collectionShipmentItems->getShipment();
258 $collectionShipments = $shipment->getCollection();
259 $order = $collectionShipments->getOrder();
261 $shipments = $this->toArray($order, $fields)[
'ORDER'][
'SHIPMENTS'];
262 foreach ($shipments as $shipment)
264 foreach ($shipment[
'SHIPMENT_ITEMS'] as $item)
266 if($item[
'ID']==$shipmentItem->getId())
277 $result =
new Result();
279 $collectionShipmentItems = $shipmentItem->getCollection();
281 $shipment = $collectionShipmentItems->getShipment();
283 $collectionShipments = $shipment->getCollection();
284 $order = $collectionShipments->getOrder();
289 $result->addErrors($r->getErrors());
291 elseif($r->hasWarnings())
293 $result->addErrors($r->getWarnings());
getPrimaryAutoWiredParameter()