47 $builder =
new static();
66 protected function callTransferMethod($className, $methodName,
Sale\
Result $result =
null)
68 if (!class_exists($className))
78 if (!method_exists($transfer, $methodName))
85 $r = $transfer->$methodName($this->
getItems(), $result);
89 $r = $transfer->$methodName($this->
getItems());
116 $this->addItem($barcodeParams[
'PRODUCT_ID'], $barcodeParams);
125 'PRODUCT_ID' => $productId,
128 $this->addItem($productId, $fields);
139 if (!$r->isSuccess())
155 if (!$r->isSuccess())
171 if (!$r->isSuccess())
187 if (!$r->isSuccess())
204 $providerData = $resultProvider->getData();
206 if (empty($providerData[$outputName]))
211 $result->setData($providerData);
312 return static::callTransferMethod($this->
getTransferClassName(),
'setItemsResultAfterShip', $result);
337 public function createItemsResultAfterDeliver(
Sale\
Result $resultAfterDeliver)
340 $resultList = array();
343 if (empty($products))
348 $resultDeliverData = $resultAfterDeliver->getData();
350 foreach ($products as $productId => $productData)
353 if (empty($resultDeliverData[
'DELIVER_PRODUCTS_LIST']) ||
354 empty($resultDeliverData[
'DELIVER_PRODUCTS_LIST'][$providerName]) ||
355 !array_key_exists($productId, $resultDeliverData[
'DELIVER_PRODUCTS_LIST'][$providerName]))
360 if (empty($productData[
'SHIPMENT_ITEM_LIST']))
369 foreach ($productData[
'SHIPMENT_ITEM_LIST'] as $shipmentItemIndex => $shipmentItem)
371 $basketItem = $shipmentItem->getBasketItem();
375 throw new Main\ObjectNotFoundException(
'Entity "BasketItem" not found');
378 $resultList[$basketItem->getBasketCode()] = $resultDeliverData[
'DELIVER_PRODUCTS_LIST'][$providerName][
$productId];
382 if (!empty($resultList))
386 'RESULT_AFTER_DELIVER_LIST' => $resultList
399 $this->items[$productData[
'PRODUCT_ID']] = $productData;
426 $providerName =
null;
431 $providerName = $reflect->getName();
444 if (is_string($providerName) && mb_substr($providerName, 0, 1) ==
"\\")
446 $providerName = mb_substr($providerName, 1);
449 return $providerName;
474 protected function addItem($productId, array $productData)
477 if (isset($this->items[$productId]))
479 $fields = $this->items[$productId];
482 $fields = $productData + $fields;
484 if (isset($fields[
'QUANTITY_LIST'][$productData[
'BASKET_CODE']]))
486 $fields[
'QUANTITY_LIST'][$productData[
'BASKET_CODE']] += (float)$productData[
'QUANTITY'];
490 $fields[
'QUANTITY_LIST'][$productData[
'BASKET_CODE']] = (float)$productData[
'QUANTITY'];
493 unset($fields[
'QUANTITY']);
495 if (isset($fields[
'QUANTITY_LIST_BY_STORE'][$productData[
'BASKET_CODE']]))
497 foreach ($productData[
'QUANTITY_BY_STORE'] as $storeId => $quantity)
499 if (!isset($fields[
'QUANTITY_LIST_BY_STORE'][$productData[
'BASKET_CODE']][$storeId]))
501 $fields[
'QUANTITY_LIST_BY_STORE'][$productData[
'BASKET_CODE']][$storeId] = 0;
504 $fields[
'QUANTITY_LIST_BY_STORE'][$productData[
'BASKET_CODE']][
$storeId] += $quantity;
509 $fields[
'QUANTITY_LIST_BY_STORE'][$productData[
'BASKET_CODE']] = $productData[
'QUANTITY_BY_STORE'] ?? [];
512 unset($fields[
'QUANTITY_BY_STORE']);
514 if (isset($fields[
'RESERVED_QUANTITY_LIST'][$productData[
'BASKET_CODE']]))
516 $fields[
'RESERVED_QUANTITY_LIST'][$productData[
'BASKET_CODE']] += (float)$productData[
'RESERVED_QUANTITY'];
520 $fields[
'RESERVED_QUANTITY_LIST'][$productData[
'BASKET_CODE']] = (float)($productData[
'RESERVED_QUANTITY'] ?? 0.0);
523 unset($fields[
'RESERVED_QUANTITY']);
525 if (isset($fields[
'RESERVED_QUANTITY_LIST_BY_STORE'][$productData[
'BASKET_CODE']]))
527 foreach ($productData[
'RESERVED_QUANTITY_BY_STORE'] as $storeId => $quantity)
529 if (!isset($fields[
'RESERVED_QUANTITY_LIST_BY_STORE'][$productData[
'BASKET_CODE']][$storeId]))
531 $fields[
'RESERVED_QUANTITY_LIST_BY_STORE'][$productData[
'BASKET_CODE']][
$storeId] = 0;
534 $fields[
'RESERVED_QUANTITY_LIST_BY_STORE'][$productData[
'BASKET_CODE']][
$storeId] += $quantity;
539 $fields[
'RESERVED_QUANTITY_LIST_BY_STORE'][$productData[
'BASKET_CODE']] = $productData[
'RESERVED_QUANTITY_BY_STORE'] ?? [];
542 unset($fields[
'RESERVED_QUANTITY_BY_STORE']);
544 if (isset($productData[
'SHIPMENT_ITEM']))
547 $shipmentItem = $productData[
'SHIPMENT_ITEM'];
548 unset($fields[
'SHIPMENT_ITEM']);
550 $fields[
'SHIPMENT_ITEM_LIST'][$shipmentItem->getInternalIndex()] = $shipmentItem;
551 $fields[
'SHIPMENT_ITEM_QUANTITY_LIST'][$shipmentItem->getInternalIndex()] = (float)$productData[
'QUANTITY'];
554 if (isset($productData[
'STORE_DATA']))
556 if (!isset($fields[
'STORE_DATA_LIST']))
558 $fields[
'STORE_DATA_LIST'] = array();
561 $fields[
'STORE_DATA_LIST'] = $productData[
'STORE_DATA'] + $fields[
'STORE_DATA_LIST'];
562 unset($fields[
'STORE_DATA']);
565 if (isset($productData[
'IS_BARCODE_MULTI']) && !isset($fields[
'IS_BARCODE_MULTI']))
567 $fields[
'IS_BARCODE_MULTI'] = $productData[
'IS_BARCODE_MULTI'];
570 if (isset($productData[
'SHIPMENT_ITEM_DATA']))
572 if (!isset($fields[
'SHIPMENT_ITEM_DATA_LIST']))
574 $fields[
'SHIPMENT_ITEM_DATA_LIST'] = array();
577 $fields[
'SHIPMENT_ITEM_DATA_LIST'] = $productData[
'SHIPMENT_ITEM_DATA'] + $fields[
'SHIPMENT_ITEM_DATA_LIST'];
578 unset($fields[
'SHIPMENT_ITEM_DATA']);
581 if (isset($productData[
'NEED_RESERVE']))
583 if (!isset($fields[
'NEED_RESERVE_LIST']))
585 $fields[
'NEED_RESERVE_LIST'] = [];
588 $fields[
'NEED_RESERVE_LIST'] = $productData[
'NEED_RESERVE'] + $fields[
'NEED_RESERVE_LIST'];
590 unset($fields[
'NEED_RESERVE']);
593 if (isset($productData[
'NEED_RESERVE_BY_STORE']))
595 if (!isset($fields[
'NEED_RESERVE_BY_STORE_LIST']))
597 $fields[
'NEED_RESERVE_BY_STORE_LIST'] = [];
600 $fields[
'NEED_RESERVE_BY_STORE_LIST'] = $productData[
'NEED_RESERVE_BY_STORE'] + $fields[
'NEED_RESERVE_BY_STORE_LIST'];
602 unset($fields[
'NEED_RESERVE_BY_STORE']);
618 $item = $this->items[$productId];
630 return (isset($this->items[$productId]));
638 return get_called_class();