• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/reservation/availablequantitycalculator.php
  • Класс: BitrixSaleReservationAvailableQuantityCalculator
  • Вызов: AvailableQuantityCalculator::getQuantityForBatch
public function getQuantityForBatch(array $basket2productId): array
{
	$basketItemsStoreQuantity = [];
	$currentStoreProductQuantity = $this->storeProductQuantity;
	$preparedReservationHistory = $this->getPreparedReservationHistory();

	foreach ($preparedReservationHistory as $item)
	{
		$storeId = $item['storeId'];
		$productId = $item['productId'];
		$basketId = $item['basketId'];

		$reservationQuantity = $item['quantity'];
		$storeQuantity = $currentStoreProductQuantity[$storeId][$productId] ?? 0.0;

		$isNeedBasketReservation = isset($basket2productId[$basketId]);
		if ($isNeedBasketReservation)
		{
			if ($storeQuantity > 0)
			{
				$basketItemsStoreQuantity[$basketId][$storeId] ??= 0.0;
				$basketItemsStoreQuantity[$basketId][$storeId] += min($storeQuantity, $reservationQuantity);
			}
		}

		if (isset($currentStoreProductQuantity[$storeId][$productId]))
		{
			$currentStoreProductQuantity[$storeId][$productId] -= $reservationQuantity;
		}
	}

	foreach ($basket2productId as $basketId => $productId)
	{
		foreach ($currentStoreProductQuantity as $storeId => $quantities)
		{
			$storeQuantity = $quantities[$productId] ?? 0.0;
			if ($storeQuantity > 0.0)
			{
				$basketItemsStoreQuantity[$basketId][$storeId] ??= 0.0;
				$basketItemsStoreQuantity[$basketId][$storeId] += $storeQuantity;
			}
		}
	}

	return $basketItemsStoreQuantity;
}