- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/internals/catalog/provider.php
- Класс: BitrixSaleInternalsCatalogProvider
- Вызов: Provider::tryShipShipment
static function tryShipShipment(SaleShipment $shipment, array $context = array())
{
$result = new SaleResult();
$order = $shipment->getOrder();
$context = self::prepareContext($order, $context);
$pool = PoolQuantity::getInstance($order->getInternalId());
/** @var SaleShipmentItemCollection $shipmentItemCollection */
$shipmentItemCollection = $shipment->getShipmentItemCollection();
$needShipList = array();
$creator = SaleInternalsProviderCreator::create($context);
/** @var SaleShipmentItem $shipmentItem */
foreach ($shipmentItemCollection as $shipmentItem)
{
$creator->addShipmentItem($shipmentItem);
}
$r = $creator->isNeedShip();
if ($r->isSuccess())
{
$data = $r->getData();
if (array_key_exists('IS_NEED_SHIP', $data))
{
$needShipList = $data['IS_NEED_SHIP'] + $needShipList;
}
}
$creator = SaleInternalsProviderCreator::create($context);
/** @var SaleShipmentItem $shipmentItem */
foreach ($shipmentItemCollection as $shipmentItem)
{
$shipmentProductData = $creator->createItemForShip($shipmentItem, $needShipList);
$creator->addProductData($shipmentProductData);
}
$tryShipProductList = array();
$isIgnoreErrors = false;
$r = $creator->tryShip();
$needSetAfterResult = false;
if ($r->isSuccess())
{
if ($r->hasWarnings())
{
$result->addWarnings($r->getWarnings());
}
else
{
$needSetAfterResult = true;
}
}
else
{
$result->addWarnings($r->getErrors());
if (self::isIgnoreErrors())
{
$isIgnoreErrors = true;
$needSetAfterResult = true;
}
else
{
$result->addErrors($r->getErrors());
}
}
$data = $r->getData();
if (array_key_exists('TRY_SHIP_PRODUCTS_LIST', $data))
{
$tryShipProductList = $data['TRY_SHIP_PRODUCTS_LIST'] + $tryShipProductList;
}
if ($needSetAfterResult && !empty($tryShipProductList))
{
if ($isIgnoreErrors)
{
foreach ($tryShipProductList as &$productList)
{
$productList = array_fill_keys(array_keys($productList), true);
}
}
$creator->setItemsResultAfterTryShip($pool, $tryShipProductList);
}
return $result;
}