Bitrix-D7  20.5.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. Подробнее...
 
 toArray ()
 

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

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 строка 145

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

◆ allowDelivery()

allowDelivery ( )

Resolution fact shipment to shipment collection.

Возвращает
Result

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

749  {
750  $result = new Result();
751 
752  $collection = $this->getNotSystemItems();
753 
754  /** @var Shipment $shipment */
755  foreach ($collection as $shipment)
756  {
757  $r = $shipment->allowDelivery();
758  if (!$r->isSuccess())
759  {
760  $result->addErrors($r->getErrors());
761  }
762  }
763  return $result;
764  }

◆ calculateDelivery()

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

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

1234  {
1235  /** @var Result $result */
1236  $result = new Result();
1237 
1238  $calculatedDeliveries = [];
1239 
1240  $collection = $this->getNotSystemItems();
1241 
1242  /** @var Shipment $shipment */
1243  foreach ($collection as $shipment)
1244  {
1245  if ($shipment->getDeliveryId() == 0)
1246  continue;
1247 
1248  if ($shipment->isCustomPrice())
1249  {
1250  $priceDelivery = $shipment->getPrice();
1251 
1252  $calcResult = new Delivery\CalculationResult();
1253  $calcResult->setDeliveryPrice($priceDelivery);
1254  }
1255  else
1256  {
1257  /** @var Delivery\CalculationResult $calcResult */
1258  $calcResult = $shipment->calculateDelivery();
1259  if (!$calcResult->isSuccess())
1260  {
1261  $result->addErrors($calcResult->getErrors());
1262  continue;
1263  }
1264 
1265  $priceDelivery = $calcResult->getPrice();
1266  if ($priceDelivery < 0)
1267  {
1268  $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_SHIPMENT_WRONG_DELIVERY_PRICE'), 'WRONG_DELIVERY_PRICE'));
1269  continue;
1270  }
1271  }
1272 
1273  $priceDelivery = PriceMaths::roundPrecision($priceDelivery);
1274  $shipment->setField('BASE_PRICE_DELIVERY', $priceDelivery);
1275 
1276  $calculatedDeliveries[] = $calcResult;
1277  }
1278 
1279  $result->setData(['CALCULATED_DELIVERIES' => $calculatedDeliveries]);
1280 
1281  return $result;
1282  }
static getMessage($code, $replace=null, $language=null)
Returns translation by message code.
Definition: loc.php:29
static roundPrecision($value)
Definition: pricemaths.php:17

◆ canAutoFixError()

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

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

1486  {
1487  $autoFix = false;
1488 
1489  /** @var Shipment $shipment */
1490  foreach ($this->collection as $shipment)
1491  {
1492  if ($autoFix = $shipment->canAutoFixError($value))
1493  {
1494  break;
1495  }
1496  }
1497  return $autoFix;
1498  }

◆ cloneShipment()

cloneShipment ( Shipment  $parentShipment,
Shipment  $childShipment 
)

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

539  {
540  foreach (static::getClonedFields() as $fieldName)
541  {
542  /** @var Result $r */
543  $childShipment->setFieldNoDemand($fieldName, $parentShipment->getField($fieldName));
544  }
545 
546  $childShipment->setExtraServices($parentShipment->getExtraServices());
547  $childShipment->setStoreId($parentShipment->getStoreId());
548  return new Result();
549  }

◆ createClone()

createClone ( \SplObjectStorage  $cloneEntity)

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

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

1440  {
1441  if ($this->isClone() && $cloneEntity->contains($this))
1442  {
1443  return $cloneEntity[$this];
1444  }
1445 
1446  /** @var ShipmentCollection $shipmentCollectionClone */
1447  $shipmentCollectionClone = parent::createClone($cloneEntity);
1448 
1449  if ($this->order)
1450  {
1451  if ($cloneEntity->contains($this->order))
1452  {
1453  $shipmentCollectionClone->order = $cloneEntity[$this->order];
1454  }
1455  }
1456 
1457  return $shipmentCollectionClone;
1458  }

◆ createItem()

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

Create new shipment.

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

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

129  {
130  /** @var Shipment $shipmentClassName */
131  $shipmentClassName = static::getItemCollectionClassName();
132  $shipment = $shipmentClassName::create($this, $delivery);
133  $this->addItem($shipment);
134 
135  return $shipment;
136  }
addItem(Internals\CollectableEntity $shipment)
Adding shipping to the collection.

◆ deleteExtraServiceInternal()

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

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

◆ deleteInternal()

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

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

1551  {
1552  return Internals\ShipmentTable::deleteWithItems($primary);
1553  }

◆ deleteItem()

deleteItem (   $index)

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

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

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

◆ disallowDelivery()

disallowDelivery ( )

Prohibition upon shipment to shipment collection.

Возвращает
Result

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

771  {
772  $result = new Result();
773 
774  $collection = $this->getNotSystemItems();
775 
776  /** @var Shipment $shipment */
777  foreach ($collection as $shipment)
778  {
779  $r = $shipment->disallowDelivery();
780  if (!$r->isSuccess())
781  {
782  $result->addErrors($r->getErrors());
783  }
784  }
785 
786  return $result;
787  }

◆ getBasePriceDelivery()

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

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

1346  {
1347  $collection = $this->getNotSystemItems();
1348 
1349  $sum = 0;
1350  /** @var Shipment $shipment */
1351  foreach ($collection as $shipment)
1352  {
1353  $sum += $shipment->getField('BASE_PRICE_DELIVERY');
1354  }
1355 
1356  return $sum;
1357  }

◆ getBasketItemDistributedQuantity()

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

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

1306  {
1307  $collection = $this->getNotSystemItems();
1308 
1309  $allQuantity = 0;
1310 
1311  /** @var Shipment $shipment */
1312  foreach ($collection as $shipment)
1313  {
1314  $allQuantity += $shipment->getBasketItemQuantity($basketItem);
1315  }
1316 
1317  return $allQuantity;
1318  }

◆ getClonedFields()

static getClonedFields ( )
staticprotected

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

Возвращает
array

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

557  {
558  return array(
559  'DELIVERY_LOCATION',
560  'PARAMS',
561  'DELIVERY_ID',
562  'DELIVERY_NAME',
563  );
564  }

◆ getDeletableItems()

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

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

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

116  {
117  return $this->getNotSystemItems();
118  }

◆ getEntityParent()

getEntityParent ( )
protected

Getting the parent entity.

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

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

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

28  {
29  return $this->getOrder();
30  }

◆ getErrorEntity()

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

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

1466  {
1467  $className = null;
1468  /** @var Shipment $shipment */
1469  foreach ($this->collection as $shipment)
1470  {
1471  if ($className = $shipment->getErrorEntity($value))
1472  {
1473  break;
1474  }
1475  }
1476 
1477  return $className;
1478  }

◆ getItemByShipmentCode()

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

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

1382  {
1383  /** @var Shipment $shipment */
1384  foreach ($this->collection as $shipment)
1385  {
1386  $shipmentCode = $shipment->getShipmentCode();
1387  if ($itemCode == $shipmentCode)
1388  return $shipment;
1389 
1390  }
1391 
1392  return null;
1393  }

◆ getList()

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

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

1542  {
1543  return Internals\ShipmentTable::getList($parameters);
1544  }

◆ getNotSystemItems()

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

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

1567  {
1568  $callback = function (Shipment $shipment)
1569  {
1570  return !$shipment->isSystem();
1571  };
1572 
1573  return new Internals\CollectionFilterIterator($this->getIterator(), $callback);
1574  }

◆ getOrder()

getOrder ( )

Getting entity of the order.

Возвращает
Order

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

223  {
224  return $this->order;
225  }

◆ getPriceDelivery()

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

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

1363  {
1364  $collection = $this->getNotSystemItems();
1365 
1366  $sum = 0;
1367  /** @var Shipment $shipment */
1368  foreach ($collection as $shipment)
1369  {
1370  $sum += $shipment->getPrice();
1371  }
1372 
1373 
1374  return $sum;
1375  }

◆ getRegistryType()

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

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

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

274  {
276  }

◆ getSystemShipment()

getSystemShipment ( )

Getting the system shipment.

Возвращает
Shipment

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

284  {
285  /** @var Shipment $shipment */
286  foreach ($this->collection as $shipment)
287  {
288  if ($shipment->isSystem())
289  {
290  return $shipment;
291  }
292  }
293 
294  /** @var Shipment $shipmentClassName */
295  $shipmentClassName = static::getItemCollectionClassName();
296  $shipment = $shipmentClassName::createSystem($this);
297  $this->addItem($shipment);
298 
299  return $shipment;
300  }

◆ hasAllowDelivery()

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

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

718  {
719  $collection = $this->getNotSystemItems();
720 
721  /** @var Shipment $shipment */
722  foreach ($collection as $shipment)
723  {
724  if ($shipment->isAllowDelivery())
725  {
726  return true;
727  }
728  }
729 
730  return false;
731  }

◆ hasShipped()

hasShipped ( )

Is the entire collection shipped.

Возвращает
bool

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

606  {
607  if (!empty($this->collection) && is_array($this->collection))
608  {
609  /** @var Shipment $shipment */
610  foreach ($this->collection as $shipment)
611  {
612  if ($shipment->isSystem())
613  {
614  continue;
615  }
616 
617  if ($shipment->isShipped() && !$shipment->isEmpty())
618  {
619  return true;
620  }
621  }
622  }
623 
624  return false;
625  }

◆ isAllowDelivery()

isAllowDelivery ( )

Is the entire collection allowed for shipment.

Возвращает
bool

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

686  {
687  if (!empty($this->collection) && is_array($this->collection))
688  {
689  /** @var Shipment $shipment */
690  foreach ($this->collection as $shipment)
691  {
692  if ($shipment->isSystem())
693  {
694  if (!$shipment->isEmpty())
695  {
696  return false;
697  }
698 
699  continue;
700  }
701 
702  if (!$shipment->isAllowDelivery() && !$shipment->isEmpty())
703  {
704  return false;
705  }
706  }
707 
708  return true;
709  }
710 
711  return false;
712  }

◆ isEmptySystemShipment()

isEmptySystemShipment ( )

Is the a system shipped empty.

Возвращает
bool

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

739  {
740  return $this->getSystemShipment()->isEmpty();
741  }
getSystemShipment()
Getting the system shipment.

◆ isExistBasketItem()

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

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

1328  {
1329  /** @var Shipment $shipment */
1330  foreach ($this->collection as $shipment)
1331  {
1332  if (!$includeSystemShipment && $shipment->isSystem())
1333  {
1334  continue;
1335  }
1336 
1337  return $shipment->isExistBasketItem($basketItem);
1338  }
1339 
1340  return false;
1341  }

◆ isExistsSystemShipment()

isExistsSystemShipment ( )

Check whether there is a system collection of shipping.

Возвращает
bool

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

308  {
309  /** @var Shipment $shipment */
310  foreach ($this->collection as $shipment)
311  {
312  if ($shipment->isSystem())
313  return true;
314  }
315 
316  return false;
317  }

◆ isMarked()

isMarked ( )

Is the entire collection of marked.

Возвращает
bool

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

633  {
634  if (!empty($this->collection) && is_array($this->collection))
635  {
636  /** @var Shipment $shipment */
637  foreach ($this->collection as $shipment)
638  {
639  if ($shipment->isSystem())
640  continue;
641 
642  if ($shipment->isMarked())
643  return true;
644  }
645  }
646 
647  return false;
648  }

◆ isReserved()

isReserved ( )

Is the entire collection reserved.

Возвращает
bool

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

656  {
657  if (!empty($this->collection) && is_array($this->collection))
658  {
659  /** @var Shipment $shipment */
660  foreach ($this->collection as $shipment)
661  {
662  if ($shipment->isSystem())
663  {
664  if (count($this->collection) == 1)
665  return $shipment->isReserved();
666 
667  continue;
668  }
669 
670  if (!$shipment->isReserved())
671  return false;
672  }
673 
674  return true;
675  }
676 
677  return false;
678  }
count()
Count elements of an object.

◆ isShipped()

isShipped ( )

Is the entire collection shipped.

Возвращает
bool

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

572  {
573  if (!empty($this->collection) && is_array($this->collection))
574  {
575  /** @var Shipment $shipment */
576  foreach ($this->collection as $shipment)
577  {
578  if ($shipment->isSystem())
579  {
580  if (!$shipment->isEmpty())
581  {
582  return false;
583  }
584 
585  continue;
586  }
587 
588  if (!$shipment->isShipped() && !$shipment->isEmpty())
589  {
590  return false;
591  }
592  }
593 
594  return true;
595  }
596 
597  return false;
598  }

◆ load()

static load ( Order  $order)
static

Loaded from the database collection shipments Order.

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

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

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

◆ onBasketModify()

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

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

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

◆ onBeforeBasketItemDelete()

onBeforeBasketItemDelete ( BasketItem  $basketItem)

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

911  {
912  $result = new Result();
913 
914  /** @var Shipment $shipment */
915  foreach ($this->collection as $shipment)
916  {
917  $r = $shipment->onBeforeBasketItemDelete($basketItem);
918  if (!$r->isSuccess())
919  {
920  $result->addErrors($r->getErrors());
921  }
922  }
923 
924  return $result;
925  }

◆ 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
Исключения
Main

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

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

◆ onOrderModify()

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

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

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

◆ refreshData()

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

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

1216  {
1217  $result = new Result();
1218 
1219  $this->resetData();
1220 
1221  $r = $this->calculateDelivery();
1222  if (!$r->isSuccess())
1223  {
1224  $result->addErrors($r->getErrors());
1225  }
1226 
1227  return $result;
1228  }

◆ resetCollection()

resetCollection ( )

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

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

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

◆ resetData()

resetData ( )

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

1288  {
1289  $collection = $this->getNotSystemItems();
1290 
1291  /** @var Shipment $shipment */
1292  foreach ($collection as $shipment)
1293  {
1294  $shipment->resetData();
1295  }
1296  }

◆ save()

save ( )

Saving data collection.

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

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

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

◆ setOrder()

setOrder ( Order  $order)

The attachment order to the collection.

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

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

527  {
528  $this->order = $order;
529  }

◆ tryReserve()

tryReserve ( )

Trying to reserve the contents of the shipment collection.

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

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

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

◆ tryUnreserve()

tryUnreserve ( )

Trying to reserve the contents of the shipment collection.

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

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

842  {
843  $result = new Result();
844 
845  if (!$order = $this->getOrder())
846  {
847  throw new Main\ObjectNotFoundException('Entity "Order" not found');
848  }
849  /** @var Shipment $shipment */
850  foreach ($this->collection as $shipment)
851  {
852  if ($shipment->isShipped())
853  {
854  if ($order &&
855  !Internals\ActionEntity::isTypeExists(
856  $order->getInternalId(),
858  )
859  )
860  {
862  $order->getInternalId(),
864  array(
865  'METHOD' => 'Bitrix\Sale\Shipment::updateReservedFlag',
866  'PARAMS' => array($shipment)
867  )
868  );
869  }
870 
871  continue;
872  }
873 
874  $r = $shipment->tryUnreserve();
875  if (!$r->isSuccess())
876  {
877  if (!$shipment->isSystem())
878  {
879  $registry = Registry::getInstance(static::getRegistryType());
880 
881  /** @var EntityMarker $entityMarker */
882  $entityMarker = $registry->getEntityMarkerClassName();
883  $entityMarker::addMarker($order, $shipment, $r);
884 
885  $shipment->setField('MARKED', 'Y');
886  }
887  $result->addErrors($r->getErrors());
888  }
889  elseif ($r->hasWarnings())
890  {
891  $result->addWarnings($r->getWarnings());
892  }
893  }
894 
895  return $result;
896  }
static add($code, $type, $value)
Definition: poolbase.php:51
static isTypeExists($code, $type)
Definition: poolbase.php:76

◆ updateReservedFlag()

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

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

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

◆ verify()

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

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

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

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

Поля

◆ $order

$order
protected

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


Объявления и описания членов класса находятся в файле: