95 $pool->addItem(
$code, $item);
151 $pool->addItem(
$code, $item);
173 public static function onOrderSave(Order
$order)
177 static::resetTrustData(
$order->getSiteId());
181 if (!$r->isSuccess())
183 $result->addErrors($r->getErrors());
186 if ($r->hasWarnings())
188 $result->addWarnings($r->getWarnings());
192 Internals\OrderTable::update(
$order->getId(),
array(
'MARKED' =>
'Y'));
196 static::refreshMarkers(
$order);
210 public static function shipBasketItem(BasketItemBase $basketItem)
216 if (!$basket = $basketItem->getCollection())
218 throw new ObjectNotFoundException(
'Entity "Basket" not found');
222 if (!
$order = $basket->getOrder())
224 throw new ObjectNotFoundException(
'Entity "Order" not found');
228 $shipmentCollection =
$order->getShipmentCollection();
231 foreach ($shipmentCollection as $shipment)
233 $needShip = $shipment->needShip();
234 if ($needShip ===
null)
237 $r = static::shipShipment($shipment);
238 if (!$r->isSuccess())
240 $result->addErrors($r->getErrors());
242 elseif ($r->hasWarnings())
244 $result->addWarnings($r->getWarnings());
245 EntityMarker::addMarker(
$order, $shipment, $r);
246 if (!$shipment->isSystem())
248 $shipment->setField(
'MARKED',
'Y');
262 public static function shipShipment(Shipment $shipment)
267 if (!$shipmentItemCollection = $shipment->getShipmentItemCollection())
269 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
273 if (!$shipmentCollection = $shipment->getCollection())
275 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
279 if (!
$order = $shipmentCollection->getOrder())
281 throw new ObjectNotFoundException(
'Entity "Order" not found');
284 $pool = Internals\PoolQuantity::getInstance(
$order->getInternalId());
293 $resultList =
array();
295 $basketList = static::getBasketFromShipmentItemCollection($shipmentItemCollection);
297 $basketProviderMap = static::createProviderBasketMap($basketList,
array(
'QUANTITY',
'RESERVED'));
298 $basketProviderList = static::redistributeToProviders($basketProviderMap);
299 $storeDataList =
array();
305 $r = static::getStoreDataFromShipmentItemCollection($shipmentItemCollection);
306 if (!$r->isSuccess())
308 $result->addErrors($r->getErrors());
312 $resultStoreData = $r->getData();
313 if (!empty($resultStoreData[
'STORE_DATA_LIST']))
315 $storeDataList = $resultStoreData[
'STORE_DATA_LIST'];
321 if (!empty($basketProviderList))
323 foreach ($basketProviderList as
$provider => $providerBasketItemList)
325 if (
$provider && array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
328 foreach ($providerBasketItemList as $providerBasketItem)
331 if ($providerBasketItem[
'BASKET_ITEM']->isBundleParent())
336 $poolQuantity = static::getQuantityPoolItem(
$order->getInternalId(), $providerBasketItem[
'BASKET_ITEM']);
338 if ($poolQuantity == 0)
341 if ($providerBasketItem[
'BASKET_ITEM']->getField(
'MODULE') !=
'')
343 $shipFields = array_merge($providerBasketItem,
array(
344 'DEDUCTION' => ($poolQuantity < 0)
347 $r = static::shipProductData(
$provider, $shipFields, $storeDataList);
349 if (!$r->isSuccess())
351 $result->addErrors($r->getErrors());
353 $resultProductData = $r->getData();
358 $resultProductData[
'RESULT'] =
true;
361 $resultList[$providerBasketItem[
'BASKET_CODE']] = $resultProductData;
363 if (array_key_exists(
"RESULT", $resultProductData)
364 && $resultProductData[
'RESULT'] ===
false && $poolQuantity < 0)
376 'SITE_ID' =>
$order->getSiteId(),
377 'CURRENCY' =>
$order->getCurrency(),
380 if (
$order->getUserId() > 0)
390 $creator = Internals\ProviderCreator::create(
$context);
392 foreach ($shipmentItemCollection as $shipmentItem)
394 $basketItem = $shipmentItem->getBasketItem();
395 $providerClass = $basketItem->getProviderEntity();
397 if ($providerClass instanceof SaleProviderBase)
399 $shipmentProductData = $creator->createItemForShip($shipmentItem);
400 $creator->addProductData($shipmentProductData);
404 $r = $creator->ship();
405 if (!$r->isSuccess())
407 $result->addErrors($r->getErrors());
410 $r = $creator->setItemsResultAfterShip($r);
411 if (!$r->isSuccess())
413 $result->addErrors($r->getErrors());
419 if ($reverse ===
true)
421 static::reverseShipment($shipment, $resultList);
425 static::setShipmentItemReserved($shipment);
442 $quantity =
$fields[
'QUANTITY'];
443 $basketCode =
$fields[
'BASKET_CODE'];
446 $basketItem =
$fields[
'BASKET_ITEM'];
449 $basket = $basketItem->getCollection();
452 $order = $basket->getOrder();
455 "BASKET_ITEM" => $basketItem,
456 "PRODUCT_ID" =>
$fields[
'PRODUCT_ID'],
457 "QUANTITY" => $quantity,
458 "PRODUCT_RESERVED" =>
"N",
459 'UNDO_DEDUCTION' =>
$fields[
'DEDUCTED']?
'N' :
'Y',
463 if (
$data[
'UNDO_DEDUCTION'] ==
'N')
465 $data[
'PRODUCT_RESERVED'] =
"Y";
468 if (!empty(
$fields[
'RESERVED']))
470 $data[
'PRODUCT_RESERVED'] =
$fields[
'RESERVED'] ?
'Y' :
'N';
473 $resultProductData =
array();
478 if (!empty($storeDataList) && is_array($storeDataList) && isset($storeDataList[$basketCode]))
480 $data[
'STORE_DATA'] = $storeDataList[$basketCode];
483 if (!empty(
$data[
'STORE_DATA']))
485 $allBarcodeQuantity = 0;
486 foreach(
$data[
'STORE_DATA'] as $basketShipmentItemStore)
488 $allBarcodeQuantity += $basketShipmentItemStore[
'QUANTITY'];
491 if ($quantity > $allBarcodeQuantity)
493 $result->addWarning(
new ResultWarning(Loc::getMessage(
'SALE_PROVIDER_SHIPMENT_SHIPPED_LESS_QUANTITY',
array(
494 '#PRODUCT_NAME#' => $basketItem->getField(
'NAME')
495 )),
'SALE_PROVIDER_SHIPMENT_SHIPPED_LESS_QUANTITY'));
497 $resultProductData[
'RESULT'] =
false;
499 elseif ($quantity < $allBarcodeQuantity)
501 $result->addWarning(
new ResultWarning(Loc::getMessage(
'SALE_PROVIDER_SHIPMENT_SHIPPED_MORE_QUANTITY',
array(
502 '#PRODUCT_NAME#' => $basketItem->getField(
'NAME')
503 )),
'SALE_PROVIDER_SHIPMENT_SHIPPED_MORE_QUANTITY'));
505 $resultProductData[
'RESULT'] =
false;
511 if (!isset($resultProductData[
'RESULT'])
512 || $resultProductData[
'RESULT'] !==
false)
516 $resultProductData = $provider::DeductProduct(
$data);
518 $result->setData($resultProductData);
520 $needShip =
$fields[
'DEDUCTED'];
522 if (!empty($oldException))
524 if ($needShip ===
true)
526 $result->addWarning(
new ResultWarning($oldException->GetString(), $oldException->GetID()) );
530 if (($oldException && $needShip ===
false) || !$oldException)
532 static::addQuantityPoolItem(
$order->getInternalId(), $basketItem, ($needShip? 1 : -1) * $quantity);
545 private static function reverseShipment(Shipment $shipment,
array $shippedList)
547 $needShip = $shipment->needShip();
551 $shipmentItemCollection = $shipment->getShipmentItemCollection();
552 $basketList = static::getBasketFromShipmentItemCollection($shipmentItemCollection);
554 $bundleIndexList = static::getBundleIndexFromShipmentItemCollection($shipmentItemCollection);
556 $basketProviderMap = static::createProviderBasketMap($basketList,
array(
'QUANTITY',
'RESERVED'));
557 $basketProviderList = static::redistributeToProviders($basketProviderMap);
562 $r = static::getStoreDataFromShipmentItemCollection($shipmentItemCollection);
565 if (!empty($basketProviderList))
567 foreach ($basketProviderList as
$provider => $providerBasketItemList)
569 if (
$provider && array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
572 foreach ($providerBasketItemList as $providerBasketItem)
574 if ($providerBasketItem[
'BASKET_ITEM']->isBundleParent())
579 $basketCode = $providerBasketItem[
'BASKET_CODE'];
580 if (!isset($shippedList[$basketCode])
581 || (array_key_exists(
"RESULT", $shippedList[$basketCode]) && $shippedList[$basketCode][
'RESULT'] ===
false))
583 if ($needShip && $shipment->isShipped())
590 if ($providerBasketItem[
'BASKET_ITEM']->getField(
'MODULE') !=
'')
593 "BASKET_ITEM" => $providerBasketItem[
'BASKET_ITEM'],
594 "PRODUCT_ID" => $providerBasketItem[
'PRODUCT_ID'],
595 "QUANTITY" => $providerBasketItem[
'QUANTITY'],
596 "PRODUCT_RESERVED" =>
"Y",
597 'UNDO_DEDUCTION' => $needShip?
'Y' :
'N',
603 $data[
'STORE_DATA'] = $storeData[$providerBasketItem[
'BASKET_CODE']];
605 $barcodeReverseList =
array();
607 if (!empty($shippedList[$basketCode][
'BARCODE']) && is_array($shippedList[$basketCode][
'BARCODE']))
609 foreach ($shippedList[$basketCode][
'BARCODE'] as $barcodeValue => $barcodeShipped)
611 if ($barcodeShipped ===
true)
613 $barcodeReverseList[] = $barcodeValue;
617 foreach (
$data[
'STORE_DATA'] as $storeId => $barcodeData)
619 if (!empty($barcodeData[
'BARCODE']) && is_array($barcodeData[
'BARCODE']))
621 if (empty($barcodeReverseList))
627 foreach ($barcodeData[
'BARCODE'] as $barcodeId => $barcodeValue)
629 if (!in_array($barcodeValue, $barcodeReverseList))
631 unset(
$data[
'STORE_DATA'][$storeId][
'BARCODE'][$barcodeId]);
642 $resultProductData = $provider::DeductProduct(
$data);
646 $resultProductData[
'RESULT'] =
true;
650 $result[$providerBasketItem[
'BASKET_CODE']] = $resultProductData;
652 if (isset($resultProductData[
'RESULT'])
653 && $resultProductData[
'RESULT'] ===
true)
664 if ($correct ===
true)
666 $shipment->setFieldNoDemand(
'DEDUCTED', $needShip?
'N' :
'Y');
670 && !empty($bundleIndexList) && is_array($bundleIndexList))
673 foreach ($bundleIndexList as $bundleParentBasketCode => $bundleChildList)
675 $tryShipmentBundle =
false;
676 foreach($bundleChildList as $bundleChildBasketCode)
678 if (isset(
$result[$bundleChildBasketCode])
679 &&
$result[$bundleChildBasketCode][
'RESULT'] ===
true)
681 $tryShipmentBundle =
true;
685 $tryShipmentBundle =
false;
691 'RESULT' => $tryShipmentBundle
704 private static function setShipmentItemReserved(Shipment $shipment)
709 $needShip = $shipment->needShip();
711 if ($needShip ===
null
712 || ($needShip ===
false && !$shipment->isReserved()))
717 $order = $shipment->getParentOrder();
720 throw new ObjectNotFoundException(
'Entity "Order" not found');
725 && !$shipment->needReservation()
728 if ($needShip ===
false)
730 if (!Internals\ActionEntity::isTypeExists(
736 Internals\ActionEntity::add(
740 'METHOD' =>
'Bitrix\Sale\ShipmentCollection::updateReservedFlag',
741 'PARAMS' =>
array($shipment->getCollection())
751 $shipmentItemCollection = $shipment->getShipmentItemCollection();
754 foreach ($shipmentItemCollection as $shipmentItem)
758 $basketItem = $shipmentItem->getBasketItem();
761 $result->addError(
new ResultError(
763 'SALE_PROVIDER_BASKET_ITEM_NOT_FOUND',
765 '#BASKET_ITEM_ID#' => $shipmentItem->getBasketId(),
766 '#SHIPMENT_ID#' => $shipment->getId(),
767 '#SHIPMENT_ITEM_ID#' => $shipmentItem->getId(),
770 'PROVIDER_SET_SHIPMENT_ITEM_RESERVED_WRONG_BASKET_ITEM')
776 $providerName = $basketItem->getProvider();
777 $providerClass =
null;
779 if (class_exists($providerName))
781 $providerClass =
new $providerName();
783 if ($providerClass && ($providerClass instanceof SaleProviderBase))
788 $setReservedQuantity = 0;
789 if ($needShip ===
false)
791 if ($basketItem->isBundleParent())
795 $setReservedQuantity = $shipmentItem->getQuantity();
798 $shipmentItem->setFieldNoDemand(
'RESERVED_QUANTITY', $setReservedQuantity);
801 if ($needShip ===
false)
803 if (!Internals\ActionEntity::isTypeExists(
809 Internals\ActionEntity::add(
813 'METHOD' =>
'Bitrix\Sale\ShipmentCollection::updateReservedFlag',
814 'PARAMS' =>
array($shipment->getCollection())
829 public static function getProductAvailableQuantity(Basket $basketCollection, BasketItem $refreshItem =
null)
832 static $proxyProductAvailableQuantity =
array();
833 $resultList =
array();
836 if ((
$order = $basketCollection->getOrder()) !==
null)
841 $basketList = static::makeArrayFromBasketCollection($basketCollection, $refreshItem);
843 $basketProviderMap = static::createProviderBasketMap($basketList);
844 $basketProviderList = static::redistributeToProviders($basketProviderMap);
847 $productsList =
array();
848 $providerList =
array();
849 $basketCodeIndex =
array();
850 if (!empty($basketProviderList))
852 foreach ($basketProviderList as
$provider => $providerBasketItemList)
854 if (array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
856 foreach ($providerBasketItemList as $providerBasketItemData)
859 $proxyProductKey = $providerBasketItemData[
'PRODUCT_ID'].
"|".
$userId;
860 if (!empty($proxyProductAvailableQuantity[$proxyProductKey]) && is_array($proxyProductAvailableQuantity[$proxyProductKey]))
862 $resultProductData = $proxyProductAvailableQuantity[$proxyProductKey];
866 $resultProductData = $resultProductData = $provider::getProductAvailableQuantity($providerBasketItemData[
'PRODUCT_ID'],
$userId);
867 $proxyProductAvailableQuantity[$proxyProductKey] = $resultProductData;
871 $basketCode = $providerBasketItemData[
'BASKET_ITEM']->getBasketCode();
872 $resultList[$basketCode] = $resultProductData;
882 'USER_ID' =>
$order->getUserId(),
883 'SITE_ID' =>
$order->getSiteId(),
884 'CURRENCY' =>
$order->getCurrency(),
891 'USER_ID' =>
$USER->getId(),
893 'CURRENCY' => Currency\CurrencyManager::getBaseCurrency(),
899 if (!$providerClass instanceof SaleProviderBase)
905 foreach ($providerBasketItemList as $providerBasketItemData)
907 $basketItem = $providerBasketItemData[
'BASKET_ITEM'];
910 $basketCode = $basketItem->getBasketCode();
911 $basketCodeIndex[
$productId][] = $basketItem->getBasketCode();
913 $providerList[
$provider] = $providerClass;
915 if (empty($productsList[
$provider][$productId]))
920 $productsList[
$provider][
$productId][
'QUANTITY_LIST'][$basketCode] = $basketItem->getQuantity();
921 $resultList[$basketCode] = 0;
926 foreach ($providerBasketItemList as $providerBasketItemData)
928 $resultProductData = \CSaleBasket::ExecuteCallbackFunction(
929 $providerBasketItemData[
'CALLBACK_FUNC'],
930 $providerBasketItemData[
'MODULE'],
931 $providerBasketItemData[
'PRODUCT_ID']
934 $basketCode = $providerBasketItemData[
'BASKET_ITEM']->getBasketCode();
935 $resultList[$basketCode] = $resultProductData;
941 if (!empty($productsList))
943 foreach ($productsList as $providerName => $products)
946 $providerClass = $providerList[$providerName];
948 $r = $providerClass->getAvailableQuantity($products);
951 $resultData = $r->getData();
952 if (!empty($resultData[
'AVAILABLE_QUANTITY_LIST']))
955 foreach ($resultData[
'AVAILABLE_QUANTITY_LIST'] as $productId => $availableQuantity)
957 if (!empty($basketCodeIndex[$productId]))
959 foreach ($basketCodeIndex[$productId] as $basketCode)
961 $resultList[$basketCode] = $availableQuantity;
985 $resultList =
array();
1001 $basket = $basketCollection->
getBasket();
1002 $siteId = $basket->getSiteId();
1012 $currency = Currency\CurrencyManager::getBaseCurrency();
1021 $basketList = static::makeArrayFromBasketCollection($basketCollection, $refreshItem);
1024 $basketProviderMap = static::createProviderBasketMap($basketList,
array(
'QUANTITY',
'RENEWAL',
'SITE_ID',
'USER_ID'));
1025 foreach ($basketProviderMap as $basketProviderMapItem)
1027 $basketProviderList = static::redistributeToProviders([
1028 $basketProviderMapItem,
1031 if (!empty($basketProviderList))
1037 foreach ($basketProviderList as $providerClassName => $productValueList)
1040 if ($r->isSuccess())
1042 $resultData = $r->getData();
1043 if (!empty($resultData[
'PRODUCT_DATA_LIST']))
1045 $resultList = $resultData[
'PRODUCT_DATA_LIST'] + $resultList;
1069 $resultList =
array();
1071 $needPrice = in_array(
'PRICE',
$select);
1072 $needBasePrice = in_array(
'BASE_PRICE',
$select);
1073 $needCoupons = in_array(
'COUPONS',
$select);
1077 'CURRENCY' =>
$context[
'CURRENCY'],
1078 'CHECK_QUANTITY' => (in_array(
'QUANTITY',
$select) ?
'Y' :
'N'),
1079 'AVAILABLE_QUANTITY' => (in_array(
'AVAILABLE_QUANTITY',
$select) ?
'Y' :
'N'),
1080 'CHECK_PRICE' => ($needPrice ?
'Y' :
'N'),
1081 'CHECK_COUPONS' => ($needCoupons ?
'Y' :
'N'),
1082 'RENEWAL' => (in_array(
'RENEWAL',
$select) ?
'Y' :
'N')
1086 $data[
'CHECK_DISCOUNT'] =
'N';
1088 $useOrderProduct =
false;
1090 $useOrderProduct =
true;
1093 $useOrderProduct =
false;
1095 $data[
'USE_ORDER_PRODUCT'] = $useOrderProduct;
1097 unset($needCoupons, $needPrice);
1100 if ($providerClassName)
1102 if (array_key_exists(
"IBXSaleProductProvider", class_implements($providerClassName)))
1104 $resultProductList = static::getProductProviderData($products, $providerClassName,
$data,
$select);
1105 if (in_array(
'RETURN_BASKET_ID',
$options))
1107 $basketList =
array();
1111 $basketList[] = $basketItem;
1114 $resultProductList = static::createItemsAfterGetProductData($basketList, $resultProductList,
$select);
1117 elseif (class_exists($providerClassName))
1119 $basketList =
array();
1125 $r = Internals\Catalog\Provider::getProductData($basketList,
$context);
1126 if ($r->isSuccess())
1128 $resultProductData = $r->getData();
1129 if (!empty($resultProductData[
'PRODUCT_DATA_LIST']))
1131 $itemsList = $resultProductData[
'PRODUCT_DATA_LIST'];
1132 $resultItemsList =
array();
1133 $resultProductList =
array();
1135 foreach ($itemsList as $providerName => $products)
1137 $resultItemsList = static::createItemsAfterGetProductData($basketList, $products,
$select);
1140 $resultProductList = $resultProductList + $resultItemsList;
1146 if (!empty($resultProductList))
1148 if (!empty($resultList) && is_array($resultList))
1150 $resultList = $resultList + $resultProductList;
1154 $resultList = $resultProductList;
1164 $callbackFunction =
null;
1170 $quantityList =
array();
1182 foreach($quantityList as $basketCode => $quantity)
1184 if (!empty($callbackFunction))
1186 $resultProductData = \CSaleBasket::executeCallbackFunction(
1195 $resultProductData =
array(
1196 'QUANTITY' => $quantity,
1197 'AVAILABLE_QUANTITY' => $quantity,
1201 $itemCode = $productId;
1202 if (in_array(
'RETURN_BASKET_ID',
$options))
1204 $itemCode = $basketCode;
1207 if (empty($resultList[$itemCode]))
1209 $resultList[$itemCode] = $resultProductData;
1212 if (!empty($resultProductData))
1214 $resultList[$itemCode][
'PRICE_LIST'][$basketCode] =
array(
1215 'QUANTITY' => $resultProductData[
'QUANTITY'],
1216 'AVAILABLE_QUANTITY' => $resultProductData[
'AVAILABLE_QUANTITY'],
1217 "ITEM_CODE" => $productId,
1218 "BASKET_CODE" => $basketCode,
1223 if (isset($resultProductData[$fieldName]))
1225 $resultList[$itemCode][
'PRICE_LIST'][$basketCode][$fieldName] = $resultProductData[$fieldName];
1235 if (!empty($resultList))
1239 'PRODUCT_DATA_LIST' => $resultList
1255 private static function createItemsAfterGetProductData($basketList,
array $productDataList,
array $select =
array())
1257 $resultList =
array();
1258 $basketIndexList =
array();
1259 $basketMap =
array();
1261 if (!is_array($basketList) && !($basketList instanceof
BasketBase))
1267 foreach ($basketList as $basketItem)
1269 $basketCode = $basketItem->getBasketCode();
1270 $productId = $basketItem->getProductId();
1272 $basketIndexList[$productId][] = $basketCode;
1273 $basketMap[$basketCode] = $basketItem;
1276 if (empty($productDataList))
1281 foreach ($productDataList as $productId =>
$productData)
1283 if (empty($basketIndexList[$productId]))
1289 foreach ($basketIndexList[$productId] as $basketCode)
1295 if (array_key_exists(
'AVAILABLE_QUANTITY', $priceData)
1296 && !array_key_exists(
'QUANTITY', $priceData))
1298 $priceData[
'QUANTITY'] = $priceData[
'AVAILABLE_QUANTITY'];
1302 $basketItem = $basketMap[$basketCode];
1304 if (in_array(
'PRICE',
$select) || $basketItem->getId() == 0)
1310 if (isset($priceData[
'QUANTITY']))
1315 if (isset($priceData[
'AVAILABLE_QUANTITY']))
1317 $productData[
'AVAILABLE_QUANTITY'] = $priceData[
'AVAILABLE_QUANTITY'];
1351 $productSelect = array_fill_keys(
$select,
true);
1354 $currentUseOrderProduct =
$data[
'USE_ORDER_PRODUCT'];
1357 $currentUseOrderProduct =
false;
1364 $fields[
'CHECK_COUPONS'] =
'Y';
1368 $fields[
'CHECK_COUPONS'] =
'N';
1373 $fields[
'CHECK_DISCOUNT'] =
'N';
1374 $fields[
'CHECK_COUPONS'] =
'N';
1381 unset($productSelect[
'QUANTITY'], $productSelect[
'AVAILABLE_QUANTITY']);
1383 $fields[
'CHECK_QUANTITY'] =
'N';
1384 $fields[
'AVAILABLE_QUANTITY'] =
'N';
1387 $quantityList =
array();
1406 if (intval($basketId) == 0)
1412 $basketId = $basketItem->getId();
1416 if (intval($basketId) > 0)
1418 $fields[
'BASKET_ID'] = $basketId;
1421 $hasTrustData =
false;
1424 $resultProductData =
array();
1426 if (static::isReadTrustData() ===
true
1429 $hasTrustData =
true;
1432 foreach (static::getProductDataRequiredFields() as $requiredField)
1434 if (!array_key_exists($requiredField, $resultProductData))
1436 $hasTrustData =
false;
1442 if ($hasTrustData && isset($productSelect[
'PRICE']))
1444 foreach (static::getProductDataRequiredPriceFields() as $requiredField)
1446 if (!array_key_exists($requiredField, $resultProductData))
1448 $hasTrustData =
false;
1457 $resultProviderDataList =
array();
1461 foreach($quantityList as $basketCode => $quantity)
1463 if (!empty($resultProviderDataList[$quantity]))
1465 $resultProviderDataList[$quantity][
'BASKET_CODE'][] = $basketCode;
1470 $requestFields[
'QUANTITY'] = $quantity;
1472 $resultProviderDataList[$quantity] =
array(
1473 'BASKET_CODE' =>
array($basketCode),
1474 'DATA' => ($currentUseOrderProduct ? $provider::OrderProduct(
1476 ) : $provider::GetProductData($requestFields))
1485 if (!isset($productSelect[
'AVAILABLE_QUANTITY']) && array_key_exists(
"AVAILABLE_QUANTITY", $resultProductData))
1487 unset($resultProductData[
'AVAILABLE_QUANTITY']);
1490 $productQuantity = floatval($resultProductData[
'QUANTITY']);
1492 $resultProviderDataList[$productQuantity] =
array(
1494 'DATA' => $resultProductData
1501 foreach ($resultProviderDataList as $quantity => $providerData)
1503 if (empty(
$result[$itemCode]))
1505 $result[$itemCode] = $providerData[
'DATA'];
1508 $basketCodeList = $providerData[
'BASKET_CODE'];
1510 foreach ($basketCodeList as $basketCode)
1513 "ITEM_CODE" => $itemCode,
1514 "BASKET_CODE" => $basketCode,
1517 if (isset($providerData[
'DATA'][
'QUANTITY']) && $providerData[
'DATA'][
'QUANTITY'] > 0)
1519 $result[$itemCode][
'PRICE_LIST'][$basketCode][
'QUANTITY'] = $providerData[
'DATA'][
'QUANTITY'];
1522 if (isset($providerData[
'DATA'][
'AVAILABLE_QUANTITY']))
1524 $result[$itemCode][
'PRICE_LIST'][$basketCode][
'AVAILABLE_QUANTITY'] = $providerData[
'DATA'][
'AVAILABLE_QUANTITY'];
1530 if (isset($providerData[
'DATA'][$fieldName]))
1532 foreach ($basketCodeList as $basketCode)
1534 $result[$itemCode][
'PRICE_LIST'][$basketCode][$fieldName] = $providerData[
'DATA'][$fieldName];
1547 if (!empty($bundleChildDataList) && is_array($bundleChildDataList))
1551 foreach ($bundleChildDataList[
"ITEMS"] as &$itemData)
1553 $itemData[
'QUANTITY'] = $itemData[
'QUANTITY'] * $quantity;
1556 $result[$itemCode][
"BUNDLE_ITEMS"] = $bundleChildDataList[
"ITEMS"];
1573 $needPrice = in_array(
'PRICE',
$select);
1574 $needBasePrice = in_array(
'BASE_PRICE',
$select);
1575 $needCoupons = in_array(
'COUPONS',
$select);
1588 if (array_key_exists(
'SITE_ID',
$context))
1593 if (array_key_exists(
'CURRENCY',
$context))
1602 'CHECK_QUANTITY' => (in_array(
'QUANTITY',
$select) ?
'Y' :
'N'),
1603 'AVAILABLE_QUANTITY' => (in_array(
'AVAILABLE_QUANTITY',
$select) ?
'Y' :
'N'),
1604 'CHECK_PRICE' => ($needPrice ?
'Y' :
'N'),
1605 'CHECK_COUPONS' => ($needCoupons ?
'Y' :
'N'),
1606 'RENEWAL' => (in_array(
'RENEWAL',
$select) ?
'Y' :
'N')
1610 $data[
'CHECK_DISCOUNT'] =
'N';
1612 $useOrderProduct =
false;
1614 $useOrderProduct =
true;
1617 $useOrderProduct =
false;
1619 unset($needCoupons, $needPrice);
1621 foreach ($basketProviderList as
$provider => $providerBasketItemList)
1623 if (
$provider && array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
1625 foreach ($providerBasketItemList as $providerBasketItem)
1627 $currentUseOrderProduct = $useOrderProduct;
1628 if (!isset($providerBasketItem[
'BASKET_ID']) || (
int)$providerBasketItem[
'BASKET_ID'] <= 0)
1629 $currentUseOrderProduct =
false;
1631 $providerFields =
$data;
1633 if ($providerBasketItem[
'BASKET_ITEM']->isBundleChild())
1635 $providerFields[
'CHECK_DISCOUNT'] =
'N';
1638 if ($providerBasketItem[
'BASKET_ITEM']->getField(
"CAN_BUY") ==
"N"
1639 || $providerBasketItem[
'BASKET_ITEM']->getField(
"DELAY") ==
"Y"
1640 || $providerBasketItem[
'BASKET_ITEM']->getField(
"SUBSCRIBE") ==
"Y"
1643 $providerFields[
'CHECK_COUPONS'] =
'N';
1647 $providerFields[
'CHECK_COUPONS'] =
'Y';
1650 $providerFields[
'PRODUCT_ID'] = $providerBasketItem[
'PRODUCT_ID'];
1651 $providerFields[
'QUANTITY'] = $providerBasketItem[
'QUANTITY'];
1653 if (intval($providerBasketItem[
'BASKET_ID']) > 0)
1655 $providerFields[
'BASKET_ID'] = $providerBasketItem[
'BASKET_ID'];
1658 $hasTrustData =
false;
1660 $trustData = static::getTrustData(
$siteId, $providerBasketItem[
'MODULE'], $providerBasketItem[
'PRODUCT_ID']);
1662 if (static::isReadTrustData() ===
true
1665 $hasTrustData =
true;
1668 foreach (static::getProductDataRequiredFields() as $requiredField)
1670 if (!array_key_exists($requiredField, $resultProductData))
1672 $hasTrustData =
false;
1678 if ($hasTrustData && in_array(
'PRICE',
$select))
1680 foreach (static::getProductDataRequiredPriceFields() as $requiredField)
1682 if (!array_key_exists($requiredField, $resultProductData))
1684 $hasTrustData =
false;
1694 $resultProductData = ($currentUseOrderProduct ? $provider::OrderProduct($providerFields) :
$provider::GetProductData($providerFields));
1698 if (!in_array(
'AVAILABLE_QUANTITY',
$select) && array_key_exists(
"AVAILABLE_QUANTITY", $resultProductData))
1700 unset($resultProductData[
'AVAILABLE_QUANTITY']);
1704 $basketCode = $providerBasketItem[
'BASKET_ITEM']->getBasketCode();
1705 $result[$basketCode] = $resultProductData;
1707 if ($providerBasketItem[
'BASKET_ITEM']->isBundleParent())
1712 $bundleChildDataList = static::getSetItems($providerBasketItem[
'BASKET_ITEM']);
1713 if (!empty($bundleChildDataList) && is_array($bundleChildDataList))
1715 $bundleChildList = reset($bundleChildDataList);
1717 foreach ($bundleChildList[
"ITEMS"] as &$itemData)
1719 $itemData[
'QUANTITY'] = $itemData[
'QUANTITY'] * $providerBasketItem[
'BASKET_ITEM']->getQuantity();
1722 $result[$basketCode][
"BUNDLE_ITEMS"] = $bundleChildList[
"ITEMS"];
1730 foreach ($providerBasketItemList as $providerBasketItem)
1732 $resultProductData = \CSaleBasket::executeCallbackFunction(
1733 $providerBasketItem[
'CALLBACK_FUNC'],
1734 $providerBasketItem[
'MODULE'],
1735 $providerBasketItem[
'PRODUCT_ID'],
1736 $providerBasketItem[
'QUANTITY']
1739 $basketCode = $providerBasketItem[
'BASKET_ITEM']->getBasketCode();
1740 $result[$basketCode] = $resultProductData;
1756 public static function tryShipment(Shipment $shipment)
1759 $needShip = $shipment->needShip();
1760 if ($needShip ===
null)
1763 $resultList =
array();
1764 $storeData =
array();
1767 $shipmentItemCollection = $shipment->getShipmentItemCollection();
1768 if (!$shipmentItemCollection)
1770 throw new ObjectNotFoundException(
'Entity "ShipmentItemCollection" not found');
1774 $shipment = $shipmentItemCollection->getShipment();
1777 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
1781 $shipmentCollection = $shipment->getCollection();
1782 if (!$shipmentCollection)
1784 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
1787 $r = static::tryShipmentItemList($shipmentItemCollection);
1789 $basketList = static::getBasketFromShipmentItemCollection($shipmentItemCollection);
1791 $bundleIndexList = static::getBundleIndexFromShipmentItemCollection($shipmentItemCollection);
1793 $basketCountList = static::getBasketCountFromShipmentItemCollection($shipmentItemCollection);
1795 $basketProviderMap = static::createProviderBasketMap($basketList,
array(
'RESERVED',
'SITE_ID'));
1796 $basketProviderList = static::redistributeToProviders($basketProviderMap);
1801 $r = static::getStoreDataFromShipmentItemCollection($shipmentItemCollection);
1802 if ($r->isSuccess())
1804 $resultStoreData = $r->getData();
1805 if (!empty($resultStoreData[
'STORE_DATA_LIST']))
1807 $storeDataList = $resultStoreData[
'STORE_DATA_LIST'];
1812 $result->addErrors($r->getErrors());
1817 if (!empty($basketProviderList))
1819 foreach ($basketProviderList as
$provider => $providerBasketItemList)
1821 if (
$provider && array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
1823 foreach ($providerBasketItemList as $providerBasketItem)
1825 if ($providerBasketItem[
'BASKET_ITEM']->isBundleParent())
1830 $resultProduct =
new Result();
1834 $basketStoreData =
array();
1836 $basketCode = $providerBasketItem[
'BASKET_CODE'];
1839 if (!$basketItem = $providerBasketItem[
'BASKET_ITEM'])
1841 throw new ObjectNotFoundException(
'Entity "BasketItem" not found');
1846 $quantity = $basketCountList[$basketCode];
1848 if (!empty($storeDataList) && is_array($storeDataList)
1849 && isset($storeDataList[$basketCode]))
1851 $basketStoreData = $storeDataList[$basketCode];
1854 if (!empty($basketStoreData))
1856 $allBarcodeQuantity = 0;
1857 foreach($basketStoreData as $basketShipmentItemStore)
1859 $allBarcodeQuantity += $basketShipmentItemStore[
'QUANTITY'];
1862 if ($quantity > $allBarcodeQuantity)
1864 $resultProduct->addError(
new ResultError(Loc::getMessage(
'SALE_PROVIDER_SHIPMENT_SHIPPED_LESS_QUANTITY',
array(
1865 '#PRODUCT_NAME#' => $basketItem->getField(
'NAME')
1866 )),
'SALE_PROVIDER_SHIPMENT_SHIPPED_LESS_QUANTITY'));
1868 elseif ($quantity < $allBarcodeQuantity)
1870 $resultProduct->addError(
new ResultError(Loc::getMessage(
'SALE_PROVIDER_SHIPMENT_SHIPPED_MORE_QUANTITY',
array(
1871 '#PRODUCT_NAME#' => $basketItem->getField(
'NAME')
1872 )),
'SALE_PROVIDER_SHIPMENT_SHIPPED_MORE_QUANTITY'));
1878 if ($resultProduct->isSuccess())
1881 if ($needShip ===
true)
1883 if (method_exists(
$provider,
'tryShipmentProduct'))
1886 $resultProduct = $provider::tryShipmentProduct($basketItem, $providerBasketItem[
'RESERVED'], $basketStoreData, $quantity);
1891 if (method_exists(
$provider,
'tryUnshipmentProduct'))
1894 $resultProduct = $provider::tryUnshipmentProduct($providerBasketItem[
'PRODUCT_ID']);
1899 $resultList[$basketCode] = $resultProduct;
1907 if (!$shipmentCollection = $shipment->getCollection())
1909 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
1913 if (!
$order = $shipmentCollection->getOrder())
1915 throw new ObjectNotFoundException(
'Entity "Order" not found');
1918 $pool = Internals\PoolQuantity::getInstance(
$order->getInternalId());
1921 'SITE_ID' =>
$order->getSiteId(),
1922 'CURRENCY' =>
$order->getCurrency(),
1925 if (
$order->getUserId() > 0)
1935 $creator = Internals\ProviderCreator::create(
$context);
1937 $tryShipProductList =
array();
1939 foreach ($shipmentItemCollection as $shipmentItem)
1941 $basketItem = $shipmentItem->getBasketItem();
1942 $providerClass = $basketItem->getProviderEntity();
1944 if ($providerClass instanceof SaleProviderBase)
1946 $shipmentProductData = $creator->createItemForShip($shipmentItem);
1947 $creator->addProductData($shipmentProductData);
1951 $r = $creator->tryShip();
1952 if ($r->isSuccess())
1954 if ($r->hasWarnings())
1956 $result->addWarnings($r->getWarnings());
1960 $data = $r->getData();
1961 if (array_key_exists(
'TRY_SHIP_PRODUCTS_LIST',
$data))
1963 $tryShipProductList =
$data[
'TRY_SHIP_PRODUCTS_LIST'] + $tryShipProductList;
1965 $creator->setItemsResultAfterTryShip($pool, $tryShipProductList);
1972 $result->addWarnings($r->getErrors());
1978 if (!empty($resultList)
1979 && !empty($bundleIndexList) && is_array($bundleIndexList))
1982 foreach ($bundleIndexList as $bundleParentBasketCode => $bundleChildList)
1985 foreach($bundleChildList as $bundleChildBasketCode)
1987 if (!isset($resultList[$bundleChildBasketCode]))
1989 if (!isset($resultList[$bundleParentBasketCode]))
1991 $resultList[$bundleParentBasketCode] =
new Result();
1994 $resultList[$bundleParentBasketCode]->addError(
new ResultError(
'Bundle child item not found',
'SALE_PROVIDER_SHIPMENT_SHIPPED_BUNDLE_CHILD_ITEM_NOT_FOUND'));
2002 if (!empty($resultList))
2005 if (!$shipmentCollection = $shipment->getCollection())
2007 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
2011 if (!
$order = $shipmentCollection->getOrder())
2013 throw new ObjectNotFoundException(
'Entity "Order" not found');
2019 foreach ($shipmentItemCollection as $shipmentItem)
2022 if(!$basketItem = $shipmentItem->getBasketItem())
2024 throw new ObjectNotFoundException(
'Entity "BasketItem" not found');
2027 if (isset($resultList[$basketItem->getBasketCode()]) && !$resultList[$basketItem->getBasketCode()]->isSuccess())
2037 foreach ($shipmentItemCollection as $shipmentItem)
2040 if(!$basketItem = $shipmentItem->getBasketItem())
2042 throw new ObjectNotFoundException(
'Entity "BasketItem" not found');
2045 if (isset($resultList[$basketItem->getBasketCode()]) && $resultList[$basketItem->getBasketCode()]->isSuccess())
2047 static::addQuantityPoolItem(
$order->getInternalId(), $basketItem, ($needShip? -1 : 1) * $shipmentItem->getQuantity());
2050 $shipmentItem->setFieldNoDemand(
"RESERVED_QUANTITY", 0);
2056 $result->setData($resultList);
2068 public static function tryShipmentItemList($shipmentItemList)
2072 $resultList =
array();
2073 $bundleIndexList = static::getBundleIndexFromShipmentItemCollection($shipmentItemList);
2078 $r = static::getStoreDataFromShipmentItemCollection($shipmentItemList);
2079 if ($r->isSuccess())
2081 $resultStoreData = $r->getData();
2082 if (!empty($resultStoreData[
'STORE_DATA_LIST']))
2084 $storeDataList = $resultStoreData[
'STORE_DATA_LIST'];
2089 $result->addErrors($r->getErrors());
2094 $shipmentItemParentsList =
array();
2096 $tryShipProductList =
array();
2099 foreach ($shipmentItemList as $shipmentItem)
2101 $itemIndex = $shipmentItem->getInternalIndex();
2102 $basketItem = $shipmentItem->getBasketItem();
2103 $providerName = $basketItem->getProviderName();
2106 $shipmentItemCollection = $shipmentItem->getCollection();
2107 if (!$shipmentItemCollection)
2109 throw new ObjectNotFoundException(
'Entity "ShipmentItemCollection" not found');
2113 $shipment = $shipmentItemCollection->getShipment();
2116 throw new ObjectNotFoundException(
'Entity "Shipment" not found');
2119 $shipmentItemParentsList[$itemIndex] =
array(
2120 'BASKET_ITEM' => $basketItem,
2121 'SHIPMENT' => $shipment,
2122 'SHIPMENT_ITEM_COLLECTION' => $shipmentItemCollection,
2125 $needShip = $shipment->needShip();
2126 if ($needShip ===
null)
2130 if ($providerName && array_key_exists(
"IBXSaleProductProvider", class_implements($providerName)))
2132 $basketItem = $shipmentItem->getBasketItem();
2135 throw new ObjectNotFoundException(
'Entity "BasketItem" not found');
2138 if ($basketItem->isBundleParent())
2143 $basketCode = $basketItem->getBasketCode();
2144 $quantity = $shipmentItem->getQuantity();
2145 $basketStoreData =
array();
2147 $resultProduct =
new Result();
2151 if (!empty($storeDataList) && is_array($storeDataList)
2152 && isset($storeDataList[$basketCode]))
2154 $basketStoreData = $storeDataList[$basketCode];
2157 if (!empty($basketStoreData))
2159 $allBarcodeQuantity = 0;
2160 foreach($basketStoreData as $basketShipmentItemStore)
2162 $allBarcodeQuantity += $basketShipmentItemStore[
'QUANTITY'];
2165 if ($quantity > $allBarcodeQuantity)
2167 $resultProduct->addError(
new ResultError(Loc::getMessage(
'SALE_PROVIDER_SHIPMENT_SHIPPED_LESS_QUANTITY',
array(
2168 '#PRODUCT_NAME#' => $basketItem->getField(
'NAME')
2169 )),
'SALE_PROVIDER_SHIPMENT_SHIPPED_LESS_QUANTITY'));
2171 elseif ($quantity < $allBarcodeQuantity)
2173 $resultProduct->addError(
new ResultError(Loc::getMessage(
'SALE_PROVIDER_SHIPMENT_SHIPPED_MORE_QUANTITY',
array(
2174 '#PRODUCT_NAME#' => $basketItem->getField(
'NAME')
2175 )),
'SALE_PROVIDER_SHIPMENT_SHIPPED_MORE_QUANTITY'));
2181 if ($resultProduct->isSuccess())
2184 if ($needShip ===
true)
2186 if (method_exists($providerName,
'tryShipmentProduct'))
2189 $resultProduct = $providerName::tryShipmentProduct($basketItem, $basketItem->getField(
'RESERVED'), $basketStoreData, $quantity);
2194 if (method_exists($providerName,
'tryUnshipmentProduct'))
2197 $resultProduct = $providerName::tryUnshipmentProduct($basketItem->getProductId());
2202 $resultList[$basketCode] = $resultProduct;
2205 elseif ($providerName && class_exists($providerName))
2208 $shipmentCollection = $shipment->getCollection();
2209 if (!$shipmentCollection)
2211 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
2215 $order = $shipmentCollection->getOrder();
2218 throw new ObjectNotFoundException(
'Entity "Order" not found');
2221 $shipmentItemParentsList[$itemIndex][
'SHIPMENT_COLLECTION'] = $shipmentCollection;
2222 $shipmentItemParentsList[$itemIndex][
'ORDER'] =
$order;
2224 $pool = Internals\PoolQuantity::getInstance(
$order->getInternalId());
2227 'SITE_ID' =>
$order->getSiteId(),
2228 'CURRENCY' =>
$order->getCurrency(),
2231 if (
$order->getUserId() > 0)
2241 $creator = Internals\ProviderCreator::create(
$context);
2243 $shipmentProductData = $creator->createItemForShip($shipmentItem);
2244 $creator->addProductData($shipmentProductData);
2246 $r = $creator->tryShip();
2247 if ($r->isSuccess())
2249 if ($r->hasWarnings())
2251 $result->addWarnings($r->getWarnings());
2255 $data = $r->getData();
2256 if (array_key_exists(
'TRY_SHIP_PRODUCTS_LIST',
$data))
2258 $tryShipProductList =
$data[
'TRY_SHIP_PRODUCTS_LIST'] + $tryShipProductList;
2259 $creator->setItemsResultAfterTryShip($pool, $tryShipProductList);
2265 $result->addWarnings($r->getErrors());
2270 if (!empty($resultList)
2271 && !empty($bundleIndexList) && is_array($bundleIndexList))
2274 foreach ($bundleIndexList as $bundleParentBasketCode => $bundleChildList)
2276 foreach($bundleChildList as $bundleChildBasketCode)
2278 if (!isset($resultList[$bundleChildBasketCode]))
2280 if (!isset($resultList[$bundleParentBasketCode]))
2282 $resultList[$bundleParentBasketCode] =
new Result();
2285 $resultList[$bundleParentBasketCode]->addError(
new ResultError(
'Bundle child item not found',
'SALE_PROVIDER_SHIPMENT_SHIPPED_BUNDLE_CHILD_ITEM_NOT_FOUND'));
2293 if (!empty($resultList))
2299 foreach ($shipmentItemList as $shipmentItem)
2301 $itemIndex = $shipmentItem->getInternalIndex();
2304 $basketItem = $shipmentItemParentsList[$itemIndex][
'BASKET_ITEM'];
2306 if (isset($resultList[$basketItem->getBasketCode()]) && !$resultList[$basketItem->getBasketCode()]->isSuccess())
2316 foreach ($shipmentItemList as $shipmentItem)
2318 $itemIndex = $shipmentItem->getInternalIndex();
2321 $basketItem = $shipmentItemParentsList[$itemIndex][
'BASKET_ITEM'];
2325 if (isset($resultList[$basketItem->getBasketCode()]) && $resultList[$basketItem->getBasketCode()]->isSuccess())
2328 $shipment = $shipmentItemParentsList[$itemIndex][
'SHIPMENT'];
2331 $order = $shipmentItemParentsList[$itemIndex][
'ORDER'];
2336 $shipmentCollection = $shipment->getCollection();
2337 if (!$shipmentCollection)
2339 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
2343 $order = $shipmentCollection->getOrder();
2346 throw new ObjectNotFoundException(
'Entity "Order" not found');
2349 $shipmentItemParentsList[$itemIndex][
'SHIPMENT_COLLECTION'] = $shipmentCollection;
2350 $shipmentItemParentsList[$itemIndex][
'ORDER'] =
$order;
2353 $needShip = $shipment->needShip();
2355 static::addQuantityPoolItem(
$order->getInternalId(), $basketItem, ($needShip? -1 : 1) * $shipmentItem->getQuantity());
2359 $shipmentItem->setFieldNoDemand(
"RESERVED_QUANTITY", 0);
2364 $poolItems = Internals\ItemsPool::get(
$order->getInternalId(), $productId);
2365 if (!empty($poolItems))
2368 foreach ($poolItems as $poolItem)
2370 if ($poolItem->getInternalIndex() == $shipmentItem->getInternalIndex())
2380 Internals\ItemsPool::add(
$order->getInternalId(), $productId, $shipmentItem);
2387 $result->setData($resultList);
2399 protected static function getBundleIndexFromShipmentItemCollection($shipmentItemList)
2401 $bundleIndexList =
array();
2403 foreach ($shipmentItemList as $shipmentItem)
2406 if (!$basketItem = $shipmentItem->getBasketItem())
2412 if ($basketItem->isBundleChild())
2415 $parentBasketItem = $basketItem->getParentBasketItem();
2416 $parentBasketCode = $parentBasketItem->getBasketCode();
2418 if (!array_key_exists($parentBasketCode, $bundleIndexList))
2420 $bundleIndexList[$parentBasketCode] =
array();
2423 $bundleIndexList[$parentBasketCode][] = $basketItem->getBasketCode();
2427 return $bundleIndexList;
2436 protected static function getBasketFromShipmentItemCollection($shipmentItemList)
2439 $basketList =
array();
2441 foreach ($shipmentItemList as $shipmentItem)
2445 if (!$basketItem = $shipmentItem->getBasketItem())
2451 $shipmentItemCollection = $shipmentItem->getCollection();
2452 if (!$shipmentItemCollection)
2454 throw new ObjectNotFoundException(
'Entity "ShipmentItemCollection" not found');
2458 $shipment = $shipmentItemCollection->getShipment();
2462 throw new ObjectNotFoundException(
'Entity "Shipment" not found');
2465 $needShip = $shipment->needShip();
2466 if ($needShip ===
null)
2471 $reserved = ((($shipmentItem->getQuantity() - $shipmentItem->getReservedQuantity()) == 0)
2472 || ($shipment->getField(
'RESERVED') ==
"Y"));
2474 if ($basketItem->isBundleParent()
2475 || (!$basketItem->isBundleParent() && !$basketItem->isBundleChild()))
2478 $basketList[$basketItem->getBasketCode()] =
array(
2479 'BASKET_ITEM' => $basketItem,
2480 'RESERVED' => ($reserved ?
"Y" :
"N"),
2481 'NEED_SHIP' => $needShip,
2482 'SHIPMENT_ITEM' => $shipmentItem
2486 if($basketItem->isBundleParent())
2489 foreach ($shipmentItemCollection as $bundleShipmentItem)
2492 $bundleBasketItem = $bundleShipmentItem->getBasketItem();
2494 if($bundleBasketItem->isBundleChild())
2496 $bundleParentBasketItem = $bundleBasketItem->getParentBasketItem();
2497 if ($bundleParentBasketItem->getBasketCode() == $basketItem->getBasketCode())
2500 $basketList[$bundleBasketItem->getBasketCode()] =
array(
2501 'BASKET_ITEM' => $bundleBasketItem,
2502 'RESERVED' => ($reserved ?
"Y" :
"N"),
2503 'NEED_SHIP' => $needShip,
2504 'SHIPMENT_ITEM' => $shipmentItem
2523 protected static function getBasketCountFromShipmentItemCollection($shipmentItemList)
2526 $basketCountList =
array();
2528 foreach ($shipmentItemList as $shipmentItem)
2532 if (!$basketItem = $shipmentItem->getBasketItem())
2537 if ($basketItem->isBundleParent()
2538 || (!$basketItem->isBundleParent() && !$basketItem->isBundleChild()))
2540 $basketCountList[$basketItem->getBasketCode()] = floatval($shipmentItem->getQuantity());
2544 if($basketItem->isBundleParent())
2547 foreach ($shipmentItemList as $bundleShipmentItem)
2550 $bundleBasketItem = $bundleShipmentItem->getBasketItem();
2552 if($bundleBasketItem->isBundleChild())
2554 $bundleParentBasketItem = $bundleBasketItem->getParentBasketItem();
2555 if ($bundleParentBasketItem->getBasketCode() == $basketItem->getBasketCode())
2557 $basketCountList[$bundleBasketItem->getBasketCode()] = floatval($bundleShipmentItem->getQuantity());
2565 return $basketCountList;
2576 $list = Internals\Catalog\Provider::createMapShipmentItemCollectionStoreData($shipmentItemList);
2580 'STORE_DATA_LIST' => $list
2594 $basketList =
array();
2596 foreach ($basketCollection as $basketItem)
2598 if ($refreshItem !==
null)
2601 if ($basketItem->getBasketCode() != $refreshItem->getBasketCode() && $basketItem->isBundleParent())
2603 if ($bundleCollection = $basketItem->getBundleCollection())
2607 foreach ($bundleCollection as $bundleBasketItem)
2609 if ($bundleBasketItem->getBasketCode() == $refreshItem->getBasketCode())
2619 $basketList[] = $bundleBasketItem;
2623 elseif ($basketItem->getBasketCode() != $refreshItem->getBasketCode())
2628 $basketList[] = $basketItem;
2633 $basketList[] = $basketItem;
2646 public static function tryReserveShipment(Shipment $shipment)
2651 $shipmentItemCollection = $shipment->getShipmentItemCollection();
2653 $shipmentItemList = $shipmentItemCollection->getShippableItems();
2655 foreach ($shipmentItemList as $shipmentItem)
2660 $r = static::tryReserveShipmentItem($shipmentItem);
2661 if (!$r->isSuccess())
2663 $result->addErrors($r->getErrors());
2665 elseif ($r->hasWarnings())
2667 $result->addWarnings($r->getWarnings());
2670 catch(\Exception $e)
2673 if (!$shipment = $shipmentItemCollection->getShipment())
2675 throw new ObjectNotFoundException(
'Entity "Shipment" not found');
2695 public static function tryUnreserveShipment(Shipment $shipment)
2699 if (!$shipmentItemCollection = $shipment->getShipmentItemCollection())
2701 throw new ObjectNotFoundException(
'Entity "ShipmentItemCollection" not found');
2705 if (!($shipmentCollection = $shipment->getCollection()))
2707 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
2711 if (!(
$order = $shipmentCollection->getOrder()))
2713 throw new ObjectNotFoundException(
'Entity "Order" not found');
2717 foreach ($shipmentItemCollection as $shipmentItem)
2720 $r = static::tryUnreserveShipmentItem($shipmentItem);
2721 if (!$r->isSuccess())
2723 $result->addErrors($r->getErrors());
2724 EntityMarker::addMarker(
$order, $shipment, $r);
2725 if (!$shipment->isSystem())
2727 $shipment->setField(
'MARKED',
'Y');
2730 elseif ($r->hasWarnings())
2732 $result->addWarnings($r->getWarnings());
2746 public static function tryReserveShipmentItem(ShipmentItem $shipmentItem)
2750 if (floatval($shipmentItem->getQuantity()) == floatval($shipmentItem->getReservedQuantity()))
2756 if (!$shipmentItemCollection = $shipmentItem->getCollection())
2758 throw new ObjectNotFoundException(
'Entity "ShipmentItemCollection" not found');
2762 if (!$shipment = $shipmentItemCollection->getShipment())
2764 throw new ObjectNotFoundException(
'Entity "Shipment" not found');
2767 if (!$shipmentCollection = $shipment->getCollection())
2769 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
2773 if (!
$order = $shipmentCollection->getOrder())
2775 throw new ObjectNotFoundException(
'Entity "Order" not found');
2779 if (!$basketItem = $shipmentItem->getBasketItem())
2781 $result->addError(
new ResultError(
2783 'SALE_PROVIDER_BASKET_ITEM_NOT_FOUND',
2785 '#BASKET_ITEM_ID#' => $shipmentItem->getBasketId(),
2786 '#SHIPMENT_ID#' => $shipment->getId(),
2787 '#SHIPMENT_ITEM_ID#' => $shipmentItem->getId(),
2790 'PROVIDER_RESERVE_SHIPMENT_ITEM_WRONG_BASKET_ITEM')
2796 if ($basketItem->isBundleParent())
2801 $needQuantity = ($shipmentItem->getQuantity() - $shipmentItem->getReservedQuantity());
2802 $canReserve =
false;
2804 $providerName = $basketItem->getProvider();
2806 if (class_exists($providerName))
2813 'USER_ID' =>
$order->getUserId(),
2814 'SITE_ID' =>
$order->getSiteId(),
2815 'CURRENCY' =>
$order->getCurrency(),
2822 'USER_ID' =>
$USER->getId(),
2824 'CURRENCY' => Currency\CurrencyManager::getBaseCurrency(),
2829 $availableQuantityData =
array();
2831 $providerClass =
new $providerName(
$context);
2832 if ($providerClass instanceof SaleProviderBase)
2834 $creator = Internals\ProviderCreator::create(
$context);
2835 $shipmentProductData = $creator->createItemForReserveByShipmentItem($shipmentItem);
2836 $creator->addProductData($shipmentProductData);
2838 $r = $creator->getAvailableQuantity();
2839 if ($r->isSuccess())
2841 $resultData = $r->getData();
2842 if (!empty($resultData[
'AVAILABLE_QUANTITY_LIST']))
2846 $resultAvailableQuantityList = $resultData[
'AVAILABLE_QUANTITY_LIST'];
2847 if (mb_substr($providerName, 0, 1) ==
"\\")
2849 $providerName = mb_substr($providerName, 1);
2852 if (isset($resultAvailableQuantityList[$providerName]) && isset($resultAvailableQuantityList[$providerName][$productId]))
2854 $availableQuantityData =
array(
2855 'HAS_PROVIDER' =>
true,
2856 'AVAILABLE_QUANTITY' => $resultAvailableQuantityList[$providerName][$productId]
2864 $result->addErrors($r->getErrors());
2871 $r = static::tryReserveBasketItem($basketItem, $needQuantity);
2873 $availableQuantityData = $r->getData();
2879 $r = static::tryReserveBasketItem($basketItem, $needQuantity);
2881 $availableQuantityData = $r->getData();
2884 if (!$r->isSuccess())
2886 $result->addErrors($r->getErrors());
2889 elseif ($r->hasWarnings())
2891 $result->addWarnings($r->getWarnings());
2895 if (array_key_exists(
'AVAILABLE_QUANTITY', $availableQuantityData))
2897 $availableQuantity = $availableQuantityData[
'AVAILABLE_QUANTITY'];
2901 $result->addWarning(
new ResultWarning(Loc::getMessage(
'SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY',
array(
2902 '#PRODUCT_NAME#' => $basketItem->getField(
'NAME')
2903 )),
'SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY') );
2907 if (array_key_exists(
'HAS_PROVIDER', $availableQuantityData))
2909 $canReserve = $availableQuantityData[
'HAS_PROVIDER'];
2912 if ($canReserve && array_key_exists(
'QUANTITY_TRACE', $availableQuantityData))
2914 $canReserve = $availableQuantityData[
'QUANTITY_TRACE'];
2919 if ($r->isSuccess() && ($needQuantity > 0) && ($needQuantity > $availableQuantity)
2922 $result->addWarning(
new ResultWarning(Loc::getMessage(
"SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_QUANTITY_NOT_ENOUGH",
array(
2923 '#PRODUCT_NAME#' => $basketItem->getField(
'NAME')
2924 )),
"SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_QUANTITY_NOT_ENOUGH"));
2929 if (($availableQuantity < 0) && ($shipmentItem->getReservedQuantity() + $availableQuantity < 0))
2931 $availableQuantity = -1 * $shipmentItem->getReservedQuantity();
2937 $reservedQuantity = ($availableQuantity >= $needQuantity ? $needQuantity : $availableQuantity);
2939 static::addReservationPoolItem(
$order->getInternalId(), $shipmentItem->getBasketItem(), $reservedQuantity);
2941 $r = $shipmentItem->setField(
'RESERVED_QUANTITY', $shipmentItem->getReservedQuantity() + $reservedQuantity);
2942 if (!$r->isSuccess())
2944 $result->addErrors($r->getErrors());
2950 'CAN_RESERVE' => $canReserve,
2966 public static function tryUnreserveShipmentItem(ShipmentItem $shipmentItem)
2971 if (!$shipmentItemCollection = $shipmentItem->getCollection())
2973 throw new ObjectNotFoundException(
'Entity "ShipmentItemCollection" not found');
2977 if (!$shipment = $shipmentItemCollection->getShipment())
2979 throw new ObjectNotFoundException(
'Entity "Shipment" not found');
2983 if (!$shipmentCollection = $shipment->getCollection())
2985 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
2989 if (!
$order = $shipmentCollection->getOrder())
2991 throw new ObjectNotFoundException(
'Entity "Order" not found');
2995 if (!$basketItem = $shipmentItem->getBasketItem())
2997 $result->addError(
new ResultError(
2999 'SALE_PROVIDER_BASKET_ITEM_NOT_FOUND',
3001 '#BASKET_ITEM_ID#' => $shipmentItem->getBasketId(),
3002 '#SHIPMENT_ID#' => $shipment->getId(),
3003 '#SHIPMENT_ITEM_ID#' => $shipmentItem->getId(),
3006 'PROVIDER_TRY_UNRESERVED_SHIPMENT_ITEM_WRONG_BASKET_ITEM')
3012 if ($basketItem->isBundleParent())
3017 $quantity = $shipmentItem->getReservedQuantity();
3019 $canReserve =
false;
3021 $providerName = $basketItem->getProvider();
3023 $providerExists =
false;
3024 $availableQuantityData =
array(
3025 'HAS_PROVIDER' =>
true,
3026 'AVAILABLE_QUANTITY' => $quantity
3029 if (class_exists($providerName))
3031 $providerClass =
new $providerName();
3032 if ($providerClass instanceof SaleProviderBase)
3034 $providerExists =
true;
3038 if (!$providerExists)
3040 if (!array_key_exists(
"IBXSaleProductProvider", class_implements($providerName)))
3042 $availableQuantityData[
'HAS_PROVIDER'] =
false;
3046 if (array_key_exists(
'HAS_PROVIDER', $availableQuantityData))
3048 $canReserve = $availableQuantityData[
'HAS_PROVIDER'];
3054 static::addReservationPoolItem(
$order->getInternalId(), $shipmentItem->getBasketItem(), $quantity);
3056 $reservedQuantity = ($shipmentItem->getReservedQuantity() > 0 ? $shipmentItem->getReservedQuantity() + $quantity : 0);
3058 $needShip = $shipment->needShip();
3061 $shipmentItem->setFieldNoDemand(
'RESERVED_QUANTITY', $reservedQuantity);
3065 $r = $shipmentItem->setField(
'RESERVED_QUANTITY', $reservedQuantity);
3066 if (!$r->isSuccess())
3068 $result->addErrors($r->getErrors());
3074 'CAN_RESERVE' => $canReserve,
3086 protected static function tryReserveBasketItem(BasketItem $basketItem, $quantity)
3092 if (!$basketItem->isBundleChild())
3095 $basket = $basketItem->getCollection();
3100 $parentBasketItem = $basketItem->getParentBasketItem();
3103 $basket = $parentBasketItem->getCollection();
3106 $order = $basket->getOrder();
3107 $hasProvider =
false;
3108 $quantityTrace =
null;
3110 $poolQuantity = static::getReservationPoolItem(
$order->getInternalId(), $basketItem);
3111 $tryQuantity = $quantity + $poolQuantity;
3113 if (
$provider && array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
3115 $hasProvider =
true;
3116 $r = static::checkAvailableProductQuantity($basketItem, $tryQuantity);
3118 $availableQuantityData = $r->getData();
3119 if (array_key_exists(
'AVAILABLE_QUANTITY', $availableQuantityData))
3121 $availableQuantity = floatval($availableQuantityData[
'AVAILABLE_QUANTITY']);
3125 $result->addWarning(
new ResultWarning(Loc::getMessage(
'SALE_PROVIDER_BASKET_ITEM_WRONG_AVAILABLE_QUANTITY',
array(
3126 '#PRODUCT_NAME#' => $basketItem->getField(
'NAME')
3127 )),
'PROVIDER_BASKET_ITEM_WRONG_AVAILABLE_QUANTITY'));
3131 if (array_key_exists(
'QUANTITY_TRACE', $availableQuantityData))
3133 $quantityTrace = $availableQuantityData[
'QUANTITY_TRACE'];
3136 if (!$r->isSuccess())
3138 $result->addErrors($r->getErrors());
3140 elseif ($r->hasWarnings())
3142 $result->addWarnings($r->getWarnings());
3145 $availableQuantity -= floatval($poolQuantity);
3149 $availableQuantity = $quantity;
3153 'AVAILABLE_QUANTITY' => $availableQuantity,
3154 'HAS_PROVIDER' => $hasProvider,
3157 if ($quantityTrace !==
null)
3159 $fields[
'QUANTITY_TRACE'] = $quantityTrace;
3174 private static function reserveBasketItem(BasketItem $basketItem, $quantity)
3181 if (!$basket = $basketItem->getCollection())
3183 throw new ObjectNotFoundException(
'Entity "Basket" not found');
3187 if (!
$order = $basket->getOrder())
3189 throw new ObjectNotFoundException(
'Entity "Order" not found');
3192 $r = static::reserveProduct(
$provider, $basketItem->getProductId(), $quantity);
3194 if ($r->hasWarnings() || !$r->isSuccess())
3196 if (!$r->isSuccess())
3198 $result->addWarnings($r->getErrors());
3201 if ($r->hasWarnings())
3203 $result->addWarnings($r->getWarnings());
3207 if (!$basket = $basketItem->getCollection())
3209 throw new ObjectNotFoundException(
'Entity "Basket" not found');
3212 if (
$order = $basket->getOrder())
3215 if (!$shipmentCollection =
$order->getShipmentCollection())
3217 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
3221 foreach ($shipmentCollection as $shipment)
3224 if (!$shipmentItemCollection = $shipment->getShipmentItemCollection())
3226 throw new ObjectNotFoundException(
'Entity "ShipmentItemCollection" not found');
3229 if($shipmentItemCollection->getItemByBasketCode($basketItem->getBasketCode()))
3232 if (!$shipment->isSystem())
3234 $shipment->setField(
'MARKED',
'Y');
3259 if (
$provider && array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
3261 $hasProvider =
true;
3266 $data[
"UNDO_RESERVATION"] =
"N";
3267 $data[
"QUANTITY_ADD"] = $quantity;
3271 $data[
"UNDO_RESERVATION"] =
"Y";
3272 $data[
"QUANTITY_ADD"] = abs($quantity);
3276 if (($resultReserveData = $provider::ReserveProduct(
$data)))
3278 if ($resultReserveData[
'RESULT'])
3280 $fields[
'QUANTITY'] = $resultReserveData[
'QUANTITY_RESERVED'];
3284 $fields[
'QUANTITY'] = $quantity;
3287 $fields[
'HAS_PROVIDER'] = $hasProvider;
3305 $result->addError(
new ResultError(Loc::getMessage(
'SALE_PROVIDER_RESERVE_BASKET_ITEM_ERROR'),
'SALE_PROVIDER_RESERVE_BASKET_ITEM_ERROR')) ;
3312 $result->addError(
new ResultError(Loc::getMessage(
'SALE_PROVIDER_RESERVE_BASKET_ITEM_ERROR'),
'SALE_PROVIDER_RESERVE_BASKET_ITEM_ERROR')) ;
3318 $fields[
'QUANTITY'] = $quantity;
3333 public static function reserveShipmentItem(
ShipmentItem $shipmentItem, $quantity)
3341 if (!$shipmentItemCollection)
3347 $shipment = $shipmentItemCollection->getShipment();
3350 throw new ObjectNotFoundException(
'Entity "Shipment" not found');
3357 $result->addError(
new ResultError(
3359 'SALE_PROVIDER_BASKET_ITEM_NOT_FOUND',
3361 '#BASKET_ITEM_ID#' => $shipmentItem->
getBasketId(),
3362 '#SHIPMENT_ID#' => $shipment->getId(),
3363 '#SHIPMENT_ITEM_ID#' => $shipmentItem->getId(),
3366 'PROVIDER_RESERVE_SHIPMENT_ITEM_WRONG_BASKET_ITEM')
3374 if (
$provider && array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
3377 "PRODUCT_ID" => $basketItem->getProductId(),
3378 "UNDO_RESERVATION" =>
"N",
3379 "QUANTITY_ADD" => $quantity,
3380 "ORDER_DEDUCTED" => $shipment->isShipped()?
"Y" :
"N",
3384 if (($resultReserveData = $provider::ReserveProduct(
$data)))
3386 if ($resultReserveData[
'RESULT'])
3388 $fields[
'QUANTITY'] = $resultReserveData[
'QUANTITY_RESERVED'];
3390 if (isset($resultReserveData[
'QUANTITY_NOT_RESERVED']) && floatval($resultReserveData[
'QUANTITY_NOT_RESERVED']) > 0)
3402 if ($ex->GetID() !=
"ALREADY_FLAG")
3403 $result->addError(
new ResultError($ex->GetString())) ;
3407 $result->addError(
new ResultError(Loc::getMessage(
'SALE_PROVIDER_RESERVE_BASKET_ITEM_ERROR'),
'SALE_PROVIDER_RESERVE_BASKET_ITEM_ERROR')) ;
3417 $shipmentCollection = $shipment->getCollection();
3418 if (!$shipmentCollection)
3420 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
3424 $order = $shipmentCollection->getOrder();
3427 throw new ObjectNotFoundException(
'Entity "Order" not found');
3431 'SITE_ID' =>
$order->getSiteId(),
3432 'CURRENCY' =>
$order->getCurrency(),
3435 if (
$order->getUserId() > 0)
3447 if ($providerClass && $providerClass instanceof SaleProviderBase)
3450 $creator = Internals\ProviderCreator::create(
$context);
3451 $creator->addShipmentItem($shipmentItem);
3453 $r = $creator->reserve();
3454 if (!$r->isSuccess())
3456 $result->addErrors($r->getErrors());
3476 public static function reduceProductQuantity(ShipmentCollection $shipmentCollection,
array $shipmentReserveList =
array())
3479 if (!
$order = $shipmentCollection->getOrder())
3481 throw new ObjectNotFoundException(
'Entity "Order" not found');
3485 'ORDER_DEDUCTED' =>
$order->isShipped()
3488 $shipmentReserveListKeys = array_keys($shipmentReserveList);
3490 foreach ($shipmentCollection as $shipmentKey => $shipment)
3492 if (!in_array($shipment->getId(), $shipmentReserveListKeys))
3494 unset($shipmentCollection[$shipmentKey]);
3499 foreach ($shipmentCollection as $shipment)
3501 $basketProviderList = static::getProviderBasketFromShipment($shipment);
3503 $productList = static::getProductListFromBasketProviderList($basketProviderList);
3505 if (!empty($basketProviderList))
3507 foreach ($basketProviderList as
$provider => $providerBasketItemList)
3509 $shipmentReserveListData =
array();
3510 if (!empty($shipmentReserveList)
3511 && !empty($shipmentReserveList[$shipment->getId()]) && is_array($shipmentReserveList[$shipment->getId()]))
3513 $shipmentReserveListData = $shipmentReserveList[$shipment->getId()];
3516 $result = $provider::reduceProductQuantity($providerBasketItemList, $productList, $shipmentReserveListData,
$options);
3530 public static function increaseProductQuantity(ShipmentCollection $shipmentCollection,
array $shipmentReserveList =
array())
3533 if (!
$order = $shipmentCollection->getOrder())
3535 throw new ObjectNotFoundException(
'Entity "Order" not found');
3539 'ORDER_DEDUCTED' =>
$order->isShipped()
3542 $shipmentReserveListKeys = array_keys($shipmentReserveList);
3544 foreach ($shipmentCollection as $shipmentKey => $shipment)
3546 if (!in_array($shipment->getId(), $shipmentReserveListKeys))
3548 unset($shipmentCollection[$shipmentKey]);
3553 foreach ($shipmentCollection as $shipment)
3555 $basketProviderList = static::getProviderBasketFromShipment($shipment);
3557 $productList = static::getProductListFromBasketProviderList($basketProviderList);
3559 if (!empty($basketProviderList))
3561 foreach ($basketProviderList as
$provider => $providerBasketItemList)
3563 $shipmentReserveListData =
array();
3564 if (!empty($shipmentReserveList)
3565 && !empty($shipmentReserveList[$shipment->getId()]) && is_array($shipmentReserveList[$shipment->getId()]))
3567 $shipmentReserveListData = $shipmentReserveList[$shipment->getId()];
3570 $result = $provider::increaseProductQuantity($providerBasketItemList, $productList, $shipmentReserveListData,
$options);
3583 public static function getProductStores(BasketItem $basketItem)
3587 $basketItemProviderMap = static::createProviderBasketItemMap($basketItem,
array(
'SITE_ID'));
3589 if (!empty($basketItemProviderMap))
3591 $provider = $basketItemProviderMap[
'PROVIDER'];
3593 if (array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
3595 $productId = $basketItemProviderMap[
"PRODUCT_ID"];
3597 "PRODUCT_ID" => $productId,
3598 "SITE_ID" => $basketItemProviderMap[
"SITE_ID"],
3599 'BASKET_ID' => $basketItemProviderMap[
'BASKET_ID']
3603 if ($r->isSuccess())
3605 $resultProductData = $r->getData();
3606 if (array_key_exists($productId, $resultProductData))
3608 $result->setData($resultProductData);
3616 $basket = $basketItem->getCollection();
3619 throw new ObjectNotFoundException(
'Entity "Basket" not found');
3623 $order = $basket->getOrder();
3626 throw new ObjectNotFoundException(
'Entity "Order" not found');
3630 'SITE_ID' =>
$order->getSiteId(),
3631 'CURRENCY' =>
$order->getCurrency(),
3634 if (
$order->getUserId() > 0)
3646 if ($providerClass && $providerClass instanceof SaleProviderBase)
3649 $creator = Internals\ProviderCreator::create(
$context);
3650 $creator->addBasketItem($basketItem);
3652 $r = $creator->getProductStores();
3653 if ($r->isSuccess())
3655 $result->setData($r->getData());
3659 $result->addErrors($r->getErrors());
3679 $resultData = $provider::getProductStores(
$fields);
3683 $fields[
'PRODUCT_ID'] => $resultData
3703 'BARCODE' =>
$params[
'BARCODE'],
3704 'STORE_ID' =>
$params[
'STORE_ID'],
3705 'PRODUCT_ID' => $productId
3709 if (
$provider && array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
3712 if ($r->isSuccess())
3714 $resultData = $r->getData();
3715 if (!empty($resultData) && array_key_exists($productId, $resultData))
3717 $result = $resultData[$productId];
3727 throw new ObjectNotFoundException(
'Entity "Basket" not found');
3730 $order = $basket->getOrder();
3735 'USER_ID' =>
$order->getUserId(),
3736 'SITE_ID' =>
$order->getSiteId(),
3737 'CURRENCY' =>
$order->getCurrency(),
3744 'USER_ID' =>
$USER->getId(),
3746 'CURRENCY' => Currency\CurrencyManager::getBaseCurrency(),
3750 $creator = Internals\ProviderCreator::create(
$context);
3753 if ($providerClass instanceof SaleProviderBase)
3755 $creator->addBasketItemBarcodeData($basketItem,
$data);
3758 $r = $creator->checkBarcode();
3759 if ($r->isSuccess())
3761 if (!empty($providerClass))
3763 $reflect = new \ReflectionClass(
$provider);
3764 $providerName = $reflect->getName();
3771 $resultData = $r->getData();
3772 if (!empty($resultData) && array_key_exists(
'BARCODE_CHECK_LIST', $resultData))
3774 $resultList = $resultData[
'BARCODE_CHECK_LIST'];
3775 if (isset($resultList[$providerName]) && isset($resultList[$providerName][
$data[
'BARCODE']]))
3777 $result = $resultList[$providerName][
$data[
'BARCODE']];
3795 if (!array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
3800 $resultData = $provider::checkProductBarcode($barcodeParams);
3804 $barcodeParams[
"PRODUCT_ID"] => $resultData
3817 public static function viewProduct(
BasketItem $basketItem)
3820 $basketProviderData = static::createProviderBasketItemMap($basketItem,
array(
'SITE_ID',
'USER_ID'));
3821 $provider = $basketProviderData[
'PROVIDER'];
3824 if (array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
3826 $productId = $basketProviderData[
'PRODUCT_ID'];
3828 'PRODUCT_ID' => $productId,
3829 'USER_ID' => $basketProviderData[
'USER_ID'],
3830 'SITE_ID' => $basketProviderData[
'SITE_ID'],
3834 if ($r->isSuccess())
3836 $resultProductData = $r->getData();
3837 if (array_key_exists($productId, $resultProductData))
3839 $result->setData($resultProductData);
3850 throw new ObjectNotFoundException(
'Entity "Basket" not found');
3853 $order = $basket->getOrder();
3858 'USER_ID' =>
$order->getUserId(),
3859 'SITE_ID' =>
$order->getSiteId(),
3860 'CURRENCY' =>
$order->getCurrency(),
3867 'USER_ID' =>
$USER->getId(),
3869 'CURRENCY' => Currency\CurrencyManager::getBaseCurrency(),
3873 $creator = Internals\ProviderCreator::create(
$context);
3876 if ($providerClass instanceof SaleProviderBase)
3878 $creator->addBasketItem($basketItem);
3881 $r = $creator->viewProduct();
3882 if ($r->isSuccess())
3884 $data = $r->getData();
3885 if (array_key_exists(
'VIEW_PRODUCTS_LIST',
$data))
3887 $resultList =
$data[
'VIEW_PRODUCTS_LIST'];
3889 if (!empty($resultList))
3896 $productId => reset($resultList)
3920 if (!array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
3925 $resultData = $provider::viewProduct(
$fields);
3928 $fields[
'PRODUCT_ID'] => $resultData
3940 public static function recurringOrderProduct(
BasketItem $basketItem)
3943 $basketProviderData = static::createProviderBasketItemMap($basketItem,
array(
'SITE_ID',
'USER_ID'));
3944 $provider = $basketProviderData[
'PROVIDER'];
3947 if (array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
3950 'PRODUCT_ID' => $basketProviderData[
'PRODUCT_ID'],
3951 'USER_ID' => $basketProviderData[
'USER_ID'],
3955 if ($r->isSuccess())
3957 $resultProductData = $r->getData();
3958 if (array_key_exists($basketProviderData[
'PRODUCT_ID'], $resultProductData))
3960 $result->setData($resultProductData);
3972 throw new ObjectNotFoundException(
'Entity "Basket" not found');
3975 $order = $basket->getOrder();
3980 'USER_ID' =>
$order->getUserId(),
3981 'SITE_ID' =>
$order->getSiteId(),
3982 'CURRENCY' =>
$order->getCurrency(),
3989 'USER_ID' =>
$USER->getId(),
3991 'CURRENCY' => Currency\CurrencyManager::getBaseCurrency(),
3995 $creator = Internals\ProviderCreator::create(
$context);
3998 if ($providerClass instanceof SaleProviderBase)
4000 $creator->addBasketItem($basketItem);
4003 $r = $creator->recurring();
4004 if ($r->isSuccess())
4006 $data = $r->getData();
4007 if (array_key_exists(
'RECURRING_PRODUCTS_LIST',
$data))
4009 $resultList =
$data[
'RECURRING_PRODUCTS_LIST'];
4011 if (!empty($resultList))
4018 $productId => reset($resultList)
4040 if (!array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
4045 $resultData = $provider::recurringOrderProduct(
$fields);
4048 $fields[
'PRODUCT_ID'] => $resultData
4062 $bundleChildList =
array();
4066 if (array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
4076 $basket = $collection->getBasket();
4079 throw new ObjectNotFoundException(
'Entity "Basket" not found');
4082 $order = $basket->getOrder();
4087 'SITE_ID' =>
$order->getSiteId(),
4088 'USER_ID' =>
$order->getUserId(),
4089 'CURRENCY' =>
$order->getCurrency(),
4098 'CURRENCY' => Currency\CurrencyManager::getBaseCurrency(),
4101 $creator = Internals\ProviderCreator::create(
$context);
4103 $creator->addBasketItem($basketItem);
4105 $r = $creator->getBundleItems();
4106 if ($r->isSuccess())
4108 $resultProductListData = $r->getData();
4109 if (!empty($resultProductListData[
'BUNDLE_LIST']))
4111 $bundleChildList = $resultProductListData[
'BUNDLE_LIST'];
4115 $order = $basket->getOrder();
4120 'SITE_ID' =>
$order->getSiteId(),
4121 'USER_ID' =>
$order->getUserId(),
4122 'CURRENCY' =>
$order->getCurrency(),
4131 'CURRENCY' => Currency\CurrencyManager::getBaseCurrency(),
4134 $creator = Internals\ProviderCreator::create(
$context);
4136 $creator->addBasketItem($basketItem);
4138 $r = $creator->getBundleItems();
4139 if ($r->isSuccess())
4141 $resultProductListData = $r->getData();
4142 if (!empty($resultProductListData[
'BUNDLE_LIST']))
4144 $bundleChildList = $resultProductListData[
'BUNDLE_LIST'];
4150 $bundleChildList = \CSaleBasket::executeCallbackFunction(
4151 $basketItem->
getField(
'CALLBACK_FUNC'),
4153 $basketItem->
getField(
'PRODUCT_ID'),
4158 return $bundleChildList;
4170 private static function getBundleChildItemsByProductData($providerName,
array $productData)
4172 if (array_key_exists(
"IBXSaleProductProvider", class_implements($providerName)))
4178 $bundleChildList = \CSaleBasket::executeCallbackFunction(
4186 if (is_array($bundleChildList))
4188 $bundleChildList = reset($bundleChildList);
4191 return $bundleChildList;
4204 $resultList =
array();
4208 $resultList[$productId] = static::getBundleChildItemsByProductData($providerName,
$productData);
4211 if (!empty($resultList))
4215 'BUNDLE_LIST' => $resultList,
4234 'NEGATIVE_AMOUNT_TRACE',
4240 $providerProductList =
array();
4242 if (!empty($basketProviderList))
4244 foreach ($basketProviderList as
$provider => $providerBasketItemList)
4246 $providerProductList = $provider::getProductList($providerBasketItemList, $productList,
$select) + $providerProductList;
4250 return (!empty($providerProductList) && is_array($providerProductList) ? $providerProductList :
false);
4261 public static function checkAvailableProductQuantity(
BasketItemBase $basketItem, $deltaQuantity)
4267 $resultProductData =
array();
4277 if (!$basket = $collection->getBasket())
4283 if ((
$order = $basket->getOrder()) !==
null)
4291 $siteId = $basket->getSiteId();
4298 if (array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
4303 $needQuantity = $deltaQuantity;
4310 $poolQuantity = static::getQuantityPoolItem(
$order->getInternalId(), $basketItem);
4313 $checkQuantity = $needQuantity - floatval($poolQuantity);
4317 "QUANTITY" => $checkQuantity,
4320 "BASKET_ID" => $basketItem->getId(),
4321 "CHECK_QUANTITY" =>
"Y",
4322 "AVAILABLE_QUANTITY" =>
"Y",
4323 'CHECK_PRICE' =>
'N',
4324 'CHECK_COUPONS' =>
'N',
4325 "SELECT_QUANTITY_TRACE" =>
"Y",
4329 if ($deltaQuantity <= 0 || $checkQuantity == 0)
4331 $result->setData(
array(
'AVAILABLE_QUANTITY' => $deltaQuantity));
4335 $hasTrustData =
false;
4339 if (static::isReadTrustData() ===
true
4342 $hasTrustData =
true;
4344 $productDataRequiredFields = array_merge(static::getProductDataRequiredFields(),
array(
'AVAILABLE_QUANTITY'));
4345 foreach ($productDataRequiredFields as $requiredField)
4347 if (!array_key_exists($requiredField, $resultProductData))
4349 $hasTrustData =
false;
4357 $hasTrustData =
false;
4365 $resultProductData = $provider::GetProductData(
$data);
4369 $result->addWarning(
new ResultWarning($ex->GetString(), $ex->GetID()) );
4378 if ($providerClass && $providerClass instanceof SaleProviderBase)
4382 $productId =>
array(
4383 'ITEM_CODE' => $productId,
4385 'QUANTITY' => $deltaQuantity,
4388 $r = $providerClass->getAvailableQuantity($products);
4389 if ($r->isSuccess())
4391 $resultData = $r->getData();
4392 if (!empty($resultData[
'AVAILABLE_QUANTITY_LIST']))
4394 $resultProductData =
array(
4395 'AVAILABLE_QUANTITY' => reset($resultData[
'AVAILABLE_QUANTITY_LIST'])
4404 $resultProductData = \CSaleBasket::ExecuteCallbackFunction(
4405 $basketItem->
getField(
'CALLBACK_FUNC'),
4413 $result->addWarning(
new ResultWarning($ex->GetString(), $ex->GetID()) );
4420 if ($deltaQuantity <= 0)
4422 $availableQuantity = $deltaQuantity;
4425 'AVAILABLE_QUANTITY' => $availableQuantity,
4433 if (array_key_exists(
'AVAILABLE_QUANTITY', $resultProductData))
4435 $fields[
'AVAILABLE_QUANTITY'] = $resultProductData[
'AVAILABLE_QUANTITY'];
4438 if (array_key_exists(
'QUANTITY_TRACE', $resultProductData))
4440 $fields[
'QUANTITY_TRACE'] = ($resultProductData[
'QUANTITY_TRACE'] ==
"Y");
4465 $callbackFunction =
null;
4477 $resultProductData =
array();
4484 $productQuantity = 0;
4491 foreach (
$productData[
'QUANTITY_LIST'] as $basketCode => $quantity)
4493 $productQuantity += $quantity;
4497 if (!empty($providerClass) && array_key_exists(
"IBXSaleProductProvider", class_implements($providerClass)))
4499 if ($productQuantity <= 0)
4503 'AVAILABLE_QUANTITY' => $productQuantity
4512 $basketId = $basketItem->getId();
4516 "PRODUCT_ID" => $productId,
4517 "QUANTITY" => $productQuantity,
4520 "BASKET_ID" => $basketId,
4521 "CHECK_QUANTITY" =>
"Y",
4522 "AVAILABLE_QUANTITY" =>
"Y",
4523 'CHECK_PRICE' =>
'N',
4524 'CHECK_COUPONS' =>
'N',
4525 "SELECT_QUANTITY_TRACE" =>
"Y",
4535 $hasTrustData =
false;
4539 if (static::isReadTrustData() ===
true
4542 $hasTrustData =
true;
4544 $productDataRequiredFields = array_merge(static::getProductDataRequiredFields(),
array(
'AVAILABLE_QUANTITY'));
4545 foreach ($productDataRequiredFields as $requiredField)
4547 if (!array_key_exists($requiredField, $resultProductData))
4549 $hasTrustData =
false;
4557 $hasTrustData =
false;
4565 $resultProductData = $providerClass::GetProductData(
$data);
4568 $result->addWarning(
new ResultWarning($ex->GetString(), $ex->GetID()) );
4573 elseif (!empty($callbackFunction))
4576 $resultProductData = \CSaleBasket::ExecuteCallbackFunction(
4585 $result->addWarning(
new ResultWarning($ex->GetString(), $ex->GetID()) );
4592 'AVAILABLE_QUANTITY' => $productQuantity
4600 if (!empty($resultProductData))
4602 if (array_key_exists(
'AVAILABLE_QUANTITY', $resultProductData))
4604 $fields[
'AVAILABLE_QUANTITY'] = $resultProductData[
'AVAILABLE_QUANTITY'];
4607 if (array_key_exists(
'QUANTITY_TRACE', $resultProductData))
4609 $fields[
'QUANTITY_TRACE'] = ($resultProductData[
'QUANTITY_TRACE'] ==
"Y");
4633 $providerName =
null;
4634 if (!empty($providerClass))
4636 $reflect = new \ReflectionClass($providerClass);
4637 $providerName = $reflect->getName();
4644 $r = static::getProductDataByList(
$items, $providerName,
array(
'PRICE',
'COUPONS',
'AVAILABLE_QUANTITY',
'QUANTITY'),
$context);
4646 if ($r->isSuccess())
4648 $resultData = $r->getData();
4649 $isExistsProductDataList = isset($resultData[
'PRODUCT_DATA_LIST']) && !empty($resultData[
'PRODUCT_DATA_LIST']);
4650 $isExistsProductData = isset($resultData[
'PRODUCT_DATA_LIST'][$productId]);
4652 if ($isExistsProductDataList && $isExistsProductData)
4654 $result->setData($resultData[
'PRODUCT_DATA_LIST'][$productId]);
4668 public static function deliverShipment(Shipment $shipment)
4673 $needDeliver =
null;
4674 if ($shipment->getFields()->isChanged(
'ALLOW_DELIVERY'))
4676 $needDeliver = $shipment->getField(
'ALLOW_DELIVERY') ===
"Y";
4679 if ($needDeliver ===
null || ($needDeliver ===
false && $shipment->getId() <= 0))
4682 $resultList =
array();
4685 if (!$shipmentItemCollection = $shipment->getShipmentItemCollection())
4687 throw new ObjectNotFoundException(
'Entity "ShipmentItemCollection" not found');
4691 if (!$shipmentCollection = $shipment->getCollection())
4693 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
4697 if (!
$order = $shipmentCollection->getOrder())
4699 throw new ObjectNotFoundException(
'Entity "Order" not found');
4703 if (!$basket =
$order->getBasket())
4708 $basketList = static::getBasketFromShipmentItemCollection($shipmentItemCollection);
4710 $basketProviderMap = static::createProviderBasketMap($basketList,
array(
'ORDER_ID',
'USER_ID',
'QUANTITY',
'ALLOW_DELIVERY',
'PAY_CALLBACK',
'PAID'));
4711 $basketProviderList = static::redistributeToProviders($basketProviderMap);
4713 if (!empty($basketProviderList))
4715 foreach ($basketProviderList as
$provider => $providerBasketItemList)
4717 if (array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
4720 foreach ($providerBasketItemList as $providerBasketItem)
4723 if ($providerBasketItem[
'BASKET_ITEM']->isBundleParent())
4728 if ($providerBasketItem[
'BASKET_ITEM']->getField(
'MODULE') !=
'')
4731 "PRODUCT_ID" => $providerBasketItem[
"PRODUCT_ID"],
4732 "USER_ID" => $providerBasketItem[
"USER_ID"],
4733 "PAID" => $providerBasketItem[
"PAID"],
4734 "ORDER_ID" => $providerBasketItem[
"ORDER_ID"],
4735 "BASKET_ID" => $providerBasketItem[
'BASKET_ID']
4739 if ($r->isSuccess())
4741 $resultData = $r->getData();
4743 if (array_key_exists($providerBasketItem[
"PRODUCT_ID"], $resultData))
4745 $resultProductData = $resultData[$providerBasketItem[
"PRODUCT_ID"]];
4750 $result->addErrors($r->getErrors());
4753 if (!empty($resultProductData) && is_array($resultProductData))
4755 $resultProductData[
'ORDER_ID'] = $providerBasketItem[
'ORDER_ID'];
4760 $resultProductData =
true;
4763 $resultList[$providerBasketItem[
'BASKET_CODE']] = $resultProductData;
4771 'SITE_ID' =>
$order->getSiteId(),
4772 'CURRENCY' =>
$order->getCurrency(),
4775 if (
$order->getUserId() > 0)
4785 $creator = Internals\ProviderCreator::create(
$context);
4788 foreach ($shipmentItemCollection as $shipmentItem)
4790 $basketItem = $shipmentItem->getBasketItem();
4793 if ($providerClass instanceof SaleProviderBase)
4795 $creator->addShipmentItem($shipmentItem);
4799 $r = $creator->deliver();
4800 if ($r->isSuccess())
4802 $r = $creator->createItemsResultAfterDeliver($r);
4803 if ($r->isSuccess())
4805 $data = $r->getData();
4806 if (array_key_exists(
'RESULT_AFTER_DELIVER_LIST',
$data))
4808 $resultList =
$data[
'RESULT_AFTER_DELIVER_LIST'] + $resultList;
4814 $result->addErrors($r->getErrors());
4819 foreach ($providerBasketItemList as $providerBasketItem)
4821 $resultProductData = \CSaleBasket::ExecuteCallbackFunction(
4822 $providerBasketItem[
'CALLBACK_FUNC'],
4823 $providerBasketItem[
'MODULE'],
4824 $providerBasketItem[
'PRODUCT_ID'],
4825 $providerBasketItem[
'USER_ID'],
4826 $providerBasketItem[
"ALLOW_DELIVERY"],
4827 $providerBasketItem[
'ORDER_ID'],
4828 $providerBasketItem[
"QUANTITY"]
4831 $basketCode = $providerBasketItem[
'BASKET_ITEM']->getBasketCode();
4833 if (!empty($resultProductData) && is_array($resultProductData))
4835 $resultProductData[
'ORDER_ID'] = $providerBasketItem[
'ORDER_ID'];
4838 $resultList[$basketCode] = $resultProductData;
4843 if (!empty($resultList) && is_array($resultList))
4845 $recurringID = intval(
$order->getField(
"RECURRING_ID"));
4846 foreach ($resultList as $basketCode => $resultData)
4850 if (!empty($resultData) && is_array($resultData))
4852 if (empty($resultData[
'ORDER_ID']) || intval($resultData[
'ORDER_ID']) < 0)
4853 $resultData[
"ORDER_ID"] =
$order->getId();
4856 $resultData[
"SUCCESS_PAYMENT"] =
"Y";
4858 if ($recurringID > 0)
4859 \CSaleRecurring::Update($recurringID, $resultData);
4861 \CSaleRecurring::Add($resultData);
4863 elseif ($recurringID > 0)
4865 \CSaleRecurring::Delete($recurringID);
4871 if (!$basketItem = $basket->getItemByBasketCode($basketCode))
4873 throw new ObjectNotFoundException(
'Entity "BasketItem" not found');
4876 $resRecurring = \CSaleRecurring::GetList(
4879 "USER_ID" =>
$order->getUserId(),
4881 "MODULE" => $basketItem->
getField(
"MODULE")
4884 while ($recurringData = $resRecurring->Fetch())
4886 \CSaleRecurring::Delete($recurringData[
"ID"]);
4893 if (!empty($resultList))
4895 $result->setData($resultList);
4913 $resultProductData =
false;
4915 if (
$provider && array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider)))
4917 $resultProductData = $provider::DeliverProduct(
$fields);
4931 if (!empty($resultProductData) && is_array($resultProductData))
4933 $resultProductData[
'ORDER_ID'] =
$fields[
'ORDER_ID'];
4945 $resultList[
$fields[
'PRODUCT_ID']] = $resultProductData;
4948 if (!empty($resultList) && is_array($resultList))
4950 $result->setData($resultList);
4965 $basketProviderMap =
array();
4971 foreach($basketList as $basketIndex => $basketItemDat)
4973 if (is_array($basketItemDat) && isset($basketItemDat[
'BASKET_ITEM']))
4975 $basketItem = $basketItemDat[
'BASKET_ITEM'];
4979 $basketItem = $basketItemDat;
4982 $basketProviderData = static::createProviderBasketItemMap($basketItem,
$select);
4983 if (!$basketProviderData)
4988 $basketProviderMap[$basketIndex] = $basketProviderData;
4992 return $basketProviderMap;
4996 protected static function createProviderBasketItemMap(BasketItem $basketItem,
array $select =
array())
4999 $basketProviderData =
array(
5000 'BASKET_ITEM' => $basketItem,
5001 'BASKET_ID' => $basketItem->getId(),
5002 'BASKET_CODE' => $basketItem->getBasketCode(),
5003 'PRODUCT_ID' => $basketItem->getProductId(),
5004 'MODULE' => $basketItem->getField(
'MODULE'),
5008 $providerClass = $basketItem->getProviderEntity();
5011 if (array_key_exists(
"IBXSaleProductProvider", class_implements(
$provider))
5012 || $providerClass instanceof SaleProviderBase)
5014 $basketProviderData[
'PROVIDER'] =
$provider;
5017 elseif (strval($basketItem->getField(
'CALLBACK_FUNC')) !=
'')
5019 $basketProviderData[
'CALLBACK_FUNC'] = $basketItem->getField(
'CALLBACK_FUNC');
5021 elseif (strval($basketItem->getField(
'PAY_CALLBACK_FUNC')) !=
'' && in_array(
'PAY_CALLBACK',
$select))
5023 $basketProviderData[
'CALLBACK_FUNC'] = $basketItem->getField(
'PAY_CALLBACK_FUNC');
5026 if (in_array(
'QUANTITY',
$select))
5028 $basketProviderData[
'QUANTITY'] = $basketItem->getQuantity();
5031 if (in_array(
'RENEWAL',
$select))
5033 $basketProviderData[
'RENEWAL'] = $basketItem->getField(
'RENEWAL')!==
null && $basketItem->getField(
'RENEWAL') !=
'N'?
'Y' :
'N';
5036 if (in_array(
'RESERVED',
$select))
5038 $basketProviderData[
'RESERVED'] = $basketItem->getField(
'RESERVED');
5041 if (in_array(
'SITE_ID',
$select))
5043 $basketProviderData[
'SITE_ID'] = $basketItem->getField(
'LID');
5046 if (in_array(
'ORDER_ID',
$select))
5049 if (!$basket = $basketItem->getCollection())
5051 throw new ObjectNotFoundException(
'Entity "Basket" not found');
5054 if ($basket->getOrder() && $basket->getOrderId() > 0)
5056 $basketProviderData[
'ORDER_ID'] = $basket->getOrderId();
5061 if (in_array(
'USER_ID',
$select))
5064 if (!$basket = $basketItem->getCollection())
5066 throw new ObjectNotFoundException(
'Entity "Basket" not found');
5069 if (
$order = $basket->getOrder())
5075 $userId = Sale\Fuser::getUserIdById($basket->getFUserId());
5080 $basketProviderData[
'USER_ID'] =
$userId;
5086 if (in_array(
'PAID',
$select))
5089 if (!$basket = $basketItem->getCollection())
5091 throw new ObjectNotFoundException(
'Entity "Basket" not found');
5094 if ($basket->getOrder() && $basket->getOrderId() > 0)
5096 $order = $basket->getOrder();
5097 $basketProviderData[
'PAID'] =
$order->isPaid();
5102 if (in_array(
'ALLOW_DELIVERY',
$select))
5105 if (!$basket = $basketItem->getCollection())
5107 throw new ObjectNotFoundException(
'Entity "Basket" not found');
5110 if ($basket->getOrder() && $basket->getOrderId() > 0)
5113 $order = $basket->getOrder();
5116 if ($shipmentCollection =
$order->getShipmentCollection())
5118 $basketProviderData[
'ALLOW_DELIVERY'] = $shipmentCollection->isAllowDelivery();
5124 return $basketProviderData;
5130 private static function getProviderBasketFromShipment(Shipment $shipment)
5132 $shipmentItemCollection = $shipment->getShipmentItemCollection();
5134 $basketList = static::getBasketFromShipmentItemCollection($shipmentItemCollection);
5136 $basketProviderMap = static::createProviderBasketMap($basketList,
array(
'QUANTITY',
'PRODUCT_ID'));
5138 $basketProviderList = static::redistributeToProviders($basketProviderMap);
5140 return $basketProviderList;
5150 $basketProviderList =
array();
5151 foreach($basketProviderMap as $basketProviderItem)
5153 $providerName = $basketProviderItem[
'PROVIDER'] ??
'';
5154 $productId = $basketProviderItem[
'BASKET_ITEM']->getProductId();
5155 $quantity = floatval($basketProviderItem[
'QUANTITY']);
5156 unset($basketProviderItem[
'QUANTITY']);
5158 $basketCode = $basketProviderItem[
'BASKET_CODE'];
5160 if (!isset($basketProviderList[$providerName][$productId]))
5162 $basketProviderList[$providerName][$productId] = $basketProviderItem;
5165 if (isset($basketProviderList[$providerName][$productId][
'QUANTITY_LIST'][$basketCode]))
5167 $basketProviderList[$providerName][$productId][
'QUANTITY_LIST'][$basketCode] += $quantity;
5171 $basketProviderList[$providerName][$productId][
'QUANTITY_LIST'][$basketCode] = $quantity;
5178 return $basketProviderList;
5187 static::$useReadTrustData = (bool)$value;
5196 return (
bool)static::$useReadTrustData;
5210 return (!empty(static::$trustData[
$siteId][$module][$productId]) && is_array(static::$trustData[
$siteId][$module][$productId]));
5237 if (static::isExistsTrustData(
$siteId, $module, $productId))
5238 return static::$trustData[
$siteId][$module][$productId];
5253 if (!empty(static::$trustData[
$siteId]))
5255 if (intval($productId) > 0 )
5257 if (strval($module) ==
'')
5259 foreach (static::$trustData[
$siteId] as $moduleName =>
$data)
5261 if (isset(static::$trustData[
$siteId][$moduleName][$productId]))
5262 unset(static::$trustData[
$siteId][$moduleName][$productId]);
5267 if (isset(static::$trustData[
$siteId][$module][$productId]))
5268 unset(static::$trustData[
$siteId][$module][$productId]);
5271 elseif (strval($module) !=
'')
5273 if (isset(static::$trustData[
$siteId][$module]))
5274 unset(static::$trustData[
$siteId][$module]);
5278 if (isset(static::$trustData[
$siteId]))
5279 unset(static::$trustData[
$siteId]);
5285 static::$trustData =
array();
5301 protected static function refreshMarkers(Order
$order)
5303 if (
$order->getId() == 0)
5308 if (!$shipmentCollection =
$order->getShipmentCollection())
5310 throw new ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
5315 throw new ObjectNotFoundException(
'Entity "PaymentCollection" not found');
5318 if (!$basket =
$order->getBasket())
5320 throw new ObjectNotFoundException(
'Entity "Basket" not found');
5323 $markList =
array();
5325 $markerEntityList =
array();
5329 '=ORDER_ID' =>
$order->getId(),
5332 'select' =>
array(
'ID',
'ENTITY_TYPE',
'ENTITY_ID',
'CODE',
'SUCCESS'),
5333 'order' =>
array(
'ID' =>
'DESC')
5336 while($markerData =
$res->fetch())
5338 if (!empty($markList[$markerData[
'ENTITY_TYPE']])
5339 && !empty($markList[$markerData[
'ENTITY_TYPE']][$markerData[
'ENTITY_ID']])
5340 && $markerData[
'CODE'] == $markList[$markerData[
'ENTITY_TYPE']][$markerData[
'ENTITY_ID']]
5348 $markList[$markerData[
'ENTITY_TYPE']][$markerData[
'ENTITY_ID']][] = $markerData[
'CODE'];
5355 foreach ($markList[$markerData[
'ENTITY_TYPE']][$markerData[
'ENTITY_ID']] as $markerIndex => $markerCode)
5357 if ($markerData[
'CODE'] == $markerCode)
5359 unset($markList[$markerData[
'ENTITY_TYPE']][$markerData[
'ENTITY_ID']][$markerIndex]);
5363 if (empty($markList[$markerData[
'ENTITY_TYPE']][$markerData[
'ENTITY_ID']]))
5365 unset($markList[$markerData[
'ENTITY_TYPE']][$markerData[
'ENTITY_ID']]);
5370 if (empty($markList[$markerData[
'ENTITY_TYPE']]))
5372 unset($markList[$markerData[
'ENTITY_TYPE']]);
5376 if (!empty($markList))
5378 foreach ($markList as $markEntityType => $markEntityList)
5380 foreach ($markEntityList as $markEntityId => $markEntityCodeList)
5382 if (empty($markEntityCodeList))
5384 if ((
$entity = EntityMarker::getEntity(
$order, $markEntityType, $markEntityId)) && (
$entity instanceof \IEntityMarker))
5388 $markedField =
$entity->getMarkField();
5389 $entity->setField($markedField,
'N');
5399 if ($shipmentCollection->isMarked())
5402 foreach ($shipmentCollection as $shipment)
5404 if ($shipment->isMarked())
5406 $shipment->setField(
'MARKED',
'N');
5422 $order->setField(
'MARKED',
'N');
5447 static::getUpdatableFields()
5470 'QUANTITY_RESERVED',
5518 $resultList =
array();
5523 if (!$r->isSuccess())
5525 $result->addErrors($r->getErrors());
5527 elseif ($r->hasWarnings())
5529 $result->addWarnings($r->getWarnings());
5532 $availableQuantityData = $r->getData();
5533 if (array_key_exists(
'AVAILABLE_QUANTITY', $availableQuantityData))
5535 $resultList[$productId] ??= 0;
5537 $resultList[$productId] += floatval($availableQuantityData[
'AVAILABLE_QUANTITY']);
5542 '#PRODUCT_ID#' => $productId
5543 )),
'PROVIDER_BASKET_ITEM_WRONG_AVAILABLE_QUANTITY'));
5548 if (!empty($resultList))
5552 'AVAILABLE_QUANTITY_LIST' => $resultList,
5569 public static function getAvailableQuantityAndPrice($providerClass,
array $products,
array $context)
5572 $availableQuantityList =
array();
5573 $priceData =
array();
5574 $providerName =
null;
5585 $callbackFunction =
null;
5591 $isCustomItem = !($providerClass || $callbackFunction);
5595 $providerData = $basketItem->getFieldValues();
5596 $providerData[
'AVAILABLE_QUANTITY'] = $basketItem->getQuantity();
5601 if (!$r->isSuccess())
5603 $result->addErrors($r->getErrors());
5605 elseif ($r->hasWarnings())
5607 $result->addWarnings($r->getWarnings());
5609 $providerData = $r->getData();
5612 if (!empty($providerData))
5614 if (isset($providerData[
'AVAILABLE_QUANTITY']))
5617 $availableQuantityList[
$productId] += (float)$providerData[
'AVAILABLE_QUANTITY'];
5621 $result->addWarning(
new ResultWarning(Loc::getMessage(
'SALE_PROVIDER_BASKET_ITEM_WRONG_AVAILABLE_QUANTITY',
array(
5622 '#PRODUCT_ID#' => $productId
5623 )),
'PROVIDER_BASKET_ITEM_WRONG_AVAILABLE_QUANTITY'));
5633 if (array_key_exists($fieldName, $providerData))
5635 $priceData[
$productId][$basketItem->getBasketCode()][$fieldName] = $providerData[$fieldName];
5645 'PRODUCT_DATA_LIST' =>
array(
5646 'PRICE_LIST' => $priceData,
5647 'AVAILABLE_QUANTITY_LIST' => $availableQuantityList
5662 public static function isNeedShip($shipmentItemList)
5666 $resultList =
array();
5669 foreach ($shipmentItemList as $shipmentItem)
5671 $basketItem = $shipmentItem->getBasketItem();
5672 $providerName = $basketItem->getProviderName();
5674 if ($providerName && array_key_exists(
"IBXSaleProductProvider", class_implements($providerName)))
5677 $isNeedShip =
false;
5679 if (method_exists($providerName,
'isNeedShip'))
5681 $isNeedShip = $providerName::isNeedShip();
5684 $resultList[$providerName] = $isNeedShip;
5689 if (!empty($resultList))
5691 $result->setData($resultList);