• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/providerbase.php
  • Класс: BitrixSaleProviderBase
  • Вызов: ProviderBase::createItemsAfterGetProductData
static function createItemsAfterGetProductData($basketList, array $productDataList, array $select = array())
{
	$resultList = array();
	$basketIndexList = array();
	$basketMap = array();

	if (!is_array($basketList) && !($basketList instanceof BasketBase))
	{
		throw new ArgumentTypeException('basketList');
	}

	/** @var BasketItem $basketItem */
	foreach ($basketList as $basketItem)
	{
		$basketCode = $basketItem->getBasketCode();
		$productId = $basketItem->getProductId();

		$basketIndexList[$productId][] = $basketCode;
		$basketMap[$basketCode] = $basketItem;
	}

	if (empty($productDataList))
	{
		return $resultList;
	}

	foreach ($productDataList as $productId => $productData)
	{
		if (empty($basketIndexList[$productId]))
			continue;

		if (empty($productData))
			continue;

		foreach ($basketIndexList[$productId] as $basketCode)
		{
			if (!empty($productData['PRICE_LIST']) && !empty($productData['PRICE_LIST'][$basketCode]))
			{
				$priceData = $productData['PRICE_LIST'][$basketCode];

				if (array_key_exists('AVAILABLE_QUANTITY', $priceData)
					&& !array_key_exists('QUANTITY', $priceData))
				{
					$priceData['QUANTITY'] = $priceData['AVAILABLE_QUANTITY'];
				}

				/** @var BasketItem $basketItem */
				$basketItem = $basketMap[$basketCode];

				if (in_array('PRICE', $select) || $basketItem->getId() == 0)
				{
					$productData = $priceData + $productData;
				}
				else
				{
					if (isset($priceData['QUANTITY']))
					{
						$productData['QUANTITY'] = $priceData['QUANTITY'];
					}

					if (isset($priceData['AVAILABLE_QUANTITY']))
					{
						$productData['AVAILABLE_QUANTITY'] = $priceData['AVAILABLE_QUANTITY'];
					}

					unset($productData['PRICE_LIST']);
				}
			}

			if (in_array('AVAILABLE_QUANTITY', $select) && isset($productData['AVAILABLE_QUANTITY']))
			{
				$productData['QUANTITY'] = $productData['AVAILABLE_QUANTITY'];
			}

			$resultList[$basketCode] = $productData;
		}
	}

	return $resultList;
}