23 function($className, $id) {
28 $shipmentClass = $registry->getShipmentClassName();
30 $r = $shipmentClass::getList([
31 'select'=>[
'ORDER_ID'],
32 'filter'=>[
'ID'=>$id],
35 if($row = $r->fetch())
38 $orderClass = $registry->getOrderClassName();
40 $order = $orderClass::load($row[
'ORDER_ID']);
41 $shipment = $order->getShipmentCollection()->getItemById($id);
49 $this->
addError(
new Error(
'shipment is not exists', 201140400001));
59 $entity = new \Bitrix\Sale\Rest\Entity\Shipment();
60 return [
'SHIPMENT'=>$entity->prepareFieldInfos(
67 $builder = $this->getBuilder();
68 $builder->buildEntityShipments($fields);
70 if($builder->getErrorsContainer()->getErrorCollection()->count()>0)
72 $this->
addErrors($builder->getErrorsContainer()->getErrors());
76 $order = $builder->getOrder();
84 elseif ($r->hasWarnings())
91 return [
'SHIPMENTS'=>$this->toArray($order)[
'ORDER'][
'SHIPMENTS']];
94 public function addAction(array $fields)
98 $data[
'ORDER'][
'ID'] = $fields[
'ORDER_ID'];
99 $data[
'ORDER'][
'SHIPMENTS'] = [$fields];
101 $builder = $this->getBuilder(
103 'deleteShipmentIfNotExists' =>
false,
104 'deleteShipmentItemIfNotExists' =>
false,
107 $builder->buildEntityShipments($data);
109 if($builder->getErrorsContainer()->getErrorCollection()->count()>0)
111 $this->
addErrors($builder->getErrorsContainer()->getErrors());
115 $order = $builder->getOrder();
118 $collection = $order->getShipmentCollection();
120 foreach($collection as $shipment)
122 if($shipment->getId() <= 0)
124 $idx = $shipment->getInternalIndex();
135 elseif ($r->hasWarnings())
142 $entity = $order->getShipmentCollection()->getItemByIndex($idx);
143 return [
'SHIPMENT'=>$this->
get($entity)];
146 public function updateAction(\
Bitrix\
Sale\Shipment $shipment, array $fields)
150 $fields[
'ID'] = $shipment->getId();
151 $fields[
'ORDER_ID'] = $shipment->getParentOrderId();
153 $data[
'ORDER'][
'ID'] = $fields[
'ORDER_ID'];
154 $data[
'ORDER'][
'SHIPMENTS'] = [$fields];
156 $builder = $this->getBuilder(
157 new SettingsContainer([
158 'deleteShipmentIfNotExists' =>
false,
159 'deleteShipmentItemIfNotExists' =>
false,
162 $builder->buildEntityShipments($data);
164 if($builder->getErrorsContainer()->getErrorCollection()->count()>0)
166 $this->
addErrors($builder->getErrorsContainer()->getErrors());
170 $order = $builder->getOrder();
178 elseif($r->hasWarnings())
185 $entity = $order->getShipmentCollection()->getItemById($shipment->getId());
186 return [
'SHIPMENT'=>$this->
get($entity)];
191 $r = $shipment->delete();
192 return $this->save($shipment, $r);
197 return [
'SHIPMENT'=>$this->
get($shipment)];
202 $select = empty($select)? [
'*']:$select;
203 $order = empty($order)? [
'ID'=>
'ASC']:$order;
204 $filter[
'!SYSTEM'] =
'Y';
207 new \Bitrix\Main\Entity\ReferenceField(
209 '\Bitrix\Sale\Internals\StatusTable',
210 array(
'=this.STATUS_ID' =>
'ref.ID')
212 new \Bitrix\Main\Entity\ReferenceField(
214 '\Bitrix\Sale\Delivery\Services\Table',
215 array(
'=this.DELIVERY_ID' =>
'ref.ID')
219 $shipments = \Bitrix\Sale\Shipment::getList(
224 'offset' => $pageNavigation->
getOffset(),
225 'limit' => $pageNavigation->
getLimit(),
226 'runtime' => $runtime,
230 return new Page(
'SHIPMENTS', $shipments,
function() use ($select, $filter, $runtime)
240 return $shipment->getAllowDeliveryDate();
245 return $shipment->getAllowDeliveryUserId();
250 return $shipment->getCompanyId();
255 return $shipment->getCurrency();
260 return $shipment->getDeliveryId();
265 return $shipment->getDeliveryName();
270 return $shipment->getParentOrderId();
275 return $shipment->getPersonTypeId();
280 return $shipment->getPrice();
285 return $shipment->getShippedDate();
290 return $shipment->getShippedUserId();
295 return $shipment->getStoreId();
300 $shipment->getUnshipReason();
305 return $shipment->getVatRate();
310 return $shipment->getVatSum();
315 return $shipment->getWeight();
320 return $shipment->isAllowDelivery()?
'Y':
'N';
325 return $shipment->isCanceled()?
'Y':
'N';
330 return $shipment->isCustomPrice()?
'Y':
'N';
335 return $shipment->isEmpty()?
'Y':
'N';
340 return $shipment->isMarked()?
'Y':
'N';
345 return $shipment->isReserved()?
'Y':
'N';
350 return $shipment->isShipped()?
'Y':
'N';
355 $r=$shipment->setBasePriceDelivery($value, $custom);
356 return $this->save($shipment, $r);
361 $r = $shipment->setField(
'DEDUCTED', $value);
362 return $this->save($shipment, $r);
376 $collection = $shipment->getCollection();
377 $r = $collection->getOrder()->save();
385 return $r->isSuccess();
390 $shipments = $this->toArray($shipment->getCollection()->getOrder(), $fields)[
'ORDER'][
'SHIPMENTS'];
391 foreach ($shipments as $item)
393 if($item[
'ID']==$shipment->getId())
405 if(isset($fields[
"SHIPMENTS"]) && is_array($fields[
"SHIPMENTS"]))
407 foreach($fields[
'SHIPMENTS'] as $k=>$shipmentFormData)
409 $data[$k] = $shipmentFormData;
410 if(isset($shipmentFormData[
'SHIPMENT_ITEMS']))
412 unset($data[$k][
'SHIPMENT_ITEMS']);
415 foreach($shipmentFormData[
'SHIPMENT_ITEMS'] as $item)
419 if(isset($item[
'ID']) && intval($item[
'ID'])>0)
421 $shipmentItem[
'ORDER_DELIVERY_BASKET_ID'] = intval($item[
'ID']);
425 if(isset($item[
'BASKET_ID']))
426 $shipmentItem[
'BASKET_CODE'] = $item[
'BASKET_ID'];
429 if(isset($item[
'XML_ID']))
430 $shipmentItem[
'XML_ID'] = $item[
'XML_ID'];
432 $shipmentItem[
'AMOUNT'] = $item[
'QUANTITY'];
438 $storesInfo = isset($item[
'BARCODE_INFO'])? $item[
'BARCODE_INFO']:[];
439 foreach($storesInfo as &$storeInfo)
441 if(isset($storeInfo[
'BARCODE']))
443 foreach ($storeInfo[
'BARCODE'] as &$barCode)
444 $barCode[
'ID'] = isset($barCode[
'ID'])?$barCode[
'ID']:0;
456 $data[$k][
'PRODUCT'][] = $shipmentItem + [
'BARCODE_INFO'=> $storesInfo];
461 $data[$k][
'PRODUCT'] =
false;
466 return is_array($data)?[
'SHIPMENT'=>$data]:[];
471 if($name ==
'getallowdeliverydate'
472 || $name ==
'getallowdeliveryuserid'
473 || $name ==
'getcompanyid'
474 || $name ==
'getcurrency'
475 || $name ==
'getdeliveryid'
476 || $name ==
'getdeliveryname'
477 || $name ==
'getparentorderid'
478 || $name ==
'getpersontypeid'
479 || $name ==
'getprice'
480 || $name ==
'getphippeddate'
481 || $name ==
'getstoreid'
482 || $name ==
'getunshipreason'
483 || $name ==
'getvatrate'
484 || $name ==
'getvatsum'
485 || $name ==
'getweight'
486 || $name ==
'getshippeddate'
487 || $name ==
'getshippeduserid'
488 || $name ==
'isallowdelivery'
489 || $name ==
'iscanceled'
490 || $name ==
'iscustomprice'
491 || $name ==
'isempty'
492 || $name ==
'ismarked'
493 || $name ==
'isreserved'
494 || $name ==
'isshipped'
497 $r = $this->checkReadPermissionEntity();
499 elseif($name ==
'setbasepricedelivery'
500 || $name ==
'setshipped'
503 $r = $this->checkModifyPermissionEntity();
507 $r = parent::checkPermissionEntity($name);
getPrimaryAutoWiredParameter()
static prepareFields($fields)
getWeightAction(\Bitrix\Sale\Shipment $shipment)
isMarkedAction(\Bitrix\Sale\Shipment $shipment)
setBasePriceDeliveryAction(\Bitrix\Sale\Shipment $shipment, $value, $custom=false)
getAction(\Bitrix\Sale\Shipment $shipment)
getAllowDeliveryDateAction(\Bitrix\Sale\Shipment $shipment)
checkPermissionEntity($name)
getAllowDeliveryUserIdAction(\Bitrix\Sale\Shipment $shipment)
getCompanyIdAction(\Bitrix\Sale\Shipment $shipment)
getVatRateAction(\Bitrix\Sale\Shipment $shipment)
getShippedUserIdAction(\Bitrix\Sale\Shipment $shipment)
getVatSumAction(\Bitrix\Sale\Shipment $shipment)
isCanceledAction(\Bitrix\Sale\Shipment $shipment)
getUnshipReasonAction(\Bitrix\Sale\Shipment $shipment)
isCustomPriceAction(\Bitrix\Sale\Shipment $shipment)
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])
isEmptyAction(\Bitrix\Sale\Shipment $shipment)
getStoreIdAction(\Bitrix\Sale\Shipment $shipment)
getPersonTypeIdAction(\Bitrix\Sale\Shipment $shipment)
isShippedAction(\Bitrix\Sale\Shipment $shipment)
deleteAction(\Bitrix\Sale\Shipment $shipment)
isReservedAction(\Bitrix\Sale\Shipment $shipment)
getDeliveryIdAction(\Bitrix\Sale\Shipment $shipment)
getCurrencyAction(\Bitrix\Sale\Shipment $shipment)
getDeliveryNameAction(\Bitrix\Sale\Shipment $shipment)
getParentOrderIdAction(\Bitrix\Sale\Shipment $shipment)
setShippedAction(\Bitrix\Sale\Shipment $shipment, $value)
getPriceAction(\Bitrix\Sale\Shipment $shipment)
isAllowDeliveryAction(\Bitrix\Sale\Shipment $shipment)
getShippedDateAction(\Bitrix\Sale\Shipment $shipment)
const REGISTRY_TYPE_ORDER
static getList(array $parameters)