• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/Reservation/AvailableQuantityCalculator.php
  • Класс: Bitrix\Crm\Reservation\AvailableQuantityCalculator
  • Вызов: AvailableQuantityCalculator::getAvailableQuantities
public function getAvailableQuantities(): array
{
	if (empty($this->newProductRowProducts) && empty($this->productRows))
	{
		return [];
	}

	$result = [];

	// first, the quantity from the basket, to account for the history of reserves
	$basketItemsQuantity = $this->getBasketItemsAvailableQuantity($this->productRows);
	if (!empty($basketItemsQuantity))
	{
		$result += $basketItemsQuantity;
	}

	// adding the products rows for which there are no basket items
	$products = $this->newProductRowProducts;
	foreach ($this->productRows as $data)
	{
		$productId = $data['productId'];
		$storeId = $data['storeId'];

		if (!isset($result[$productId][$storeId]))
		{
			$products[$productId][$storeId] ??= 0;
			$products[$productId][$storeId] += $data['needQuantity'];
		}
	}

	$productsQuantity = $this->getProductsAvailableQuantity($products);
	if (!empty($productsQuantity))
	{
		$result += $productsQuantity;
	}

	return $result;
}