• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/product/catalogprovider.php
  • Класс: BitrixCatalogProductCatalogProvider
  • Вызов: CatalogProvider::getStoreAmountFromSource
static function getStoreAmountFromSource(array $product, array $sourceList): ?array
	{
		if (empty($product) || empty($sourceList))
		{
			return null;
		}

		$result = [];
		$found = false;
		foreach ($sourceList as $source)
		{
			switch ($source)
			{
				case self::AMOUNT_SRC_STORE_QUANTITY_LIST:
				case self::AMOUNT_SRC_STORE_RESERVED_LIST:
					if (
						!empty($product[$source])
						&& is_array($product[$source])
					)
					{
						switch (self::getQuantityFormat($product[$source]))
						{
							case self::QUANTITY_FORMAT_STORE:
								$internalResult = self::calculateQuantityFromStores($product[$source]);
								break;
							case self::QUANTITY_FORMAT_SHIPMENT:
								$internalResult = self::calculateQuantityFromShipments($product[$source]);
								break;
							default:
								$internalResult = null;
								break;
						}
						if ($internalResult !== null)
						{
							$result = $internalResult;
							$found = true;
						}
						unset($internalResult);
					}
					break;
				case self::AMOUNT_SRC_QUANTITY_LIST:
				case self::AMOUNT_SRC_RESERVED_LIST:
					/*
					'QUANTITY_LIST' =>
						array (
							289 => 1.0,
							290 => 3.0,
							291 => 4.0,
						),
					 */
					if (
						!empty($product[$source])
						&& is_array($product[$source])
					)
					{
						$result[static::getDefaultStoreId()] = array_sum($product[$source]);
						$found = true;
					}
					break;
				case self::AMOUNT_SRC_QUANTITY:
					if (array_key_exists($source, $product))
					{
						$result[static::getDefaultStoreId()] = (float)$product[$source];
						$found = true;
					}
					break;
			}
			if ($found)
			{
				break;
			}
		}

		return (!empty($result) ? $result : null);
	}