Bitrix-D7  20.0.0
Класс ShipmentCollection
Граф наследования:ShipmentCollection:
EntityCollection CollectionBase

Открытые члены

 resetCollection ()
 Deletes all shipments and creates system shipment containing the whole basket. Подробнее...
 
 createItem (Delivery\Services\Base $delivery=null)
 Create new shipment. Подробнее...
 
 deleteItem ($index)
 
 onItemModify (Internals\CollectableEntity $item, $name=null, $oldValue=null, $value=null)
 Processing changes the essence of the shipment fields. Подробнее...
 
 getOrder ()
 Getting entity of the order. Подробнее...
 
 getSystemShipment ()
 Getting the system shipment. Подробнее...
 
 isExistsSystemShipment ()
 Check whether there is a system collection of shipping. Подробнее...
 
 save ()
 Saving data collection. Подробнее...
 
 setOrder (Order $order)
 The attachment order to the collection. Подробнее...
 
 cloneShipment (Shipment $parentShipment, Shipment $childShipment)
 
 isShipped ()
 Is the entire collection shipped. Подробнее...
 
 hasShipped ()
 Is the entire collection shipped. Подробнее...
 
 isMarked ()
 Is the entire collection of marked. Подробнее...
 
 isReserved ()
 Is the entire collection reserved. Подробнее...
 
 isAllowDelivery ()
 Is the entire collection allowed for shipment. Подробнее...
 
 hasAllowDelivery ()
 
 isEmptySystemShipment ()
 Is the a system shipped empty. Подробнее...
 
 allowDelivery ()
 Resolution fact shipment to shipment collection. Подробнее...
 
 disallowDelivery ()
 Prohibition upon shipment to shipment collection. Подробнее...
 
 tryReserve ()
 Trying to reserve the contents of the shipment collection. Подробнее...
 
 tryUnreserve ()
 Trying to reserve the contents of the shipment collection. Подробнее...
 
 onBeforeBasketItemDelete (BasketItem $basketItem)
 
 onBasketModify ($action, BasketItemBase $basketItem, $name=null, $oldValue=null, $value=null)
 
 onOrderModify ($name, $oldValue, $value)
 
 refreshData ()
 
 calculateDelivery ()
 
 resetData ()
 
 getBasketItemDistributedQuantity (BasketItem $basketItem)
 
 isExistBasketItem (BasketItem $basketItem, $includeSystemShipment=false)
 
 getBasePriceDelivery ()
 
 getPriceDelivery ()
 
 getItemByShipmentCode ($itemCode)
 
 verify ()
 
 createClone (\SplObjectStorage $cloneEntity)
 
 getErrorEntity ($value)
 
 canAutoFixError ($value)
 
 updateReservedFlag (ShipmentCollection $collection)
 
 getNotSystemItems ()
 
- Открытые члены унаследованные от EntityCollection
 onItemModify (CollectableEntity $item, $name=null, $oldValue=null, $value=null)
 
 clearCollection ()
 
 getItemById ($id)
 
 getIndexById ($id)
 
 getItemByIndex ($index)
 
 isStartField ($isMeaningfulField=false)
 
 clearStartField ()
 
 hasMeaningfulField ()
 
 doFinalAction ($hasMeaningfulField=false)
 
 isMathActionOnly ()
 
 setMathActionOnly ($value=false)
 
 isChanged ()
 
 isClone ()
 
 isAnyItemDeleted ()
 
 clearChanged ()
 
- Открытые члены унаследованные от CollectionBase
 getIterator ()
 
 offsetExists ($offset)
 Whether a offset exists. Подробнее...
 
 offsetGet ($offset)
 Offset to retrieve. Подробнее...
 
 offsetSet ($offset, $value)
 Offset to set. Подробнее...
 
 offsetUnset ($offset)
 Offset to unset. Подробнее...
 
 count ()
 Count elements of an object. Подробнее...
 
 current ()
 Return the current element. Подробнее...
 
 next ()
 Move forward to next element. Подробнее...
 
 key ()
 Return the key of the current element. Подробнее...
 
 valid ()
 Checks if current position is valid. Подробнее...
 
 rewind ()
 Rewind the Iterator to the first element. Подробнее...
 
 isEmpty ()
 Checks if collection is empty. Подробнее...
 

Открытые статические члены

static load (Order $order)
 Loaded from the database collection shipments Order. Подробнее...
 
static getRegistryType ()
 
static getList (array $parameters=array())
 

Защищенные члены

 getEntityParent ()
 Getting the parent entity. Подробнее...
 
 getDeletableItems ()
 
 addItem (Internals\CollectableEntity $shipment)
 Adding shipping to the collection. Подробнее...
 
 deleteInternal ($primary)
 
 deleteExtraServiceInternal ($shipmentId)
 
- Защищенные члены унаследованные от EntityCollection
 __construct ()
 EntityCollection constructor. Подробнее...
 
 addItem (CollectableEntity $item)
 
 createIndex ()
 
 callEventOnBeforeCollectionClear ()
 
 setAnyItemDeleted ($value)
 

Защищенные статические члены

static getClonedFields ()
 Fields that are cloned into the system from a conventional shipping. Подробнее...
 

Защищенные данные

 $order
 
- Защищенные данные унаследованные от EntityCollection
 $isClone = false
 
 $anyItemDeleted = false
 
- Защищенные данные унаследованные от CollectionBase
 $collection = array()
 

Подробное описание

См. определение в файле shipmentcollection.php строка 17

Методы

◆ addItem()

addItem ( Internals\CollectableEntity  $shipment)
protected

Adding shipping to the collection.

Аргументы
Internals\CollectableEntity$shipment
Возвращает
Internals\CollectableEntity|Shipment
Исключения
Main

См. определение в файле shipmentcollection.php строка 148

149  {
150  /** @var Shipment $shipment */
151  $shipment = parent::addItem($shipment);
152 
153  /** @var Order $order */
154  if (!$order = $this->getOrder())
155  {
156  throw new Main\ObjectNotFoundException('Entity "Order" not found');
157  }
158 
159  $order->onShipmentCollectionModify(EventActions::ADD, $shipment);
160 
161  return $shipment;
162  }

◆ allowDelivery()

allowDelivery ( )

Resolution fact shipment to shipment collection.

Возвращает
Result

См. определение в файле shipmentcollection.php строка 741

742  {
743  $result = new Result();
744 
745  $collection = $this->getNotSystemItems();
746 
747  /** @var Shipment $shipment */
748  foreach ($collection as $shipment)
749  {
750  $r = $shipment->allowDelivery();
751  if (!$r->isSuccess())
752  {
753  $result->addErrors($r->getErrors());
754  }
755  }
756  return $result;
757  }

◆ calculateDelivery()

calculateDelivery ( )
Возвращает
Result

См. определение в файле shipmentcollection.php строка 1227

1228  {
1229  /** @var Result $result */
1230  $result = new Result();
1231 
1232  $calculatedDeliveries = [];
1233 
1234  $collection = $this->getNotSystemItems();
1235 
1236  /** @var Shipment $shipment */
1237  foreach ($collection as $shipment)
1238  {
1239  if ($shipment->getDeliveryId() == 0)
1240  continue;
1241 
1242  if ($shipment->isCustomPrice())
1243  {
1244  $priceDelivery = $shipment->getPrice();
1245 
1246  $calcResult = new Delivery\CalculationResult();
1247  $calcResult->setDeliveryPrice($priceDelivery);
1248  }
1249  else
1250  {
1251  /** @var Delivery\CalculationResult $calcResult */
1252  $calcResult = $shipment->calculateDelivery();
1253  if (!$calcResult->isSuccess())
1254  {
1255  $result->addErrors($calcResult->getErrors());
1256  continue;
1257  }
1258 
1259  $priceDelivery = $calcResult->getPrice();
1260  if ($priceDelivery < 0)
1261  {
1262  $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_SHIPMENT_WRONG_DELIVERY_PRICE'), 'WRONG_DELIVERY_PRICE'));
1263  continue;
1264  }
1265  }
1266 
1267  $priceDelivery = PriceMaths::roundPrecision($priceDelivery);
1268  $shipment->setField('BASE_PRICE_DELIVERY', $priceDelivery);
1269 
1270  $calculatedDeliveries[] = $calcResult;
1271  }
1272 
1273  $result->setData(['CALCULATED_DELIVERIES' => $calculatedDeliveries]);
1274 
1275  return $result;
1276  }

◆ canAutoFixError()

canAutoFixError (   $value)
Аргументы
$value
Возвращает
string

См. определение в файле shipmentcollection.php строка 1479

1480  {
1481  $autoFix = false;
1482 
1483  /** @var Shipment $shipment */
1484  foreach ($this->collection as $shipment)
1485  {
1486  if ($autoFix = $shipment->canAutoFixError($value))
1487  {
1488  break;
1489  }
1490  }
1491  return $autoFix;
1492  }

◆ cloneShipment()

cloneShipment ( Shipment  $parentShipment,
Shipment  $childShipment 
)

См. определение в файле shipmentcollection.php строка 531

532  {
533  foreach (static::getClonedFields() as $fieldName)
534  {
535  /** @var Result $r */
536  $childShipment->setFieldNoDemand($fieldName, $parentShipment->getField($fieldName));
537  }
538 
539  $childShipment->setExtraServices($parentShipment->getExtraServices());
540  $childShipment->setStoreId($parentShipment->getStoreId());
541  return new Result();
542  }

◆ createClone()

createClone ( \SplObjectStorage  $cloneEntity)

Переопределяет метод предка EntityCollection.

См. определение в файле shipmentcollection.php строка 1433

1434  {
1435  if ($this->isClone() && $cloneEntity->contains($this))
1436  {
1437  return $cloneEntity[$this];
1438  }
1439 
1440  /** @var ShipmentCollection $shipmentCollectionClone */
1441  $shipmentCollectionClone = parent::createClone($cloneEntity);
1442 
1443  if ($this->order)
1444  {
1445  if ($cloneEntity->contains($this->order))
1446  {
1447  $shipmentCollectionClone->order = $cloneEntity[$this->order];
1448  }
1449  }
1450 
1451  return $shipmentCollectionClone;
1452  }

◆ createItem()

createItem ( Delivery\Services\Base  $delivery = null)

Create new shipment.

Аргументы
Delivery\Services\Base | null$delivery
Возвращает
mixed
Исключения
Main

См. определение в файле shipmentcollection.php строка 131

132  {
133  /** @var Shipment $shipmentClassName */
134  $shipmentClassName = static::getItemCollectionClassName();
135  $shipment = $shipmentClassName::create($this, $delivery);
136  $this->addItem($shipment);
137 
138  return $shipment;
139  }

◆ deleteExtraServiceInternal()

deleteExtraServiceInternal (   $shipmentId)
protected
Аргументы
$shipmentId

См. определение в файле shipmentcollection.php строка 1552

1553  {
1555  }

◆ deleteInternal()

deleteInternal (   $primary)
protected
Аргументы
$primary
Возвращает
Entity\DeleteResult

См. определение в файле shipmentcollection.php строка 1544

1545  {
1546  return Internals\ShipmentTable::deleteWithItems($primary);
1547  }

◆ deleteItem()

deleteItem (   $index)

Переопределяет метод предка EntityCollection.

См. определение в файле shipmentcollection.php строка 171

172  {
173  $result = new Result();
174  /** @var Shipment $oldItem */
175  $oldItem = parent::deleteItem($index);
176 
177  /** @var Shipment $systemShipment */
178  if ($oldItem->getId() > 0 && !$oldItem->isSystem() && ($systemShipment = $this->getSystemShipment()) && $systemShipment->getId() == 0)
179  {
180  $r = $this->cloneShipment($oldItem, $systemShipment);
181  if (!$r->isSuccess())
182  {
183  $result->addErrors($r->getErrors());
184  }
185  }
186 
187  $order = $this->getOrder();
188  $order->onShipmentCollectionModify(EventActions::DELETE, $oldItem);
189  }

◆ disallowDelivery()

disallowDelivery ( )

Prohibition upon shipment to shipment collection.

Возвращает
Result

См. определение в файле shipmentcollection.php строка 763

764  {
765  $result = new Result();
766 
767  $collection = $this->getNotSystemItems();
768 
769  /** @var Shipment $shipment */
770  foreach ($collection as $shipment)
771  {
772  $r = $shipment->disallowDelivery();
773  if (!$r->isSuccess())
774  {
775  $result->addErrors($r->getErrors());
776  }
777  }
778 
779  return $result;
780  }

◆ getBasePriceDelivery()

getBasePriceDelivery ( )
Возвращает
float

См. определение в файле shipmentcollection.php строка 1339

1340  {
1341  $collection = $this->getNotSystemItems();
1342 
1343  $sum = 0;
1344  /** @var Shipment $shipment */
1345  foreach ($collection as $shipment)
1346  {
1347  $sum += $shipment->getField('BASE_PRICE_DELIVERY');
1348  }
1349 
1350  return $sum;
1351  }

◆ getBasketItemDistributedQuantity()

getBasketItemDistributedQuantity ( BasketItem  $basketItem)
Аргументы
BasketItem$basketItem
Возвращает
float|int
Исключения
Main

См. определение в файле shipmentcollection.php строка 1299

1300  {
1301  $collection = $this->getNotSystemItems();
1302 
1303  $allQuantity = 0;
1304 
1305  /** @var Shipment $shipment */
1306  foreach ($collection as $shipment)
1307  {
1308  $allQuantity += $shipment->getBasketItemQuantity($basketItem);
1309  }
1310 
1311  return $allQuantity;
1312  }

◆ getClonedFields()

static getClonedFields ( )
staticprotected

Fields that are cloned into the system from a conventional shipping.

Возвращает
array

См. определение в файле shipmentcollection.php строка 549

550  {
551  return array(
552  'DELIVERY_LOCATION',
553  'PARAMS',
554  'DELIVERY_ID',
555  'DELIVERY_NAME',
556  );
557  }

◆ getDeletableItems()

getDeletableItems ( )
protected
Возвращает
array|Internals\CollectionFilterIterator

Переопределяет метод предка EntityCollection.

См. определение в файле shipmentcollection.php строка 118

119  {
120  return $this->getNotSystemItems();
121  }

◆ getEntityParent()

getEntityParent ( )
protected

Getting the parent entity.

Возвращает
Order - order entity

Переопределяет метод предка EntityCollection.

См. определение в файле shipmentcollection.php строка 30

31  {
32  return $this->getOrder();
33  }

◆ getErrorEntity()

getErrorEntity (   $value)
Аргументы
$value
Возвращает
string

См. определение в файле shipmentcollection.php строка 1459

1460  {
1461  $className = null;
1462  /** @var Shipment $shipment */
1463  foreach ($this->collection as $shipment)
1464  {
1465  if ($className = $shipment->getErrorEntity($value))
1466  {
1467  break;
1468  }
1469  }
1470 
1471  return $className;
1472  }

◆ getItemByShipmentCode()

getItemByShipmentCode (   $itemCode)
Аргументы
$itemCode
Возвращает
Shipment|null

См. определение в файле shipmentcollection.php строка 1375

1376  {
1377  /** @var Shipment $shipment */
1378  foreach ($this->collection as $shipment)
1379  {
1380  $shipmentCode = $shipment->getShipmentCode();
1381  if ($itemCode == $shipmentCode)
1382  return $shipment;
1383 
1384  }
1385 
1386  return null;
1387  }

◆ getList()

static getList ( array  $parameters = array())
static
Аргументы
array$parameters
Возвращает
Main\DB\Result

См. определение в файле shipmentcollection.php строка 1535

1536  {
1537  return Internals\ShipmentTable::getList($parameters);
1538  }

◆ getNotSystemItems()

getNotSystemItems ( )
Возвращает
Internals\CollectionFilterIterator

См. определение в файле shipmentcollection.php строка 1560

1561  {
1562  $callback = function (Shipment $shipment)
1563  {
1564  return !$shipment->isSystem();
1565  };
1566 
1567  return new Internals\CollectionFilterIterator($this->getIterator(), $callback);
1568  }

◆ getOrder()

getOrder ( )

Getting entity of the order.

Возвращает
Order

См. определение в файле shipmentcollection.php строка 218

219  {
220  return $this->order;
221  }

◆ getPriceDelivery()

getPriceDelivery ( )
Возвращает
float

См. определение в файле shipmentcollection.php строка 1356

1357  {
1358  $collection = $this->getNotSystemItems();
1359 
1360  $sum = 0;
1361  /** @var Shipment $shipment */
1362  foreach ($collection as $shipment)
1363  {
1364  $sum += $shipment->getPrice();
1365  }
1366 
1367 
1368  return $sum;
1369  }

◆ getRegistryType()

static getRegistryType ( )
static
Возвращает
string

Переопределяет метод предка EntityCollection.

См. определение в файле shipmentcollection.php строка 266

267  {
269  }

◆ getSystemShipment()

getSystemShipment ( )

Getting the system shipment.

Возвращает
Shipment

См. определение в файле shipmentcollection.php строка 276

277  {
278  /** @var Shipment $shipment */
279  foreach ($this->collection as $shipment)
280  {
281  if ($shipment->isSystem())
282  {
283  return $shipment;
284  }
285  }
286 
287  /** @var Shipment $shipmentClassName */
288  $shipmentClassName = static::getItemCollectionClassName();
289  $shipment = $shipmentClassName::createSystem($this);
290  $this->addItem($shipment);
291 
292  return $shipment;
293  }

◆ hasAllowDelivery()

hasAllowDelivery ( )
Возвращает
bool

См. определение в файле shipmentcollection.php строка 710

711  {
712  $collection = $this->getNotSystemItems();
713 
714  /** @var Shipment $shipment */
715  foreach ($collection as $shipment)
716  {
717  if ($shipment->isAllowDelivery())
718  {
719  return true;
720  }
721  }
722 
723  return false;
724  }

◆ hasShipped()

hasShipped ( )

Is the entire collection shipped.

Возвращает
bool

См. определение в файле shipmentcollection.php строка 598

599  {
600  if (!empty($this->collection) && is_array($this->collection))
601  {
602  /** @var Shipment $shipment */
603  foreach ($this->collection as $shipment)
604  {
605  if ($shipment->isSystem())
606  {
607  continue;
608  }
609 
610  if ($shipment->isShipped() && !$shipment->isEmpty())
611  {
612  return true;
613  }
614  }
615  }
616 
617  return false;
618  }

◆ isAllowDelivery()

isAllowDelivery ( )

Is the entire collection allowed for shipment.

Возвращает
bool

См. определение в файле shipmentcollection.php строка 678

679  {
680  if (!empty($this->collection) && is_array($this->collection))
681  {
682  /** @var Shipment $shipment */
683  foreach ($this->collection as $shipment)
684  {
685  if ($shipment->isSystem())
686  {
687  if (!$shipment->isEmpty())
688  {
689  return false;
690  }
691 
692  continue;
693  }
694 
695  if (!$shipment->isAllowDelivery() && !$shipment->isEmpty())
696  {
697  return false;
698  }
699  }
700 
701  return true;
702  }
703 
704  return false;
705  }

◆ isEmptySystemShipment()

isEmptySystemShipment ( )

Is the a system shipped empty.

Возвращает
bool

См. определение в файле shipmentcollection.php строка 731

732  {
733  return $this->getSystemShipment()->isEmpty();
734  }

◆ isExistBasketItem()

isExistBasketItem ( BasketItem  $basketItem,
  $includeSystemShipment = false 
)
Аргументы
BasketItem$basketItem
bool | false$includeSystemShipment
Возвращает
bool
Исключения
Main

См. определение в файле shipmentcollection.php строка 1321

1322  {
1323  /** @var Shipment $shipment */
1324  foreach ($this->collection as $shipment)
1325  {
1326  if (!$includeSystemShipment && $shipment->isSystem())
1327  {
1328  continue;
1329  }
1330 
1331  return $shipment->isExistBasketItem($basketItem);
1332  }
1333 
1334  return false;
1335  }

◆ isExistsSystemShipment()

isExistsSystemShipment ( )

Check whether there is a system collection of shipping.

Возвращает
bool

См. определение в файле shipmentcollection.php строка 300

301  {
302  /** @var Shipment $shipment */
303  foreach ($this->collection as $shipment)
304  {
305  if ($shipment->isSystem())
306  return true;
307  }
308 
309  return false;
310  }

◆ isMarked()

isMarked ( )

Is the entire collection of marked.

Возвращает
bool

См. определение в файле shipmentcollection.php строка 625

626  {
627  if (!empty($this->collection) && is_array($this->collection))
628  {
629  /** @var Shipment $shipment */
630  foreach ($this->collection as $shipment)
631  {
632  if ($shipment->isSystem())
633  continue;
634 
635  if ($shipment->isMarked())
636  return true;
637  }
638  }
639 
640  return false;
641  }

◆ isReserved()

isReserved ( )

Is the entire collection reserved.

Возвращает
bool

См. определение в файле shipmentcollection.php строка 648

649  {
650  if (!empty($this->collection) && is_array($this->collection))
651  {
652  /** @var Shipment $shipment */
653  foreach ($this->collection as $shipment)
654  {
655  if ($shipment->isSystem())
656  {
657  if (count($this->collection) == 1)
658  return $shipment->isReserved();
659 
660  continue;
661  }
662 
663  if (!$shipment->isReserved())
664  return false;
665  }
666 
667  return true;
668  }
669 
670  return false;
671  }

◆ isShipped()

isShipped ( )

Is the entire collection shipped.

Возвращает
bool

См. определение в файле shipmentcollection.php строка 564

565  {
566  if (!empty($this->collection) && is_array($this->collection))
567  {
568  /** @var Shipment $shipment */
569  foreach ($this->collection as $shipment)
570  {
571  if ($shipment->isSystem())
572  {
573  if (!$shipment->isEmpty())
574  {
575  return false;
576  }
577 
578  continue;
579  }
580 
581  if (!$shipment->isShipped() && !$shipment->isEmpty())
582  {
583  return false;
584  }
585  }
586 
587  return true;
588  }
589 
590  return false;
591  }

◆ load()

static load ( Order  $order)
static

Loaded from the database collection shipments Order.

Аргументы
Order$order
Возвращает
ShipmentCollection
Исключения
Main

См. определение в файле shipmentcollection.php строка 230

231  {
232  /** @var ShipmentCollection $shipmentCollection */
233  $shipmentCollection = static::createShipmentCollectionObject();
234  $shipmentCollection->setOrder($order);
235 
236  if ($order->getId() > 0)
237  {
238  /** @var Shipment $shipmentClassName */
239  $shipmentClassName = static::getItemCollectionClassName();
240  $shipmentList = $shipmentClassName::loadForOrder($order->getId());
241  /** @var Shipment $shipment */
242  foreach ($shipmentList as $shipment)
243  {
244  $shipment->setCollection($shipmentCollection);
245  $shipmentCollection->addItem($shipment);
246  }
247  }
248 
249  return $shipmentCollection;
250  }

◆ onBasketModify()

onBasketModify (   $action,
BasketItemBase  $basketItem,
  $name = null,
  $oldValue = null,
  $value = null 
)
Аргументы
$action
BasketItemBase$basketItem
null$name
null$oldValue
null$value
Возвращает
Result
Исключения
Main

См. определение в файле shipmentcollection.php строка 934

934  : Result
935  {
936  $result = new Result();
937 
938  if (!($basketItem instanceof BasketItem))
939  {
940  return $result;
941  }
942 
943  if ($action === EventActions::DELETE)
944  {
945  $order = $this->getOrder();
946  if ($order->getId() == 0 && !$order->isMathActionOnly())
947  {
948  $this->refreshData();
949  }
950 
951  return $result;
952  }
953  elseif ($action === EventActions::ADD)
954  {
955  return $this->getSystemShipment()->onBasketModify($action, $basketItem, $name, $oldValue, $value);
956  }
957  elseif ($action !== EventActions::UPDATE)
958  {
959  return $result;
960  }
961 
962  if ($name == 'QUANTITY')
963  {
964  if (!$this->isAllowAutoEdit($basketItem))
965  {
966  $result = $this->checkDistributedQuantity($basketItem, $value);
967  if (!$result->isSuccess())
968  {
969  return $result;
970  }
971  }
972 
973  $shipment = $this->getItemForAutoEdit($basketItem);
974 
975  if ($value - $oldValue > 0)
976  {
977  $r = $this->getSystemShipment()->onBasketModify($action, $basketItem, $name, $oldValue, $value);
978  if (!$r->isSuccess())
979  {
980  return $result->addErrors($r->getErrors());
981  }
982  }
983 
984  if ($shipment)
985  {
986  $r = $shipment->onBasketModify($action, $basketItem, $name, $oldValue, $value);
987  if (!$r->isSuccess())
988  {
989  $result->addErrors($r->getErrors());
990  return $result;
991  }
992  }
993 
994  if ($value - $oldValue < 0)
995  {
996  $r = $this->getSystemShipment()->onBasketModify($action, $basketItem, $name, $oldValue, $value);
997  if (!$r->isSuccess())
998  {
999  $result->addErrors($r->getErrors());
1000  return $result;
1001  }
1002  }
1003  }
1004  elseif ($name === 'WEIGHT')
1005  {
1006  /** @var Shipment $shipment */
1007  foreach ($this->getNotSystemItems() as $shipment)
1008  {
1009  $shipment->onBasketModify($action, $basketItem, $name, $value, $oldValue);
1010  }
1011  }
1012 
1013  return $result;
1014  }

◆ onBeforeBasketItemDelete()

onBeforeBasketItemDelete ( BasketItem  $basketItem)

См. определение в файле shipmentcollection.php строка 903

904  {
905  $result = new Result();
906 
907  /** @var Shipment $shipment */
908  foreach ($this->collection as $shipment)
909  {
910  $r = $shipment->onBeforeBasketItemDelete($basketItem);
911  if (!$r->isSuccess())
912  {
913  $result->addErrors($r->getErrors());
914  }
915  }
916 
917  return $result;
918  }

◆ onItemModify()

onItemModify ( Internals\CollectableEntity  $item,
  $name = null,
  $oldValue = null,
  $value = null 
)

Processing changes the essence of the shipment fields.

Аргументы
Internals\CollectableEntity$item
null$name
null$oldValue
null$value
Возвращает
Result

См. определение в файле shipmentcollection.php строка 200

201  {
202  /** @var Order $order */
203  $order = $this->getOrder();
204 
205  if ($item instanceof Shipment)
206  {
207  return $order->onShipmentCollectionModify(EventActions::UPDATE, $item, $name, $oldValue, $value);
208  }
209 
210  return new Result();
211  }

◆ onOrderModify()

onOrderModify (   $name,
  $oldValue,
  $value 
)
Аргументы
$name
$oldValue
$value
Возвращает
Result
Исключения
Main

См. определение в файле shipmentcollection.php строка 1119

1120  {
1121  $result = new Result();
1122 
1123  switch($name)
1124  {
1125  case "CANCELED":
1126  if ($value == "Y")
1127  {
1128  $isShipped = false;
1129  /** @var Shipment $shipment */
1130  foreach ($this->collection as $shipment)
1131  {
1132  if ($shipment->isShipped())
1133  {
1134  $isShipped = true;
1135  break;
1136  }
1137  }
1138 
1139  if ($isShipped)
1140  {
1141  $result->addError(
1142  new ResultError(
1143  Loc::getMessage('SALE_ORDER_CANCEL_SHIPMENT_EXIST_SHIPPED'),
1144  'SALE_ORDER_CANCEL_SHIPMENT_EXIST_SHIPPED'
1145  )
1146  );
1147 
1148  return $result;
1149  }
1150 
1151  $this->tryUnreserve();
1152  }
1153  else
1154  {
1155  if (!$order = $this->getOrder())
1156  {
1157  throw new Main\ObjectNotFoundException('Entity "Order" not found');
1158  }
1159 
1160  /** @var Shipment $shipment */
1161  foreach ($this->collection as $shipment)
1162  {
1163  if ($shipment->needReservation())
1164  {
1165  /** @var Result $r */
1166  $r = $shipment->tryReserve();
1167  if (!$r->isSuccess())
1168  {
1169  $registry = Registry::getInstance(static::getRegistryType());
1170 
1171  /** @var EntityMarker $entityMarker */
1172  $entityMarker = $registry->getEntityMarkerClassName();
1173  $entityMarker::addMarker($order, $shipment, $r);
1174  if (!$shipment->isSystem())
1175  {
1176  $shipment->setField('MARKED', 'Y');
1177  }
1178 
1179  $result->addErrors($r->getErrors());
1180  }
1181  }
1182  }
1183 
1184  }
1185  break;
1186 
1187  case "MARKED":
1188  if ($value == "N")
1189  {
1190  /** @var Shipment $shipment */
1191  foreach ($this->collection as $shipment)
1192  {
1193  if ($shipment->isSystem())
1194  continue;
1195 
1196  $shipment->setField('MARKED', $value);
1197  }
1198  }
1199  break;
1200  }
1201 
1202  return $result;
1203  }

◆ refreshData()

refreshData ( )
Возвращает
Result
Исключения
Main

См. определение в файле shipmentcollection.php строка 1209

1210  {
1211  $result = new Result();
1212 
1213  $this->resetData();
1214 
1215  $r = $this->calculateDelivery();
1216  if (!$r->isSuccess())
1217  {
1218  $result->addErrors($r->getErrors());
1219  }
1220 
1221  return $result;
1222  }

◆ resetCollection()

resetCollection ( )

Deletes all shipments and creates system shipment containing the whole basket.

См. определение в файле shipmentcollection.php строка 45

46  {
47  /** @var Order $order */
48  if (!$order = $this->getOrder())
49  {
50  throw new Main\ObjectNotFoundException('Entity "Order" not found');
51  }
52 
53  /** @var Basket $basket */
54  if (!$basket = $order->getBasket())
55  {
56  throw new Main\ObjectNotFoundException('Entity "Basket" not found');
57  }
58 
59  $result = new Result();
60 
61  $deliveryInfo = array();
62 
63  if (count($this->collection) > 0)
64  {
65  /** @var Shipment $shipment */
66  foreach ($this->collection as $shipment)
67  {
68  if (empty($deliveryInfo))
69  {
70  if ($shipment->isSystem() && $shipment->getDeliveryId() > 0)
71  {
72  foreach (static::getClonedFields() as $field)
73  {
74  if (strval(trim($shipment->getField($field))) != '')
75  $deliveryInfo[$field] = trim($shipment->getField($field));
76  }
77  }
78  }
79  $shipment->delete();
80  }
81  }
82 
83  /** @var Shipment $systemShipment */
84  if (!$systemShipment = $this->getSystemShipment())
85  {
86  throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
87  }
88 
89  /** @var ShipmentItemCollection $systemShipmentItemCollection */
90  if (!$systemShipmentItemCollection = $systemShipment->getShipmentItemCollection())
91  {
92  throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
93  }
94 
95  $systemShipmentItemCollection->resetCollection($basket);
96 
97  if (!empty($deliveryInfo))
98  {
99  $systemShipment->setFieldsNoDemand($deliveryInfo);
100  }
101 
103  {
104  /** @var Result $r */
105  $r = $this->tryReserve();
106  if (!$r->isSuccess())
107  {
108  $result->addErrors($r->getErrors());
109  }
110  }
111 
112  return $result;
113  }

◆ resetData()

resetData ( )

См. определение в файле shipmentcollection.php строка 1281

1282  {
1283  $collection = $this->getNotSystemItems();
1284 
1285  /** @var Shipment $shipment */
1286  foreach ($collection as $shipment)
1287  {
1288  $shipment->resetData();
1289  }
1290  }

◆ save()

save ( )

Saving data collection.

Возвращает
Entity\Result
Исключения
Main

См. определение в файле shipmentcollection.php строка 320

321  {
322  $result = new Entity\Result();
323 
324  /** @var Order $order */
325  if (!$order = $this->getOrder())
326  {
327  throw new Main\ObjectNotFoundException('Entity "Order" not found');
328  }
329 
330  $itemsFromDb = array();
331  if ($order->getId() > 0)
332  {
333  $itemsFromDbList = static::getList(
334  array(
335  "filter" => array("ORDER_ID" => $order->getId()),
336  "select" => array("ID" , "DELIVERY_NAME", "DELIVERY_ID")
337  )
338  );
339  while ($itemsFromDbItem = $itemsFromDbList->fetch())
340  $itemsFromDb[$itemsFromDbItem["ID"]] = $itemsFromDbItem;
341  }
342 
343  /** @var Shipment $shipment */
344  foreach ($this->collection as $shipment)
345  {
346  if ($shipment->isSystem())
347  continue;
348 
349  if (($systemShipment = $this->getSystemShipment()) && $systemShipment->getId() == 0)
350  {
351  /** @var Result $r */
352  $r = $this->cloneShipment($shipment, $systemShipment);
353  if ($r->isSuccess())
354  {
355  break;
356  }
357  else
358  {
359  $result->addErrors($r->getErrors());
360  }
361  }
362  }
363 
364  $changeMeaningfulFields = array(
365  "DELIVERY_LOCATION",
366  "PRICE_DELIVERY",
367  "CUSTOM_PRICE_DELIVERY",
368  "ALLOW_DELIVERY",
369  "DEDUCTED",
370  "RESERVED",
371  "DELIVERY_NAME",
372  "DELIVERY_ID",
373  "CANCELED",
374  "MARKED",
375  "SYSTEM",
376  "COMPANY_ID",
377  "DISCOUNT_PRICE",
378  "BASE_PRICE_DELIVERY",
379  "EXTERNAL_DELIVERY",
380  );
381 
382  /** @var Shipment $shipment */
383  foreach ($this->collection as $shipment)
384  {
385  $isNew = (bool)($shipment->getId() <= 0);
386  $isChanged = $shipment->isChanged();
387 
388  if ($order->getId() > 0 && $isChanged)
389  {
390  $logFields = array();
391 
392 
393  $fields = $shipment->getFields();
394  $originalValues = $fields->getOriginalValues();
395 
396  foreach($originalValues as $originalFieldName => $originalFieldValue)
397  {
398  if (in_array($originalFieldName, $changeMeaningfulFields) && $shipment->getField($originalFieldName) != $originalFieldValue)
399  {
400  $logFields[$originalFieldName] = $shipment->getField($originalFieldName);
401  if (!$isNew)
402  $logFields['OLD_'.$originalFieldName] = $originalFieldValue;
403  }
404  }
405 
406  }
407 
408  $r = $shipment->save();
409  if ($r->isSuccess())
410  {
411  if ($order->getId() > 0)
412  {
413  if ($isChanged)
414  {
415  $registry = Registry::getInstance(static::getRegistryType());
416 
417  /** @var OrderHistory $orderHistory */
418  $orderHistory = $registry->getOrderHistoryClassName();
419  $orderHistory::addLog(
420  'SHIPMENT',
421  $order->getId(),
422  $isNew ? 'SHIPMENT_ADD' : 'SHIPMENT_UPDATE',
423  $shipment->getId(),
424  $shipment,
425  $logFields,
426  $orderHistory::SALE_ORDER_HISTORY_LOG_LEVEL_1
427  );
428 
429  $orderHistory::addAction(
430  'SHIPMENT',
431  $order->getId(),
432  "SHIPMENT_SAVED",
433  $shipment->getId(),
434  $shipment,
435  array(),
437  );
438  }
439  }
440 
441  }
442  else
443  {
444  $result->addErrors($r->getErrors());
445  }
446 
447  if (isset($itemsFromDb[$shipment->getId()]))
448  unset($itemsFromDb[$shipment->getId()]);
449  }
450 
451  foreach ($itemsFromDb as $k => $v)
452  {
453  $v['ENTITY_REGISTRY_TYPE'] = static::getRegistryType();
454 
455  /** @var Main\Event $event */
456  $event = new Main\Event('sale', "OnBeforeSaleShipmentDeleted", array(
457  'VALUES' => $v,
458  ));
459  $event->send();
460 
461  $this->deleteInternal($k);
462  $this->deleteExtraServiceInternal($k);
463 
464  /** @var Main\Event $event */
465  $event = new Main\Event('sale', "OnSaleShipmentDeleted", array(
466  'VALUES' => $v,
467  ));
468  $event->send();
469 
470  if ($order->getId() > 0)
471  {
472  $registry = Registry::getInstance(static::getRegistryType());
473 
474  /** @var OrderHistory $orderHistory */
475  $orderHistory = $registry->getOrderHistoryClassName();
476  $orderHistory::addAction(
477  'SHIPMENT',
478  $order->getId(),
479  'SHIPMENT_REMOVED',
480  $k,
481  null,
482  array(
483  'ID' => $k,
484  'DELIVERY_NAME' => $v['DELIVERY_NAME'],
485  'DELIVERY_ID' => $v['DELIVERY_ID'],
486  )
487  );
488 
489  $registry = Registry::getInstance(static::getRegistryType());
490 
491  /** @var EntityMarker $entityMarker */
492  $entityMarker = $registry->getEntityMarkerClassName();
493  $entityMarker::deleteByFilter(array(
494  '=ORDER_ID' => $order->getId(),
495  '=ENTITY_TYPE' => $entityMarker::ENTITY_TYPE_SHIPMENT,
496  '=ENTITY_ID' => $k,
497  ));
498  }
499 
500  }
501 
502  if ($order->getId() > 0)
503  {
504  $registry = Registry::getInstance(static::getRegistryType());
505 
506  /** @var OrderHistory $orderHistory */
507  $orderHistory = $registry->getOrderHistoryClassName();
508  $orderHistory::collectEntityFields('SHIPMENT', $order->getId());
509  }
510 
511  return $result;
512  }

◆ setOrder()

setOrder ( Order  $order)

The attachment order to the collection.

Аргументы
OrderBase$order

См. определение в файле shipmentcollection.php строка 519

520  {
521  $this->order = $order;
522  }

◆ tryReserve()

tryReserve ( )

Trying to reserve the contents of the shipment collection.

Возвращает
Result
Исключения
Main

См. определение в файле shipmentcollection.php строка 787

788  {
789  $result = new Result();
790 
791  /** @var Order $order */
792  if (!($order = $this->getOrder()))
793  {
794  throw new Main\ObjectNotFoundException('Entity "Order" not found');
795  }
796 
797  /** @var Shipment $shipment */
798  foreach ($this->collection as $shipment)
799  {
800  if ($shipment->isReserved() || $shipment->isShipped())
801  continue;
802 
803  $r = $shipment->tryReserve();
804  if (!$r->isSuccess())
805  {
806  $result->addErrors($r->getErrors());
807  }
808  elseif ($r->hasWarnings())
809  {
810  $result->addWarnings($r->getWarnings());
811 
812  $registry = Registry::getInstance(static::getRegistryType());
813  /** @var EntityMarker $entityMarker */
814  $entityMarker = $registry->getEntityMarkerClassName();
815  $entityMarker::addMarker($order, $shipment, $r);
816  if (!$shipment->isSystem())
817  {
818  $shipment->setField('MARKED', 'Y');
819  }
820  }
821  }
822  return $result;
823  }

◆ tryUnreserve()

tryUnreserve ( )

Trying to reserve the contents of the shipment collection.

Возвращает
Result
Исключения
Main

См. определение в файле shipmentcollection.php строка 834

835  {
836  $result = new Result();
837 
838  if (!$order = $this->getOrder())
839  {
840  throw new Main\ObjectNotFoundException('Entity "Order" not found');
841  }
842  /** @var Shipment $shipment */
843  foreach ($this->collection as $shipment)
844  {
845  if ($shipment->isShipped())
846  {
847  if ($order &&
848  !Internals\ActionEntity::isTypeExists(
849  $order->getInternalId(),
851  )
852  )
853  {
855  $order->getInternalId(),
857  array(
858  'METHOD' => 'Bitrix\Sale\Shipment::updateReservedFlag',
859  'PARAMS' => array($shipment)
860  )
861  );
862  }
863 
864  continue;
865  }
866 
867  $r = $shipment->tryUnreserve();
868  if (!$r->isSuccess())
869  {
870  if (!$shipment->isSystem())
871  {
872  $registry = Registry::getInstance(static::getRegistryType());
873 
874  /** @var EntityMarker $entityMarker */
875  $entityMarker = $registry->getEntityMarkerClassName();
876  $entityMarker::addMarker($order, $shipment, $r);
877 
878  $shipment->setField('MARKED', 'Y');
879  }
880  $result->addErrors($r->getErrors());
881  }
882  elseif ($r->hasWarnings())
883  {
884  $result->addWarnings($r->getWarnings());
885  }
886  }
887 
888  return $result;
889  }

◆ updateReservedFlag()

updateReservedFlag ( ShipmentCollection  $collection)
Аргументы
ShipmentCollection$collection
Возвращает
Result

См. определение в файле shipmentcollection.php строка 1499

1500  {
1501  $result = new Result();
1502  /** @var Shipment $shipment */
1503  foreach ($collection as $shipment)
1504  {
1505  /** @var Shipment $shipmentClassName */
1506  $shipmentClassName = static::getItemCollectionClassName();
1507  $r = $shipmentClassName::updateReservedFlag($shipment);
1508  if (!$r->isSuccess())
1509  {
1510  $result->addErrors($r->getErrors());
1511  }
1512 
1513  if ($r->hasWarnings())
1514  {
1515  $result->addWarnings($r->getWarnings());
1516  }
1517  }
1518 
1519  return $result;
1520  }

◆ verify()

verify ( )
Возвращает
Result
Исключения
Main

Переопределяет метод предка EntityCollection.

См. определение в файле shipmentcollection.php строка 1397

1398  {
1399  $result = new Result();
1400 
1401  /** @var Shipment $shipment */
1402  foreach ($this->collection as $shipment)
1403  {
1404  if ($shipment->isSystem())
1405  {
1406  continue;
1407  }
1408 
1409  $r = $shipment->verify();
1410  if (!$r->isSuccess())
1411  {
1412  $result->addErrors($r->getErrors());
1413 
1414  $registry = Registry::getInstance(static::getRegistryType());
1415 
1416  /** @var EntityMarker $entityMarker */
1417  $entityMarker = $registry->getEntityMarkerClassName();
1418  $entityMarker::addMarker($this->getOrder(), $shipment, $r);
1419 
1420  $shipment->setField('MARKED', 'Y');
1421  }
1422  }
1423 
1424  return $result;
1425  }

Поля

◆ $order

$order
protected

См. определение в файле shipmentcollection.php строка 21


Объявления и описания членов класса находятся в файле:
Bitrix\Sale\ShipmentCollection\getSystemShipment
getSystemShipment()
Getting the system shipment.
Definition: shipmentcollection.php:276
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Returns translation by message code.
Definition: loc.php:29
Bitrix\Sale\Internals\CollectionBase\getIterator
getIterator()
Definition: collectionbase.php:26
Bitrix\Sale\EventActions\ADD
const ADD
Definition: eventactions.php:8
Bitrix\Sale\Internals\PoolBase\add
static add($code, $type, $value)
Definition: poolbase.php:51
Bitrix\Sale\Registry\REGISTRY_TYPE_ORDER
const REGISTRY_TYPE_ORDER
Definition: sale/lib/registry.php:16
Bitrix\Sale\EventActions\DELETE
const DELETE
Definition: eventactions.php:10
Bitrix\Sale\ShipmentCollection\deleteInternal
deleteInternal($primary)
Definition: shipmentcollection.php:1544
Bitrix\Sale\ShipmentCollection\getOrder
getOrder()
Getting entity of the order.
Definition: shipmentcollection.php:218
Bitrix\Sale\Internals\ShipmentExtraServiceTable\deleteByShipmentId
static deleteByShipmentId($shipmentId)
Definition: shipmentextraservice.php:67
Bitrix\Sale\Internals\PoolBase\isTypeExists
static isTypeExists($code, $type)
Definition: poolbase.php:76
Bitrix\Sale\ShipmentCollection\addItem
addItem(Internals\CollectableEntity $shipment)
Adding shipping to the collection.
Definition: shipmentcollection.php:148
Bitrix\Sale\ShipmentCollection\tryReserve
tryReserve()
Trying to reserve the contents of the shipment collection.
Definition: shipmentcollection.php:787
Bitrix\Sale\Internals\CollectionBase\count
count()
Count elements of an object.
Definition: collectionbase.php:79
Bitrix\Sale\ShipmentCollection\getNotSystemItems
getNotSystemItems()
Definition: shipmentcollection.php:1560
Bitrix\Sale\Internals\CollectionBase\$collection
$collection
Definition: collectionbase.php:21
Bitrix\Sale\ShipmentCollection\cloneShipment
cloneShipment(Shipment $parentShipment, Shipment $childShipment)
Definition: shipmentcollection.php:531
Bitrix\Sale\Registry\getInstance
static getInstance($type)
Definition: sale/lib/registry.php:161
Bitrix\Sale\EventActions\UPDATE
const UPDATE
Definition: eventactions.php:9
Bitrix\Sale\Configuration\RESERVE_ON_CREATE
const RESERVE_ON_CREATE
Definition: sale/lib/configuration.php:16
Bitrix\Sale\ShipmentCollection\calculateDelivery
calculateDelivery()
Definition: shipmentcollection.php:1227
Bitrix\Sale\Internals\ActionEntity\ACTION_ENTITY_SHIPMENT_RESERVED_QUANTITY
const ACTION_ENTITY_SHIPMENT_RESERVED_QUANTITY
Definition: actionentity.php:12
Bitrix\Sale\ShipmentCollection\resetData
resetData()
Definition: shipmentcollection.php:1281
Bitrix\Sale\Configuration\getProductReservationCondition
static getProductReservationCondition()
Returns current reservation condition.
Definition: sale/lib/configuration.php:60
Bitrix\Sale\ShipmentCollection\tryUnreserve
tryUnreserve()
Trying to reserve the contents of the shipment collection.
Definition: shipmentcollection.php:834
Bitrix\Sale\ShipmentCollection\deleteExtraServiceInternal
deleteExtraServiceInternal($shipmentId)
Definition: shipmentcollection.php:1552
Bitrix\Sale\ShipmentCollection\$order
$order
Definition: shipmentcollection.php:21
Bitrix\Sale\PriceMaths\roundPrecision
static roundPrecision($value)
Definition: pricemaths.php:17
Bitrix\Sale\OrderHistory\SALE_ORDER_HISTORY_ACTION_LOG_LEVEL_1
const SALE_ORDER_HISTORY_ACTION_LOG_LEVEL_1
Definition: orderhistory.php:29
Bitrix\Sale\Internals\EntityCollection\isClone
isClone()
Definition: entitycollection.php:358
Bitrix\Sale\ShipmentCollection\refreshData
refreshData()
Definition: shipmentcollection.php:1209