- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/internals/transferproviderbase.php
- Класс: BitrixSaleInternalsTransferProviderBase
- Вызов: TransferProviderBase::reserve
public function reserve(array $products);
/**
* @param array $products
*
* @return SaleResult
* @throws MainSystemException
*/
abstract public function deliver(array $products);
/**
* @param array $products
*
* @return SaleResult
* @throws MainSystemException
*/
abstract public function viewProduct(array $products);
/**
* @param array $products
*
* @return SaleResult
* @throws MainSystemException
*/
abstract public function getProductListStores(array $products);
/**
* @param PoolQuantity $pool
* @param array $products
* @param array $productTryShipList
*
* @return SaleResult
* @throws MainObjectNotFoundException
*/
abstract public function setItemsResultAfterTryShip(PoolQuantity $pool, array $products, array $productTryShipList);
/**
* @param array $products
* @param SaleResult $resultAfterShip
*
* @return SaleResult
* @throws MainObjectNotFoundException
*/
public function setItemsResultAfterShip(array $products, SaleResult $resultAfterShip)
{
$result = new SaleResult();
$needReverse = false;
$shippedProductList = array();
$resultData = $resultAfterShip->getData();
if (!empty($resultData['SHIPPED_PRODUCTS_LIST']))
{
$shippedProductList = $resultData['SHIPPED_PRODUCTS_LIST'];
foreach ($shippedProductList as $isShipped)
{
if ($isShipped === false)
{
$needReverse = true;
break;
}
}
}
$shipmentList = array();
$productIndex = array();
foreach ($products as $productId => $itemData)
{
if (!empty($itemData['SHIPMENT_ITEM_LIST']))
{
/** @var SaleShipmentItem $shipmentItem */
foreach ($itemData['SHIPMENT_ITEM_LIST'] as $shipmentItemIndex => $shipmentItem)
{
$basketItem = $shipmentItem->getBasketItem();
$shipment = $shipmentItem->getCollection()->getShipment();
if (isset($itemData['NEED_RESERVE_BY_STORE_LIST'][$shipmentItemIndex]))
{
$needReverseByStore = $itemData['NEED_RESERVE_BY_STORE_LIST'][$shipmentItemIndex];
foreach ($needReverseByStore as $storeId => $isNeeded)
{
/** @var SaleReserveQuantityCollection $reserveQuantityCollection */
$reserveQuantityCollection = $basketItem->getReserveQuantityCollection();
if (
$isNeeded
&& $reserveQuantityCollection
&& $shipment->needShip() !== CatalogProvider::SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_NOT_SHIP)
{
/** @var SaleReserveQuantity $reserve */
foreach ($reserveQuantityCollection as $reserve)
{
if ($reserve->getStoreId() !== $storeId)
{
continue;
}
if (isset($itemData['STORE_DATA_LIST'][$shipmentItemIndex][$storeId]))
{
$reserveQuantity = $itemData['STORE_DATA_LIST'][$shipmentItemIndex][$storeId]['RESERVED_QUANTITY'];
}
else
{
$reserveQuantity = $shipmentItem->getQuantity();
}
if ($reserve->getQuantity() > $reserveQuantity)
{
$reserve->setFieldNoDemand('QUANTITY', $reserve->getQuantity() - $reserveQuantity);
}
else
{
$reserve->deleteNoDemand();
}
}
}
}
if ($shipment->needShip() !== CatalogProvider::SALE_TRANSFER_PROVIDER_SHIPMENT_NEED_NOT_SHIP)
{
$shipmentItem->getFields()->set('RESERVED_QUANTITY', 0);
}
}
$shipmentIndex = $shipment->getInternalIndex();
if (!array_key_exists($shipmentIndex, $shipmentList))
{
$shipmentList[$shipmentIndex] = $shipment;
}
if (
!isset($productIndex[$shipmentIndex][$shipmentItemIndex])
|| !in_array($productId, $productIndex[$shipmentIndex][$shipmentItemIndex])
)
{
$productIndex[$shipmentIndex][$shipmentItemIndex] = $productId;
}
}
}
}
$reverseProducts = array();
if ($needReverse && !empty($productIndex))
{
foreach ($productIndex as $productList)
{
foreach ($productList as $productId)
{
$isExistsProduct = array_key_exists($productId, $shippedProductList);
if (
$isExistsProduct
&& $shippedProductList[$productId] === true
&& empty($reverseProducts[$productId])
)
{
$reverseProducts[$productId] = $products[$productId];
$reverseProducts[$productId]['QUANTITY'] *= -1;
}
}
}
}
if (!empty($reverseProducts))
{
$r = $this->ship($reverseProducts);
}
return $result;
}