• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/product/catalogprovider.php
  • Класс: BitrixCatalogProductCatalogProvider
  • Вызов: CatalogProvider::getQuantityDataFromStore
static function getQuantityDataFromStore(array $product): array
	{
		$result = [
			'AMOUNT' => [],
			'QUANTITY_RESERVED' => [],
		];

		$storeDataExists = (
			!empty($product['STORE_DATA_LIST'])
			&& is_array($product['STORE_DATA_LIST'])
		);
		$reserveDataExists = (
			!empty($product[self::AMOUNT_SRC_STORE_RESERVED_LIST])
			&& is_array($product[self::AMOUNT_SRC_STORE_RESERVED_LIST])
		);
		if (!$storeDataExists && !$reserveDataExists)
		{
			return $result;
		}

		$found = false;
		if ($storeDataExists)
		{
			foreach ($product['STORE_DATA_LIST'] as $storeList)
			{
				if (!is_array($storeList))
				{
					continue;
				}
				$found = true;
				foreach ($storeList as $storeId => $store)
				{
					if (!isset($result['AMOUNT'][$storeId]))
					{
						$result['AMOUNT'][$storeId] = 0;
					}
					$result['AMOUNT'][$storeId] += (float)$store['QUANTITY'];
					if (isset($store['RESERVED_QUANTITY']))
					{
						if (!isset($result['QUANTITY_RESERVED'][$storeId]))
						{
							$result['QUANTITY_RESERVED'][$storeId] = 0;
						}
						$result['QUANTITY_RESERVED'][$storeId] += (float)$store['RESERVED_QUANTITY'];
					}
				}
			}
		}

		if (!$found && $reserveDataExists)
		{
			switch (self::getQuantityFormat($product[self::AMOUNT_SRC_STORE_RESERVED_LIST]))
			{
				case self::QUANTITY_FORMAT_STORE:
					$internalResult = self::calculateQuantityFromStores($product[self::AMOUNT_SRC_STORE_RESERVED_LIST]);
					break;
				case self::QUANTITY_FORMAT_SHIPMENT:
					$internalResult = self::calculateQuantityFromShipments($product[self::AMOUNT_SRC_STORE_RESERVED_LIST]);
					break;
				default:
					$internalResult = null;
					break;
			}
			if ($internalResult !== null)
			{
				$result['QUANTITY_RESERVED'] = $internalResult;
			}
			unset($internalResult);
		}

		return $result;
	}