1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
shipmentcollection.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale;
4
5use Bitrix\Main;
6use Bitrix\Main\Entity;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Sale\Delivery;
9use Bitrix\Sale\Internals;
10use Bitrix\Sale\Reservation\Configuration\ReserveCondition;
11
12Loc::loadMessages(__FILE__);
13
20{
22 protected $order;
23
28 protected function getEntityParent()
29 {
30 return $this->getOrder();
31 }
32
43 public function resetCollection()
44 {
45 $result = new Result();
46
47 $deliveryInfo = array();
48
49 if (count($this->collection) > 0)
50 {
52 foreach ($this->collection as $shipment)
53 {
54 if (empty($deliveryInfo))
55 {
56 if ($shipment->isSystem() && $shipment->getDeliveryId() > 0)
57 {
58 foreach (static::getClonedFields() as $field)
59 {
60 if (strval(trim($shipment->getField($field))) != '')
61 $deliveryInfo[$field] = trim($shipment->getField($field));
62 }
63 }
64 }
65 $shipment->delete();
66 }
67 }
68
69 $systemShipment = $this->getSystemShipment();
70
72 $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
73
75 $basket = $this->getOrder()->getBasket();
76 $systemShipmentItemCollection->resetCollection($basket);
77
78 if (!empty($deliveryInfo))
79 {
80 $systemShipment->setFieldsNoDemand($deliveryInfo);
81 }
82
83 if (
85 && Configuration::getProductReservationCondition() == ReserveCondition::ON_CREATE
86 )
87 {
88 $r = $this->tryReserve();
89 if (!$r->isSuccess())
90 {
91 $result->addErrors($r->getErrors());
92 }
93 }
94
95 return $result;
96 }
97
101 protected function getDeletableItems()
102 {
103 return $this->getNotSystemItems();
104 }
105
114 public function createItem(Delivery\Services\Base $delivery = null)
115 {
117 $shipmentClassName = static::getItemCollectionClassName();
118 $shipment = $shipmentClassName::create($this, $delivery);
119 $this->addItem($shipment);
120
121 return $shipment;
122 }
123
131 protected function addItem(Internals\CollectableEntity $shipment)
132 {
134 $shipment = parent::addItem($shipment);
135
137 if (!$order = $this->getOrder())
138 {
139 throw new Main\ObjectNotFoundException('Entity "Order" not found');
140 }
141
142 $order->onShipmentCollectionModify(EventActions::ADD, $shipment);
143
144 return $shipment;
145 }
146
154 public function deleteItem($index)
155 {
156 $result = new Result();
158 $oldItem = parent::deleteItem($index);
159
161 if ($oldItem->getId() > 0 && !$oldItem->isSystem() && ($systemShipment = $this->getSystemShipment()) && $systemShipment->getId() == 0)
162 {
163 $r = $this->cloneShipment($oldItem, $systemShipment);
164 if (!$r->isSuccess())
165 {
166 $result->addErrors($r->getErrors());
167 }
168 }
169
170 $order = $this->getOrder();
171 $order->onShipmentCollectionModify(EventActions::DELETE, $oldItem);
172 }
173
190 public function onItemModify(Internals\CollectableEntity $item, $name = null, $oldValue = null, $value = null)
191 {
193 $order = $this->getOrder();
194
195 if ($item instanceof Shipment)
196 {
197 return $order->onShipmentCollectionModify(EventActions::UPDATE, $item, $name, $oldValue, $value);
198 }
199
200 return new Result();
201 }
202
208 public function getOrder()
209 {
210 return $this->order;
211 }
212
219 public static function load(Order $order)
220 {
222 $shipmentCollection = static::createShipmentCollectionObject();
223 $shipmentCollection->setOrder($order);
224
225 if ($order->getId() > 0)
226 {
228 $shipmentClassName = static::getItemCollectionClassName();
229 $shipmentList = $shipmentClassName::loadForOrder($order->getId());
231 foreach ($shipmentList as $shipment)
232 {
233 $shipment->setCollection($shipmentCollection);
234 $shipmentCollection->bindItem($shipment);
235 }
236
237 $controller = Internals\CustomFieldsController::getInstance();
238 $controller->initializeCollection($shipmentCollection);
239 }
240
241 return $shipmentCollection;
242 }
243
247 private static function createShipmentCollectionObject()
248 {
249 $registry = Registry::getInstance(static::getRegistryType());
250 $className = $registry->getShipmentCollectionClassName();
251
252 return new $className();
253 }
254
258 public static function getRegistryType()
259 {
261 }
262
268 public function getSystemShipment()
269 {
271 foreach ($this->collection as $shipment)
272 {
273 if ($shipment->isSystem())
274 {
275 return $shipment;
276 }
277 }
278
280 $shipmentClassName = static::getItemCollectionClassName();
281 $shipment = $shipmentClassName::createSystem($this);
282 $this->addItem($shipment);
283
284 return $shipment;
285 }
286
292 public function isExistsSystemShipment()
293 {
295 foreach ($this->collection as $shipment)
296 {
297 if ($shipment->isSystem())
298 return true;
299 }
300
301 return false;
302 }
303
312 public function save()
313 {
314 $result = new Entity\Result();
315
317 if (!$order = $this->getOrder())
318 {
319 throw new Main\ObjectNotFoundException('Entity "Order" not found');
320 }
321
322 $itemsFromDb = array();
323 if ($order->getId() > 0)
324 {
325 $itemsFromDbList = static::getList(
326 array(
327 "filter" => array("ORDER_ID" => $order->getId()),
328 "select" => array("ID" , "DELIVERY_NAME", "DELIVERY_ID")
329 )
330 );
331 while ($itemsFromDbItem = $itemsFromDbList->fetch())
332 $itemsFromDb[$itemsFromDbItem["ID"]] = $itemsFromDbItem;
333 }
334
336 foreach ($this->collection as $shipment)
337 {
338 if ($shipment->isSystem())
339 continue;
340
341 if (($systemShipment = $this->getSystemShipment()) && $systemShipment->getId() == 0)
342 {
344 $r = $this->cloneShipment($shipment, $systemShipment);
345 if ($r->isSuccess())
346 {
347 break;
348 }
349 else
350 {
351 $result->addErrors($r->getErrors());
352 }
353 }
354 }
355
356 $changeMeaningfulFields = array(
357 "DELIVERY_LOCATION",
358 "PRICE_DELIVERY",
359 "CUSTOM_PRICE_DELIVERY",
360 "ALLOW_DELIVERY",
361 "DEDUCTED",
362 "RESERVED",
363 "DELIVERY_NAME",
364 "DELIVERY_ID",
365 "CANCELED",
366 "MARKED",
367 "SYSTEM",
368 "COMPANY_ID",
369 "DISCOUNT_PRICE",
370 "BASE_PRICE_DELIVERY",
371 "EXTERNAL_DELIVERY",
372 );
373
375 foreach ($this->collection as $shipment)
376 {
377 $isNew = (bool)($shipment->getId() <= 0);
378 $isChanged = $shipment->isChanged();
379
380 if ($order->getId() > 0 && $isChanged)
381 {
382 $logFields = array();
383
384
385 $fields = $shipment->getFields();
386 $originalValues = $fields->getOriginalValues();
387
388 foreach($originalValues as $originalFieldName => $originalFieldValue)
389 {
390 if (in_array($originalFieldName, $changeMeaningfulFields) && $shipment->getField($originalFieldName) != $originalFieldValue)
391 {
392 $logFields[$originalFieldName] = $shipment->getField($originalFieldName);
393 if (!$isNew)
394 $logFields['OLD_'.$originalFieldName] = $originalFieldValue;
395 }
396 }
397
398 }
399
400 $r = $shipment->save();
401 if ($r->isSuccess())
402 {
403 if ($order->getId() > 0)
404 {
405 if ($isChanged)
406 {
407 $registry = Registry::getInstance(static::getRegistryType());
408
410 $orderHistory = $registry->getOrderHistoryClassName();
411 $orderHistory::addLog(
412 'SHIPMENT',
413 $order->getId(),
414 $isNew ? 'SHIPMENT_ADD' : 'SHIPMENT_UPDATE',
415 $shipment->getId(),
416 $shipment,
417 $logFields,
418 $orderHistory::SALE_ORDER_HISTORY_LOG_LEVEL_1
419 );
420
421 $orderHistory::addAction(
422 'SHIPMENT',
423 $order->getId(),
424 "SHIPMENT_SAVED",
425 $shipment->getId(),
426 $shipment,
427 array(),
429 );
430 }
431 }
432
433 }
434 else
435 {
436 $result->addErrors($r->getErrors());
437 }
438
439 if (isset($itemsFromDb[$shipment->getId()]))
440 unset($itemsFromDb[$shipment->getId()]);
441 }
442
443 foreach ($itemsFromDb as $k => $v)
444 {
445 $v['ENTITY_REGISTRY_TYPE'] = static::getRegistryType();
446
448 $event = new Main\Event('sale', "OnBeforeSaleShipmentDeleted", array(
449 'VALUES' => $v,
450 ));
451 $event->send();
452
453 $this->deleteInternal($k);
455
457 $event = new Main\Event('sale', "OnSaleShipmentDeleted", array(
458 'VALUES' => $v,
459 ));
460 $event->send();
461
462 if ($order->getId() > 0)
463 {
464 $registry = Registry::getInstance(static::getRegistryType());
465
467 $orderHistory = $registry->getOrderHistoryClassName();
468 $orderHistory::addAction(
469 'SHIPMENT',
470 $order->getId(),
471 'SHIPMENT_REMOVED',
472 $k,
473 null,
474 array(
475 'ID' => $k,
476 'DELIVERY_NAME' => $v['DELIVERY_NAME'],
477 'DELIVERY_ID' => $v['DELIVERY_ID'],
478 )
479 );
480
481 $registry = Registry::getInstance(static::getRegistryType());
482
484 $entityMarker = $registry->getEntityMarkerClassName();
485 $entityMarker::deleteByFilter(array(
486 '=ORDER_ID' => $order->getId(),
487 '=ENTITY_TYPE' => $entityMarker::ENTITY_TYPE_SHIPMENT,
488 '=ENTITY_ID' => $k,
489 ));
490 }
491
492 }
493
494 if ($order->getId() > 0)
495 {
496 $registry = Registry::getInstance(static::getRegistryType());
497
499 $orderHistory = $registry->getOrderHistoryClassName();
500 $orderHistory::collectEntityFields('SHIPMENT', $order->getId());
501 }
502
503 return $result;
504 }
505
511 public function setOrder(Order $order)
512 {
513 $this->order = $order;
514 }
515
523 public function cloneShipment(Shipment $parentShipment, Shipment $childShipment)
524 {
525 foreach (static::getClonedFields() as $fieldName)
526 {
528 $childShipment->setFieldNoDemand($fieldName, $parentShipment->getField($fieldName));
529 }
530
531 $childShipment->setExtraServices($parentShipment->getExtraServices());
532 $childShipment->setStoreId($parentShipment->getStoreId());
533 return new Result();
534 }
535
541 protected static function getClonedFields()
542 {
543 return array(
544 'DELIVERY_LOCATION',
545 'PARAMS',
546 'DELIVERY_ID',
547 'DELIVERY_NAME',
548 );
549 }
550
556 public function isShipped()
557 {
558 if (!empty($this->collection) && is_array($this->collection))
559 {
561 foreach ($this->collection as $shipment)
562 {
563 if ($shipment->isSystem())
564 {
565 if (!$shipment->isEmpty())
566 {
567 return false;
568 }
569
570 continue;
571 }
572
573 if (!$shipment->isShipped() && !$shipment->isEmpty())
574 {
575 return false;
576 }
577 }
578
579 return true;
580 }
581
582 return false;
583 }
584
590 public function hasShipped()
591 {
592 if (!empty($this->collection) && is_array($this->collection))
593 {
595 foreach ($this->collection as $shipment)
596 {
597 if ($shipment->isSystem())
598 {
599 continue;
600 }
601
602 if ($shipment->isShipped() && !$shipment->isEmpty())
603 {
604 return true;
605 }
606 }
607 }
608
609 return false;
610 }
611
617 public function isMarked()
618 {
619 if (!empty($this->collection) && is_array($this->collection))
620 {
622 foreach ($this->collection as $shipment)
623 {
624 if ($shipment->isSystem())
625 continue;
626
627 if ($shipment->isMarked())
628 return true;
629 }
630 }
631
632 return false;
633 }
634
640 public function isReserved()
641 {
642 if (!empty($this->collection) && is_array($this->collection))
643 {
645 foreach ($this->collection as $shipment)
646 {
647 if ($shipment->isSystem())
648 {
649 if (count($this->collection) == 1)
650 return $shipment->isReserved();
651
652 continue;
653 }
654
655 if (!$shipment->isReserved())
656 return false;
657 }
658
659 return true;
660 }
661
662 return false;
663 }
664
670 public function isAllowDelivery()
671 {
672 if (!empty($this->collection) && is_array($this->collection))
673 {
675 foreach ($this->collection as $shipment)
676 {
677 if ($shipment->isSystem())
678 {
679 if (!$shipment->isEmpty())
680 {
681 return false;
682 }
683
684 continue;
685 }
686
687 if (!$shipment->isAllowDelivery() && !$shipment->isEmpty())
688 {
689 return false;
690 }
691 }
692
693 return true;
694 }
695
696 return false;
697 }
698
702 public function hasAllowDelivery()
703 {
704 $collection = $this->getNotSystemItems();
705
707 foreach ($collection as $shipment)
708 {
709 if ($shipment->isAllowDelivery())
710 {
711 return true;
712 }
713 }
714
715 return false;
716 }
717
723 public function isEmptySystemShipment()
724 {
725 return $this->getSystemShipment()->isEmpty();
726 }
727
733 public function allowDelivery()
734 {
735 $result = new Result();
736
737 $collection = $this->getNotSystemItems();
738
740 foreach ($collection as $shipment)
741 {
742 $r = $shipment->allowDelivery();
743 if (!$r->isSuccess())
744 {
745 $result->addErrors($r->getErrors());
746 }
747 }
748 return $result;
749 }
750
755 public function disallowDelivery()
756 {
757 $result = new Result();
758
759 $collection = $this->getNotSystemItems();
760
762 foreach ($collection as $shipment)
763 {
764 $r = $shipment->disallowDelivery();
765 if (!$r->isSuccess())
766 {
767 $result->addErrors($r->getErrors());
768 }
769 }
770
771 return $result;
772 }
773
778 public function tryReserve()
779 {
780 $result = new Result();
781
783 foreach ($this->collection as $shipment)
784 {
785 if ($shipment->isReserved() || $shipment->isShipped())
786 continue;
787
788 $r = $shipment->tryReserve();
789 if (!$r->isSuccess())
790 {
791 $result->addErrors($r->getErrors());
792 }
793 elseif ($r->hasWarnings())
794 {
795 $result->addWarnings($r->getWarnings());
796
797 $registry = Registry::getInstance(static::getRegistryType());
799 $entityMarker = $registry->getEntityMarkerClassName();
800 $entityMarker::addMarker($this->getOrder(), $shipment, $r);
801 if (!$shipment->isSystem())
802 {
803 $shipment->setField('MARKED', 'Y');
804 }
805 }
806 }
807 return $result;
808 }
809
819 public function tryUnreserve()
820 {
821 $result = new Result();
822
823 if (!$order = $this->getOrder())
824 {
825 throw new Main\ObjectNotFoundException('Entity "Order" not found');
826 }
828 foreach ($this->collection as $shipment)
829 {
830 if ($shipment->isShipped())
831 {
832 if ($order &&
833 !Internals\ActionEntity::isTypeExists(
834 $order->getInternalId(),
836 )
837 )
838 {
839 Internals\ActionEntity::add(
840 $order->getInternalId(),
842 array(
843 'METHOD' => 'Bitrix\Sale\Shipment::updateReservedFlag',
844 'PARAMS' => array($shipment)
845 )
846 );
847 }
848
849 continue;
850 }
851
852 $r = $shipment->tryUnreserve();
853 if (!$r->isSuccess())
854 {
855 if (!$shipment->isSystem())
856 {
857 $registry = Registry::getInstance(static::getRegistryType());
858
860 $entityMarker = $registry->getEntityMarkerClassName();
861 $entityMarker::addMarker($order, $shipment, $r);
862
863 $shipment->setField('MARKED', 'Y');
864 }
865 $result->addErrors($r->getErrors());
866 }
867 elseif ($r->hasWarnings())
868 {
869 $result->addWarnings($r->getWarnings());
870 }
871 }
872
873 return $result;
874 }
875
888 public function onBeforeBasketItemDelete(BasketItem $basketItem)
889 {
890 $result = new Result();
891
893 foreach ($this->collection as $shipment)
894 {
895 $r = $shipment->onBeforeBasketItemDelete($basketItem);
896 if (!$r->isSuccess())
897 {
898 $result->addErrors($r->getErrors());
899 }
900 }
901
902 return $result;
903 }
904
919 public function onBasketModify($action, BasketItemBase $basketItem, $name = null, $oldValue = null, $value = null) : Result
920 {
921 $result = new Result();
922
923 if (!($basketItem instanceof BasketItem))
924 {
925 return $result;
926 }
927
929 {
930 $order = $this->getOrder();
931 if ($order->getId() == 0 && !$order->isMathActionOnly())
932 {
933 $this->refreshData();
934 }
935
936 return $result;
937 }
939 {
940 return $this->getSystemShipment()->onBasketModify($action, $basketItem, $name, $oldValue, $value);
941 }
943 {
944 return $result;
945 }
946
947 if ($name == 'QUANTITY')
948 {
949 if (!$this->isAllowAutoEdit($basketItem))
950 {
951 $result = $this->checkDistributedQuantity($basketItem, $value);
952 if (!$result->isSuccess())
953 {
954 return $result;
955 }
956 }
957
958 $shipment = $this->getItemForAutoEdit($basketItem);
959
960 if ($value - $oldValue > 0)
961 {
962 $r = $this->getSystemShipment()->onBasketModify($action, $basketItem, $name, $oldValue, $value);
963 if (!$r->isSuccess())
964 {
965 return $result->addErrors($r->getErrors());
966 }
967 }
968
969 if ($shipment)
970 {
971 $r = $shipment->onBasketModify($action, $basketItem, $name, $oldValue, $value);
972 if (!$r->isSuccess())
973 {
974 $result->addErrors($r->getErrors());
975 return $result;
976 }
977 }
978
979 if ($value - $oldValue < 0)
980 {
981 $r = $this->getSystemShipment()->onBasketModify($action, $basketItem, $name, $oldValue, $value);
982 if (!$r->isSuccess())
983 {
984 return $result->addErrors($r->getErrors());
985 }
986 }
987 }
988 elseif (in_array($name, ['WEIGHT', 'PRICE']))
989 {
991 foreach ($this->getNotSystemItems() as $shipment)
992 {
993 $shipment->onBasketModify($action, $basketItem, $name, $value, $oldValue);
994 }
995 }
996
997 return $result;
998 }
999
1006 private function getItemForAutoEdit(BasketItem $basketItem)
1007 {
1008 if ($this->isAllowAutoEdit($basketItem))
1009 {
1011 foreach ($this->getNotSystemItems() as $shipment)
1012 {
1013 return $shipment;
1014 }
1015 }
1016
1017 return null;
1018 }
1019
1026 protected function isAllowAutoEdit(BasketItem $basketItem)
1027 {
1028 if ($this->count() === 1
1029 ||
1030 (
1031 $this->count() === 2
1032 &&
1033 $this->isExistsSystemShipment()
1034 )
1035 )
1036 {
1037 if (!$this->getSystemShipment()->isExistBasketItem($basketItem)
1038 || (int)$basketItem->getId() === 0
1039 )
1040 {
1041 foreach ($this->getNotSystemItems() as $shipment)
1042 {
1043 if (!$shipment->isAllowDelivery()
1044 && !$shipment->isCanceled()
1045 && !$shipment->isShipped()
1046 )
1047 {
1049 if ($deliveryService = $shipment->getDelivery())
1050 {
1051 return $deliveryService->isAllowEditShipment();
1052 }
1053 }
1054 }
1055 }
1056 }
1057
1058 return false;
1059 }
1060
1069 private function checkDistributedQuantity(BasketItem $basketItem, $value)
1070 {
1071 $result = new Result();
1072
1073 $basketItemQuantity = $this->getBasketItemDistributedQuantity($basketItem);
1074 if ($basketItemQuantity > $value)
1075 {
1076 $result->addError(new ResultError(
1077 Loc::getMessage('SALE_ORDER_SYSTEM_SHIPMENT_LESS_QUANTITY',
1078 array(
1079 '#PRODUCT_NAME#' => $basketItem->getField("NAME"),
1080 '#BASKET_ITEM_QUANTITY#' => $basketItemQuantity,
1081 '#BASKET_ITEM_MEASURE#' => $basketItem->getField("MEASURE_NAME"),
1082 '#QUANTITY#' => $basketItemQuantity - $value
1083 )
1084 ),
1085 'SALE_ORDER_SYSTEM_SHIPMENT_LESS_QUANTITY')
1086 );
1087 }
1088
1089 return $result;
1090 }
1091
1103 public function onOrderModify($name, $oldValue, $value)
1104 {
1105 $result = new Result();
1106
1107 switch($name)
1108 {
1109 case "CANCELED":
1110 if ($value == "Y")
1111 {
1112 $isShipped = false;
1114 foreach ($this->collection as $shipment)
1115 {
1116 if ($shipment->isShipped())
1117 {
1118 $isShipped = true;
1119 break;
1120 }
1121 }
1122
1123 if ($isShipped)
1124 {
1125 $result->addError(
1126 new ResultError(
1127 Loc::getMessage('SALE_ORDER_CANCEL_SHIPMENT_EXIST_SHIPPED_MSGVER_1'),
1128 'SALE_ORDER_CANCEL_SHIPMENT_EXIST_SHIPPED'
1129 )
1130 );
1131
1132 return $result;
1133 }
1134
1135 $this->tryUnreserve();
1136 }
1138 {
1140 foreach ($this->collection as $shipment)
1141 {
1142 if ($shipment->needReservation())
1143 {
1145 $r = $shipment->tryReserve();
1146 if (!$r->isSuccess())
1147 {
1148 $registry = Registry::getInstance(static::getRegistryType());
1149
1151 $entityMarker = $registry->getEntityMarkerClassName();
1152 $entityMarker::addMarker($this->getOrder(), $shipment, $r);
1153 if (!$shipment->isSystem())
1154 {
1155 $shipment->setField('MARKED', 'Y');
1156 }
1157
1158 $result->addErrors($r->getErrors());
1159 }
1160 }
1161 }
1162
1163 }
1164 break;
1165
1166 case "MARKED":
1167 if ($value == "N")
1168 {
1170 foreach ($this->collection as $shipment)
1171 {
1172 if ($shipment->isSystem())
1173 continue;
1174
1175 $shipment->setField('MARKED', $value);
1176 }
1177 }
1178 break;
1179 }
1180
1181 return $result;
1182 }
1183
1188 public function refreshData()
1189 {
1190 $result = new Result();
1191
1192 $this->resetData();
1193
1194 $r = $this->calculateDelivery();
1195 if (!$r->isSuccess())
1196 {
1197 $result->addErrors($r->getErrors());
1198 }
1199
1200 return $result;
1201 }
1202
1206 public function calculateDelivery()
1207 {
1209 $result = new Result();
1210
1211 $calculatedDeliveries = [];
1212
1213 $collection = $this->getNotSystemItems();
1214
1216 foreach ($collection as $shipment)
1217 {
1218 if ($shipment->getDeliveryId() == 0)
1219 continue;
1220
1221 if ($shipment->isCustomPrice())
1222 {
1223 $priceDelivery = $shipment->getPrice();
1224
1225 $calcResult = new Delivery\CalculationResult();
1226 $calcResult->setDeliveryPrice($priceDelivery);
1227 }
1228 else
1229 {
1231 $calcResult = $shipment->calculateDelivery();
1232 if (!$calcResult->isSuccess())
1233 {
1234 $result->addErrors($calcResult->getErrors());
1235 continue;
1236 }
1237
1238 $priceDelivery = $calcResult->getPrice();
1239 if ($priceDelivery < 0)
1240 {
1241 $result->addError(new ResultError(Loc::getMessage('SALE_ORDER_SHIPMENT_WRONG_DELIVERY_PRICE'), 'WRONG_DELIVERY_PRICE'));
1242 continue;
1243 }
1244 }
1245
1246 $priceDelivery = PriceMaths::roundPrecision($priceDelivery);
1247 $shipment->setField('BASE_PRICE_DELIVERY', $priceDelivery);
1248
1249 $calculatedDeliveries[] = $calcResult;
1250 }
1251
1252 $result->setData(['CALCULATED_DELIVERIES' => $calculatedDeliveries]);
1253
1254 return $result;
1255 }
1256
1260 public function resetData()
1261 {
1262 $collection = $this->getNotSystemItems();
1263
1265 foreach ($collection as $shipment)
1266 {
1267 $shipment->resetData();
1268 }
1269 }
1270
1278 public function getBasketItemDistributedQuantity(BasketItem $basketItem)
1279 {
1280 $collection = $this->getNotSystemItems();
1281
1282 $allQuantity = 0;
1283
1285 foreach ($collection as $shipment)
1286 {
1287 $allQuantity += $shipment->getBasketItemQuantity($basketItem);
1288 }
1289
1290 return $allQuantity;
1291 }
1292
1300 public function getBasketItemShippedQuantity(BasketItem $basketItem)
1301 {
1302 $quantity = 0;
1303
1305 foreach ($this->collection as $shipment)
1306 {
1307 if ($shipment->isShipped())
1308 {
1309 $quantity += $shipment->getShipmentItemCollection()->getBasketItemQuantity($basketItem);
1310 }
1311 }
1312
1313 return $quantity;
1314 }
1315
1323 public function isExistBasketItem(BasketItem $basketItem, $includeSystemShipment = false)
1324 {
1326 foreach ($this->collection as $shipment)
1327 {
1328 if (!$includeSystemShipment && $shipment->isSystem())
1329 {
1330 continue;
1331 }
1332
1333 return $shipment->isExistBasketItem($basketItem);
1334 }
1335
1336 return false;
1337 }
1341 public function getBasePriceDelivery()
1342 {
1343 $collection = $this->getNotSystemItems();
1344
1345 $sum = 0;
1347 foreach ($collection as $shipment)
1348 {
1349 $sum += $shipment->getField('BASE_PRICE_DELIVERY');
1350 }
1351
1352 return $sum;
1353 }
1354
1358 public function getPriceDelivery()
1359 {
1360 $collection = $this->getNotSystemItems();
1361
1362 $sum = 0;
1364 foreach ($collection as $shipment)
1365 {
1366 $sum += $shipment->getPrice();
1367 }
1368
1369
1370 return $sum;
1371 }
1372
1377 public function getItemByShipmentCode($itemCode)
1378 {
1380 foreach ($this->collection as $shipment)
1381 {
1382 $shipmentCode = $shipment->getShipmentCode();
1383 if ($itemCode == $shipmentCode)
1384 return $shipment;
1385
1386 }
1387
1388 return null;
1389 }
1390
1399 public function verify()
1400 {
1401 $result = new Result();
1402
1404 foreach ($this->collection as $shipment)
1405 {
1406 if ($shipment->isSystem())
1407 {
1408 continue;
1409 }
1410
1411 $r = $shipment->verify();
1412 if (!$r->isSuccess())
1413 {
1414 $result->addErrors($r->getErrors());
1415
1416 $registry = Registry::getInstance(static::getRegistryType());
1417
1419 $entityMarker = $registry->getEntityMarkerClassName();
1420 $entityMarker::addMarker($this->getOrder(), $shipment, $r);
1421
1422 $shipment->setField('MARKED', 'Y');
1423 }
1424 }
1425
1426 return $result;
1427 }
1428
1435 public function createClone(\SplObjectStorage $cloneEntity)
1436 {
1437 if ($this->isClone() && $cloneEntity->contains($this))
1438 {
1439 return $cloneEntity[$this];
1440 }
1441
1443 $shipmentCollectionClone = parent::createClone($cloneEntity);
1444
1445 if ($this->order)
1446 {
1447 if ($cloneEntity->contains($this->order))
1448 {
1449 $shipmentCollectionClone->order = $cloneEntity[$this->order];
1450 }
1451 }
1452
1453 return $shipmentCollectionClone;
1454 }
1455
1461 public function getErrorEntity($value)
1462 {
1463 $className = null;
1465 foreach ($this->collection as $shipment)
1466 {
1467 if ($className = $shipment->getErrorEntity($value))
1468 {
1469 break;
1470 }
1471 }
1472
1473 return $className;
1474 }
1475
1481 public function canAutoFixError($value)
1482 {
1483 $autoFix = false;
1484
1486 foreach ($this->collection as $shipment)
1487 {
1488 if ($autoFix = $shipment->canAutoFixError($value))
1489 {
1490 break;
1491 }
1492 }
1493 return $autoFix;
1494 }
1495
1501 public static function updateReservedFlag(ShipmentCollection $collection)
1502 {
1503 $result = new Result();
1505 foreach ($collection as $shipment)
1506 {
1508 $shipmentClassName = static::getItemCollectionClassName();
1509 $r = $shipmentClassName::updateReservedFlag($shipment);
1510 if (!$r->isSuccess())
1511 {
1512 $result->addErrors($r->getErrors());
1513 }
1514
1515 if ($r->hasWarnings())
1516 {
1517 $result->addWarnings($r->getWarnings());
1518 }
1519 }
1520
1521 return $result;
1522 }
1523
1527 private static function getItemCollectionClassName()
1528 {
1529 $registry = Registry::getInstance(static::getRegistryType());
1530 return $registry->getShipmentClassName();
1531 }
1532
1537 public static function getList(array $parameters = array())
1538 {
1539 return Internals\ShipmentTable::getList($parameters);
1540 }
1541
1546 protected function deleteInternal($primary)
1547 {
1549 }
1550
1554 protected function deleteExtraServiceInternal($shipmentId)
1555 {
1557 }
1558
1559
1563 public function getNotSystemItems()
1564 {
1565 $callback = function (Shipment $shipment)
1566 {
1567 return !$shipment->isSystem();
1568 };
1569
1570 return new Internals\CollectionFilterIterator($this->getIterator(), $callback);
1571 }
1572
1573}
$sum
Определения checkout.php:6
static isEnableAutomaticReservation()
Определения configuration.php:86
static getProductReservationCondition()
Определения configuration.php:78
const ADD
Определения eventactions.php:8
const DELETE
Определения eventactions.php:10
const UPDATE
Определения eventactions.php:9
const ACTION_ENTITY_SHIPMENT_RESERVED_QUANTITY
Определения actionentity.php:12
static deleteWithItems($id)
Определения shipment.php:89
const SALE_ORDER_HISTORY_ACTION_LOG_LEVEL_1
Определения orderhistory.php:29
static roundPrecision($value)
Определения pricemaths.php:16
static getInstance($type)
Определения registry.php:183
const REGISTRY_TYPE_ORDER
Определения registry.php:16
setOrder(Order $order)
Определения shipmentcollection.php:511
static getList(array $parameters=array())
Определения shipmentcollection.php:1537
deleteExtraServiceInternal($shipmentId)
Определения shipmentcollection.php:1554
getStoreId()
Определения shipment.php:2130
setStoreId(int $storeId)
Определения shipment.php:2143
setFieldNoDemand($name, $value)
Определения shipment.php:866
getExtraServices()
Определения shipment.php:2080
setExtraServices(array $extraServices)
Определения shipment.php:2093
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$name
Определения menu_edit.php:35
$order
Определения payment.php:8
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$k
Определения template_pdf.php:567
$action
Определения file_dialog.php:21
$fields
Определения yandex_run.php:501