Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
transferprovidercompatibility.php
1<?php
2
4
8
13{
20 public function tryShip(array $products)
21 {
22 Main\Loader::includeModule('catalog');
23 $result = new Sale\Result();
24
25 $tryShipmentItemList = array();
26 $reservedQuantityList = array();
27 $shipmentItemParents = array();
28
29 $shipmentItemList = static::getShipmentItemListFromProducts($products);
30 if (!empty($shipmentItemList))
31 {
33 foreach ($shipmentItemList as $shipmentItem)
34 {
36 $shipmentItemCollection = $shipmentItem->getCollection();
37 if (!$shipmentItemCollection)
38 {
39 throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
40 }
41
42 $shipment = $shipmentItemCollection->getShipment();
43 if (!$shipment)
44 {
45 throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
46 }
47
48 $shipmentItemParents[$shipmentItem->getInternalIndex()] = $shipment;
49
50 $basketItem = $shipmentItem->getBasketItem();
51
52 $provider = $basketItem->getProviderEntity();
53
54 if ($provider instanceof Catalog\Product\CatalogProvider)
55 {
56 continue;
57 }
58
59 if ($shipment->needShip() === Sale\Internals\Catalog\Provider::SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_SHIP
60 && !array_key_exists($shipment->getInternalIndex(), $reservedQuantityList))
61 {
62 $reservedQuantityList[$shipment->getInternalIndex()] = static::getReservedQuantity($shipment);
63 }
64
65 $tryShipmentItemList[$shipmentItem->getInternalIndex()] = $shipmentItem;
66 }
67 }
68
69 if (!empty($tryShipmentItemList))
70 {
71
72 $reservedQuantityList = array();
73
74 $r = Sale\Provider::tryShipmentItemList($tryShipmentItemList);
75
76 if (!$r->isSuccess())
77 {
78 $result->addErrors($r->getErrors());
79 }
80
81 $data = $r->getData();
82 if (!empty($data) && is_array($data))
83 {
88 foreach ($data as $basketCode => $resultTryShipment)
89 {
90 if (!$resultTryShipment->isSuccess())
91 {
92 $result->addErrors($resultTryShipment->getErrors());
93 }
94 }
95 }
96
97 if ($result->isSuccess())
98 {
99 if (!empty($reservedQuantityList))
100 {
101 static::setReservedQuantityToShipmentItem($tryShipmentItemList, $reservedQuantityList);
102 }
103
104 $resultList = static::createListFromTryShipmentResult($tryShipmentItemList, $r);
105 }
106 }
107
108 if (!empty($resultList))
109 {
110 $result->addData(
111 array(
112 'TRY_SHIP_PRODUCTS_LIST' => $resultList
113 )
114 );
115 }
116
117 return $result;
118 }
119
126 public function isNeedShip(array $products)
127 {
128 Main\Loader::includeModule('catalog');
129 $result = new Sale\Result();
130
131 $resultNeedShipList = array();
132 $needShipmentItemList = array();
133
134 $shipmentItemList = static::getShipmentItemListFromProducts($products);
135 if (!empty($shipmentItemList))
136 {
138 foreach ($shipmentItemList as $shipmentItem)
139 {
141 $shipmentItemCollection = $shipmentItem->getCollection();
142 if (!$shipmentItemCollection)
143 {
144 throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
145 }
146
147 $shipment = $shipmentItemCollection->getShipment();
148 if (!$shipment)
149 {
150 throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
151 }
152
153 $basketItem = $shipmentItem->getBasketItem();
154
155 $provider = $basketItem->getProviderEntity();
156
157 if ($provider instanceof Catalog\Product\CatalogProvider)
158 {
159 continue;
160 }
161
162 $needShipmentItemList[$shipmentItem->getInternalIndex()] = $shipmentItem;
163 }
164 }
165
166 if (!empty($needShipmentItemList))
167 {
168 $r = Sale\Provider::isNeedShip($needShipmentItemList);
169 if (!$r->isSuccess())
170 {
171 $result->addErrors($r->getErrors());
172 }
173
174 $data = $r->getData();
175 if (!empty($data) && is_array($data))
176 {
177 $needShipmentItemList = $data;
178 }
179
180 }
181
182 if (!empty($needShipmentItemList))
183 {
184 $result->setData(
185 array(
186 'IS_NEED_SHIP' => $needShipmentItemList
187 )
188 );
189 }
190
191 return $result;
192 }
193
200 private static function getReservedQuantity(Sale\Shipment $shipment)
201 {
202 $reservedQuantityList = array();
203 $shipmentItemCollection = $shipment->getShipmentItemCollection();
204 if (!$shipmentItemCollection)
205 {
206 throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
207 }
208
210 foreach ($shipmentItemCollection as $shipmentItem)
211 {
212 $reservedQuantityList[$shipmentItem->getInternalIndex()] = $shipmentItem->getReservedQuantity();
213 }
214
215 return $reservedQuantityList;
216 }
217
224 private static function setReservedQuantityToShipmentItem($shipmentItemList, array $reservedQuantityList)
225 {
227 foreach ($shipmentItemList as $shipmentItem)
228 {
229 $shipmentItemIndex = $shipmentItem->getInternalIndex();
230 if (!empty($reservedQuantityList[$shipmentItemIndex]))
231 {
232 $shipmentItem->setFieldNoDemand('RESERVED_QUANTITY', $reservedQuantityList[$shipmentItemIndex]);
233 }
234 }
235
236 }
237
244 public function ship(array $products)
245 {
246 $basketItemList = array();
247 $shipmentItemList = array();
248 $basketItemShipmentItemList = array();
249 $shipmentItemQuantityList = array();
250
251 $oneReserveStatus = true;
252 $needReserved = null;
253 $reservedList = array();
254
255 $resultList = array();
256
257 foreach ($products as $productId => $itemData)
258 {
259 $fields = $itemData;
260
261 if (!empty($fields['SHIPMENT_ITEM_LIST']))
262 {
264 foreach ($fields['SHIPMENT_ITEM_LIST'] as $shipmentIndexItem => $shipmentItem)
265 {
266 $shipmentItemList[$shipmentIndexItem] = $shipmentItem;
267
268 $basketItem = $shipmentItem->getBasketItem();
269 if (!$basketItem)
270 {
271 throw new Main\ObjectNotFoundException('Entity "BasketItemBase" not found');
272 }
273//
274 $basketCode = $basketItem->getBasketCode();
275 $basketItemList[$basketCode] = $basketItem;
276//
277// /** @var Sale\ShipmentItemCollection $shipmentItemCollection */
278// $shipmentItemCollection = $shipmentItem->getCollection();
279// if (!$shipmentItemCollection)
280// {
281// throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
282// }
283//
284// $shipment = $shipmentItemCollection->getShipment();
285// if (!$shipment)
286// {
287// throw new Main\ObjectNotFoundException('Entity "Shipment" not found');
288// }
289//
290 $basketItemShipmentItemList[$basketCode][$shipmentIndexItem] = $shipmentItem;
291 }
292 }
293
294 if (!empty($fields['NEED_RESERVE_LIST']))
295 {
296 foreach ($fields['NEED_RESERVE_LIST'] as $shipmentItemIndex => $reserved)
297 {
298 $reserveValue = $reserved ? 'Y': 'N';
299
300 $reservedList[$reserveValue][] = $shipmentItemIndex;
301 if (!empty($reservedList) && !isset($reservedList[$reserveValue]))
302 {
303 $oneReserveStatus = false;
304 }
305 elseif ($needReserved === null)
306 {
307 $needReserved = $reserved;
308 }
309
310 }
311 }
312
313 if (!empty($fields['SHIPMENT_ITEM_QUANTITY_LIST']))
314 {
315 foreach ($fields['SHIPMENT_ITEM_QUANTITY_LIST'] as $shipmentItemIndex => $quantity)
316 {
317 $shipmentItemQuantityList[$fields['BASKET_CODE']][$shipmentItemIndex] = $quantity;
318 }
319 }
320
321 $resultList[$productId] = false;
322 }
323
324 $result = new Sale\Result();
325
326 $r = static::tryShip($products);
327 if (!$r->isSuccess())
328 {
329 $result->addErrors($r->getErrors());
330 }
331 elseif ($r->hasWarnings())
332 {
333 $result->addWarnings($r->getWarnings());
334 }
335
336 if (!empty($basketItemList))
337 {
339 foreach ($basketItemList as $basketItem)
340 {
341 $productId = $basketItem->getProductId();
342 $productData = $products[$productId];
343 $basketCode = $basketItem->getBasketCode();
344 $quantity = $productData['QUANTITY_LIST'][$basketCode];
345
346 $shipmentFieldsList = array();
347 if (!$oneReserveStatus)
348 {
353 foreach ($reservedList as $reserveValue => $shipmentItemIndexList)
354 {
355 $quantity = 0;
356 foreach ($shipmentItemIndexList as $shipmentItemIndex)
357 {
358 if (isset($shipmentItemQuantityList[$basketCode][$shipmentItemIndex]))
359 {
360 $quantity += $shipmentItemQuantityList[$basketCode][$shipmentItemIndex];
361 }
362 }
363
364
365 $shipmentFieldsList[] = array(
366 'BASKET_ITEM' => $basketItem,
367 'BASKET_CODE' => $basketItem->getBasketCode(),
368 'PRODUCT_ID' => $productId,
369 'QUANTITY' => abs($quantity),
370 'DEDUCTED' => $quantity < 0,
371 'RESERVED' => $reserveValue,
372 );
373 }
374 }
375 else
376 {
377 $shipmentFieldsList[] = array(
378 'BASKET_ITEM' => $basketItem,
379 'BASKET_CODE' => $basketItem->getBasketCode(),
380 'PRODUCT_ID' => $productId,
381 'QUANTITY' => abs($quantity),
382 'DEDUCTED' => $quantity < 0,
383 'RESERVED' => $needReserved,
384 );
385 }
386
387
388
389 $provider = $basketItem->getProvider();
390
391 $storeDataList = array();
392
393 if (!empty($productData['STORE_DATA_LIST']))
394 {
395 $storeDataList = $productData['STORE_DATA_LIST'];
396 }
397
398 foreach ($shipmentFieldsList as $shipFields)
399 {
400 $r = Sale\Provider::shipProductData($provider, $shipFields, $storeDataList);
401 if ($r->isSuccess())
402 {
403 $productId = $basketItem->getProductId();
404 $resultList[$productId] = true;
405 }
406 elseif ($r->hasWarnings())
407 {
408 $result->addWarnings($r->getWarnings());
409 }
410 else
411 {
412 $result->addErrors($r->getErrors());
413 }
414 }
415 }
416 }
417
418 if (!empty($resultList))
419 {
420 $result->setData(
421 array(
422 'SHIPPED_PRODUCTS_LIST' => $resultList
423 )
424 );
425 }
426
427 return $result;
428 }
429
436 public function reserve(array $products)
437 {
438 $result = new Sale\Result();
439 $resultList = array();
440
441 foreach ($products as $productId => $productData)
442 {
443 $productQuantity = 0;
444 if (array_key_exists('QUANTITY', $productData))
445 {
446 $productQuantity = $productData['QUANTITY'];
447 }
448 elseif (!empty($productData['QUANTITY_LIST']))
449 {
450 foreach ($productData['QUANTITY_LIST'] as $basketCode => $quantity)
451 {
452 $productQuantity += $quantity;
453 }
454 }
455
460 $r = Sale\Provider::reserveProduct($this->getProviderClass(), $productId, $productQuantity);
461 if ($r->isSuccess())
462 {
463 $fields = $r->getData();
464 if (!empty($fields))
465 {
466 $resultList[$productId] = array(
467 'QUANTITY_RESERVED' => $fields['QUANTITY']
468 );
469 }
470 }
471 else
472 {
473 $result->addErrors($r->getErrors());
474 }
475
476 if ($r->hasWarnings())
477 {
478 $result->addWarnings($r->getWarnings());
479 }
480 }
481
482 if (!empty($resultList))
483 {
484 $result->setData(
485 array(
486 'RESERVED_PRODUCTS_LIST' => $resultList
487 )
488 );
489 }
490
491 return $result;
492 }
493
499 private static function getShipmentItemListFromProducts(array $products)
500 {
501 $resultList = array();
502
503 foreach ($products as $productData)
504 {
506 foreach ($productData['SHIPMENT_ITEM_LIST'] as $shipmentItem)
507 {
508 if (!array_key_exists($shipmentItem->getInternalIndex(), $resultList))
509 {
510 $resultList[$shipmentItem->getInternalIndex()] = $shipmentItem;
511 }
512 }
513 }
514
515 return $resultList;
516 }
517
525 private static function createListFromTryShipmentResult($shipmentItemList, Sale\Result $result)
526 {
527 if (!$result->isSuccess())
528 {
529 return array();
530 }
531
532 $basketCodeList = array();
533 $basketItemList = array();
534 foreach ($shipmentItemList as $shipmentItem)
535 {
536 $basketItem = $shipmentItem->getBasketItem();
537 $basketCodeList[$shipmentItem->getInternalIndex()] = $basketItem->getBasketCode();
538
539 $basketItemList[$basketItem->getBasketCode()] = $basketItem;
540 }
541
542 $resultList = array();
543
544 $data = $result->getData();
545 if (!empty($data))
546 {
551 foreach ($data as $basketCode => $resultTryShipment)
552 {
553 if (!isset($basketItemList[$basketCode]))
554 {
555 throw new Main\ObjectNotFoundException('Entity "Basket" not found');
556 }
557
558 $basketItem = $basketItemList[$basketCode];
559
560 $resultList[$basketItem->getProductId()] = $resultTryShipment->isSuccess();
561 }
562 }
563
564 return $resultList;
565 }
566
575 public function setItemsResultAfterTryShip(PoolQuantity $pool, array $products, array $productTryShipList)
576 {
577 return new Sale\Result();
578 }
579
588 public function setItemsResultAfterTryUnship(PoolQuantity $pool, array $products, array $productTryShipList)
589 {
590 return new Sale\Result();
591 }
592
599 public function getAvailableQuantity(array $products)
600 {
602 return Sale\Provider::getAvailableQuantity($this->getProviderClass(), $products, $this->getContext());
603 }
604
611 public function getAvailableQuantityAndPrice(array $products)
612 {
614 return Sale\Provider::getAvailableQuantityAndPrice($this->getProviderClass(), $products, $this->getContext());
615 }
616
623 public function getProductData(array $products)
624 {
625 $providerName = null;
627 if ($providerClass)
628 {
629 $reflect = new \ReflectionClass($providerClass);
630 $providerName = $reflect->getName();
631 }
632
633 return Sale\Provider::getProductDataByList($products, $providerName, array('PRICE','QUANTITY','CHECK_DISCOUNT', 'AVAILABLE_QUANTITY', 'COUPONS'), $this->getContext());
634 }
635
641 public function getBundleItems(array $products)
642 {
643 return Sale\Provider::getBundleChildItems($this->getProviderClass(), $products);
644 }
645
649 public function getStoresCount()
650 {
651 $context = $this->getContext();
652 $parameters = (isset($context['SITE_ID'])? array("SITE_ID" => $context['SITE_ID']) : array());
653 return Sale\Provider::getStoresCount($parameters);
654 }
655
656
663 public function deliver(array $products)
664 {
665 Main\Loader::includeModule('catalog');
666 $result = new Sale\Result();
667 $resultList = array();
668
669 $productOrderList = Catalog\Product\CatalogProvider::createOrderListFromProducts($products);
670 foreach ($products as $productId => $productData)
671 {
672 if (empty($productOrderList[$productId]))
673 {
674 continue;
675 }
676
678 foreach ($productOrderList[$productId] as $order)
679 {
680 $resultList[$productId] = false;
681 if (!empty($productData['SHIPMENT_ITEM_LIST']))
682 {
683
684 $quantityList = array();
685
686 if (isset($productData['QUANTITY_LIST']))
687 {
688 $quantityList = $productData['QUANTITY_LIST'];
689 }
694 foreach ($productData['SHIPMENT_ITEM_LIST'] as $shipmentIndex => $shipmentItem)
695 {
696
698 $shipmentItemCollection = $shipmentItem->getCollection();
699 if (!$shipmentItemCollection)
700 {
701 throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found');
702 }
703
704 $shipment = $shipmentItemCollection->getShipment();
705
706 $basketItem = $shipmentItem->getBasketItem();
707
708 $basketCode = $basketItem->getBasketCode();
709 $quantity = null;
710
711 if (isset($quantityList[$basketCode]))
712 {
713 $quantity = $quantityList[$basketCode];
714 }
715
716 $fields = array(
717 "PRODUCT_ID" => $productId,
718 "USER_ID" => $order->getUserId(),
719 "PAID" => $order->isPaid() ? 'Y' : 'N',
720 "ORDER_ID" => $order->getId(),
721
722 "BASKET_CODE" => $basketCode,
723 "CALLBACK_FUNC" => $basketItem->getField('CALLBACK_FUNC'),
724 "MODULE" => $basketItem->getField('MODULE'),
725 "ALLOW_DELIVERY" => $shipment->getField('ALLOW_DELIVERY'),
726 "QUANTITY" => $quantity,
727 );
728
729 $r = Sale\Provider::deliverProductData($this->getProviderClass(), $fields);
730 if ($r->isSuccess())
731 {
732 $resultData = $r->getData();
733
734 if (array_key_exists($productId, $resultData))
735 {
736 $resultList[$productId] = $resultData[$productId];
737 }
738 }
739 }
740 }
741
742 }
743
744 }
745
746
747 if (!empty($resultList))
748 {
749 $result->setData(
750 array(
751 'DELIVER_PRODUCTS_LIST' => $resultList
752 )
753 );
754 }
755
756 return $result;
757 }
758
765 public function viewProduct(array $products)
766 {
767 global $USER;
768 Main\Loader::includeModule('catalog');
769 $result = new Sale\Result();
770 $resultList = array();
771
772 $productOrderList = Catalog\Product\CatalogProvider::createOrderListFromProducts($products);
773 foreach ($products as $productId => $productData)
774 {
775 $productParamsList = array();
776 if (!empty($productOrderList[$productId]))
777 {
779 foreach ($productOrderList[$productId] as $order)
780 {
781 $hash = $order->getUserId()."|".$order->getSiteId();
782
783 if (!isset($productParamsList[$hash]))
784 {
785 $productParamsList[$hash] = array(
786 'PRODUCT_ID' => $productId,
787 'USER_ID' => $order->getUserId(),
788 'SITE_ID' => $order->getSiteId(),
789 );
790 }
791
792 }
793 }
794 else
795 {
796 $hash = $USER->getId() . "|" .SITE_ID;
797 if (!isset($productParamsList[$hash]))
798 {
799 $productParamsList[$hash] = array(
800 'PRODUCT_ID' => $productId,
801 'USER_ID' => $USER->getId(),
802 'SITE_ID' => SITE_ID,
803 );
804 }
805 }
806
807 foreach ($productParamsList as $productParams)
808 {
809 $r = Sale\Provider::getViewProduct($this->getProviderClass(), $productParams);
810 if ($r->isSuccess())
811 {
812 $resultData = $r->getData();
813 if (array_key_exists($productId, $resultData))
814 {
815 $resultList[$productId] = $resultData[$productId];
816 }
817
818 }
819 }
820
821 }
822
823
824 if (!empty($resultList))
825 {
826 $result->setData(
827 array(
828 'VIEW_PRODUCTS_LIST' => $resultList
829 )
830 );
831 }
832
833 return $result;
834 }
835
842 public function getProductListStores(array $products)
843 {
844 Main\Loader::includeModule('catalog');
845 $result = new Sale\Result();
846 $resultList = array();
847
848
849 $productOrderList = Catalog\Product\CatalogProvider::createOrderListFromProducts($products);
850 foreach ($products as $productId => $productData)
851 {
852 $productParamsList = array();
853 if (!empty($productOrderList[$productId]))
854 {
856 foreach ($productOrderList[$productId] as $order)
857 {
858 $hash = $order->getSiteId();
859
860 if (!isset($productParamsList[$hash]))
861 {
862 $productParamsList[$hash] = array(
863 'PRODUCT_ID' => $productId,
864 'SITE_ID' => $order->getSiteId(),
865 );
866 }
867
868 }
869 }
870 else
871 {
872 $hash = SITE_ID;
873 if (!isset($productParamsList[$hash]))
874 {
875 $productParamsList[$hash] = array(
876 'PRODUCT_ID' => $productId,
877 'SITE_ID' => SITE_ID,
878 );
879 }
880 }
881
882 foreach ($productParamsList as $productParams)
883 {
884 $r = Sale\Provider::getStores($this->getProviderClass(), $productParams);
885 if ($r->isSuccess())
886 {
887 $resultData = $r->getData();
888 if (array_key_exists($productId, $resultData))
889 {
890 $resultList[$productId] = $resultData[$productId];
891 }
892
893 }
894 }
895
896 }
897
898 if (!empty($resultList))
899 {
900 $result->setData(
901 array(
902 'PRODUCT_STORES_LIST' => $resultList
903 )
904 );
905 }
906
907 return $result;
908 }
909
916 public function checkBarcode(array $items)
917 {
918 $result = new Sale\Result();
919 $resultList = array();
920
921 foreach ($items as $productId => $barcodeParams)
922 {
927 $r = Sale\Provider::checkBarcode($this->getProviderClass(), $barcodeParams);
928 if ($r->isSuccess())
929 {
930 $resultData = $r->getData();
931 if (!empty($resultData) && array_key_exists($productId, $resultData))
932 {
933 $resultList[$barcodeParams['BARCODE']] = $resultData[$productId];
934 }
935 }
936 else
937 {
938 $result->addErrors($r->getErrors());
939 }
940
941 if ($r->hasWarnings())
942 {
943 $result->addWarnings($r->getWarnings());
944 }
945 }
946
947 if (!empty($resultList))
948 {
949 $result->setData(
950 array(
951 'RESERVED_PRODUCTS_LIST' => $resultList
952 )
953 );
954 }
955
956 return $result;
957 }
958
965 public function recurring(array $products)
966 {
967 global $USER;
968 Main\Loader::includeModule('catalog');
969
970 $result = new Sale\Result();
971 $resultList = array();
972
973 $productOrderList = Catalog\Product\CatalogProvider::createOrderListFromProducts($products);
974 foreach ($products as $productId => $productData)
975 {
976 $productParamsList = array();
977 if (!empty($productOrderList[$productId]))
978 {
980 foreach ($productOrderList[$productId] as $order)
981 {
982 $hash = $order->getUserId();
983
984 if (!isset($productParamsList[$hash]))
985 {
986 $productParamsList[$hash] = array(
987 'PRODUCT_ID' => $productId,
988 'USER_ID' => $order->getUserId(),
989 );
990 }
991
992 }
993 }
994 else
995 {
996 $hash = $USER->getId();
997 if (!isset($productParamsList[$hash]))
998 {
999 $productParamsList[$hash] = array(
1000 'PRODUCT_ID' => $productId,
1001 'USER_ID' => $USER->getId(),
1002 );
1003 }
1004 }
1005
1006 foreach ($productParamsList as $productParams)
1007 {
1008 $r = Sale\Provider::recurringProduct($this->getProviderClass(), $productParams);
1009 if ($r->isSuccess())
1010 {
1011 $resultData = $r->getData();
1012
1013 if (array_key_exists($productId, $resultData))
1014 {
1015 $resultList[$productId] = $resultData[$productId];
1016 }
1017 }
1018 }
1019
1020 }
1021
1022
1023 if (!empty($resultList))
1024 {
1025 $result->setData(
1026 array(
1027 'RECURRING_PRODUCTS_LIST' => $resultList
1028 )
1029 );
1030 }
1031
1032 return $result;
1033 }
1034
1041 public function getAvailableQuantityByStore(array $products)
1042 {
1043 $result = $this->getAvailableQuantity($products);
1044
1045 $resultData = $result->getData();
1046 if (!array_key_exists('AVAILABLE_QUANTITY_LIST', $resultData))
1047 {
1048 return $result;
1049 }
1050
1051 $quantityByStore = [];
1052
1053 foreach ($products as $productId => $item)
1054 {
1055 $quantityByStore[$productId] = $this->distributeQuantityByStore(
1056 $item['QUANTITY_LIST_BY_STORE'],
1057 $resultData['AVAILABLE_QUANTITY_LIST'][$productId]
1058 );
1059 }
1060
1061 return $result->setData(['AVAILABLE_QUANTITY_LIST_BY_STORE' => $quantityByStore]);
1062 }
1063
1064 private function distributeQuantityByStore($needQuantityList, $availableQuantity) : array
1065 {
1066 $result = [];
1067
1068 foreach ($needQuantityList as $quantityByStore)
1069 {
1070 if (is_array($quantityByStore))
1071 {
1072 foreach ($quantityByStore as $storeId => $quantity)
1073 {
1074 if (abs($quantity) < abs($availableQuantity))
1075 {
1076 $result[$storeId] = $quantity;
1077 $availableQuantity -= $quantity;
1078 }
1079 else
1080 {
1081 $result[$storeId] = $availableQuantity;
1082 $availableQuantity = 0;
1083 }
1084 }
1085 }
1086 }
1087
1088 return $result;
1089 }
1090}
setItemsResultAfterTryUnship(PoolQuantity $pool, array $products, array $productTryShipList)
setItemsResultAfterTryShip(PoolQuantity $pool, array $products, array $productTryShipList)