- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/helpers/admin/blocks/orderbasketshipment.php
- Класс: BitrixSaleHelpersAdminBlocksOrderBasketShipment
- Вызов: OrderBasketShipment::getProductsInfo
public function getProductsInfo($shipmentItemCollection)
{
/** @var BitrixSaleShipment $shipment */
$shipment = $shipmentItemCollection->getShipment();
$systemShipmentItemCollection = null;
$systemShipmentItem = null;
$result = array(
"ITEMS" => array()
);
if (!$shipment->isSystem())
{
/** @var BitrixSaleShipment $systemShipment */
$systemShipment = $shipment->getCollection()->getSystemShipment();
$systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
}
$items = array();
$catalogProductsIds = array();
/** @var BitrixSaleShipmentItem $item */
foreach($shipmentItemCollection as $item)
{
$basketItem = $item->getBasketItem();
if ($basketItem && $basketItem->getField("MODULE") == "catalog")
$catalogProductsIds[] = $basketItem->getProductId();
}
if(!empty($catalogProductsIds))
$catalogProductsFields = self::getProductsData($catalogProductsIds, $this->order->getSiteId(), $this->visibleColumns, $this->order->getUserId());
/** @var BitrixSaleShipmentItem $item */
foreach($shipmentItemCollection as $item)
{
$params = array();
$basketItem = $item->getBasketItem();
if ($basketItem)
{
$systemShipmentItem = null;
if ($systemShipmentItemCollection)
{
/** @var BitrixSaleShipmentItemCollection $systemShipmentItemCollection */
$systemShipmentItem = $systemShipmentItemCollection->getItemByBasketCode($basketItem->getBasketCode());
}
$productId = $basketItem->getProductId();
if ($basketItem->getField("MODULE") === "catalog" && !empty($catalogProductsFields[$productId]))
{
$params = $catalogProductsFields[$productId];
}
if (intval($basketItem->getField("MEASURE_CODE")) > 0)
{
$params["MEASURE_CODE"] = intval($basketItem->getField("MEASURE_CODE"));
}
elseif (!isset($params["MEASURE_CODE"]))
{
$params["MEASURE_CODE"] = 0;
}
if (!empty($basketItem->getField("MEASURE_NAME")))
{
$params["MEASURE_TEXT"] = $basketItem->getField("MEASURE_NAME");
}
elseif(!isset($params["MEASURE_TEXT"]))
{
$params["MEASURE_TEXT"] = "";
}
if ($basketItem->isBundleParent())
{
$params["BASE_ELEMENTS_QUANTITY"] = $basketItem->getBundleBaseQuantity();
if (!isset($params['IS_SET_ITEM']))
$params['IS_SET_ITEM'] = 'N';
if (!isset($params['IS_SET_PARENT']))
$params['IS_SET_PARENT'] = 'Y';
if (!isset($params['OLD_PARENT_ID']))
$params['OLD_PARENT_ID'] = '';
}
$params["BASKET_ID"] = $basketItem->getId();
$params["PRODUCT_PROVIDER_CLASS"] = $basketItem->getProvider();
$params["NAME"] = $basketItem->getField("NAME");
$params["MODULE"] = $basketItem->getField("MODULE");
$params['TYPE'] = (int)$basketItem->getField('TYPE');
$params['BARCODE_INFO'] = [];
$itemStoreCollection = $item->getShipmentItemStoreCollection();
if ($itemStoreCollection)
{
/** @var BitrixSaleShipmentItemStore $barcode */
foreach ($itemStoreCollection as $barcode)
{
$storeId = $barcode->getStoreId();
if (!isset($params['BARCODE_INFO'][$storeId]))
{
$params['BARCODE_INFO'][$storeId] = [];
}
$params['BARCODE_INFO'][$storeId][] = [
'ID' => $barcode->getId(),
'BARCODE' => $barcode->getBarcode(),
'MARKING_CODE' => $barcode->getMarkingCode(),
'QUANTITY' => $barcode->getQuantity(),
];
}
}
if (!$shipment->isSystem())
$params['ORDER_DELIVERY_BASKET_ID'] = $item->getId();
$systemItemQuantity = ($systemShipmentItem) ? $systemShipmentItem->getQuantity() : 0;
$params["QUANTITY"] = floatval($item->getQuantity() + $systemItemQuantity);
$params["AMOUNT"] = floatval($item->getQuantity());
$params["PRICE"] = $basketItem->getPrice();
$params["CURRENCY"] = $basketItem->getCurrency();
$params["PROPS"] = array();
/** @var BitrixSaleBasketPropertyItem $property */
foreach($basketItem->getPropertyCollection() as $property)
{
$params["PROPS"][] = array(
"VALUE" => $property->getField("VALUE"),
"NAME" => $property->getField("NAME"),
"CODE" => $property->getField("CODE"),
"SORT" => $property->getField("SORT")
);
}
if(BitrixMainLoader::includeModule("catalog"))
{
$productInfo = CCatalogSku::GetProductInfo($productId);
if ($productInfo)
{
$params["OFFERS_IBLOCK_ID"] = $productInfo["OFFER_IBLOCK_ID"];
$params["IBLOCK_ID"] = $productInfo["IBLOCK_ID"];
$params["PRODUCT_ID"] = $productInfo["ID"];
}
}
$params["PARENT_BASKET_ID"] = $basketItem->getParentBasketItemId() ?? 0;
//If product became bundle, but in saved order it is a simple product.
if ($basketItem->getBasketCode() == intval($basketItem->getBasketCode()) && !$basketItem->isBundleParent() && !empty($params['SET_ITEMS']))
{
unset($params['SET_ITEMS'], $params['OLD_PARENT_ID']);
$params['IS_SET_PARENT'] = 'N';
}
$params['IS_SUPPORTED_MARKING_CODE'] = $basketItem->isSupportedMarkingCode() ? 'Y' : 'N';
}
else
{
$systemShipmentItem = null;
if ($systemShipmentItemCollection)
{
/** @var BitrixSaleShipmentItemCollection $systemShipmentItemCollection */
$systemShipmentItem = $systemShipmentItemCollection->getItemByBasketId($item->getBasketId());
}
$systemItemQuantity = ($systemShipmentItem) ? $systemShipmentItem->getQuantity() : 0;
$params = array(
'NAME' => Loc::getMessage("SALE_ORDER_SHIPMENT_BASKET_WRONG_BASKET_ITEM"),
'QUANTITY' => floatval($item->getQuantity() + $systemItemQuantity),
'AMOUNT' => floatval($item->getQuantity()),
'BASKET_ID' => $item->getBasketId(),
);
}
$items[$params['BASKET_ID']] = $params;
}
$bundleChild = array();
foreach ($items as $basketId => $item)
{
$parentBasketId = $item['PARENT_BASKET_ID'];
if ($parentBasketId > 0)
{
$item['IS_SET_ITEM'] = 'Y';
$item['OLD_PARENT_ID'] = $items[$parentBasketId]['OLD_PARENT_ID'];
$bundleChild[$parentBasketId][] = $item;
unset($items[$basketId]);
}
}
foreach ($items as $basketId => $item)
{
if (isset($bundleChild[$basketId]))
$items[$basketId]['SET_ITEMS'] = $bundleChild[$basketId];
}
$result['ITEMS'] = $items;
return $result;
}