• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/product/catalogprovider.php
  • Класс: BitrixCatalogProductCatalogProvider
  • Вызов: CatalogProvider::getPriceDataList
static function getPriceDataList(array $products, array $config): array
	{
		/*
			'IS_ADMIN_SECTION' => $adminSection,
			'USER_ID' => $userId,
			'SITE_ID' => $siteId,
			'CURRENCY' => $currency,
		*/
		$userGroups = self::getUserGroups($config['USER_ID']);

		CCatalogProduct::GetVATDataByIDList(array_keys($products));

		if ($config['IS_ADMIN_SECTION'])
		{
			if ($config['USER_ID'] > 0)
			{
				CCatalogDiscountSave::SetDiscountUserID($config['USER_ID']);
			}
			else
			{
				CCatalogDiscountSave::Disable();
			}
		}

		PriceCalculation::pushConfig();
		PriceCalculation::setConfig([
			'CURRENCY' => $config['CURRENCY'],
			'PRECISION' => (int)MainConfigOption::get('sale', 'value_precision'),
			'RESULT_WITH_VAT' => true,
			'RESULT_MODE' => CatalogProductPriceCalculation::RESULT_MODE_RAW
		]);

		$priceDataList = CCatalogProduct::GetOptimalPriceList(
			$products,
			$userGroups,
			'N',
			[],
			($config['IS_ADMIN_SECTION'] ? $config['SITE_ID'] : false)
		);

		if (empty($priceDataList))
		{
			$productsQuantityList = $products;
			$quantityCorrected = false;

			foreach ($productsQuantityList as $productId => $productData)
			{
				$quantityList = array($productData['BASKET_CODE'] => $productData['QUANTITY']);

				if (empty($productData[Base::FLAT_QUANTITY_LIST]))
				{
					$quantityList = $productData[Base::FLAT_QUANTITY_LIST];
				}

				if (empty($quantityList))
				{
					continue;
				}

				foreach ($quantityList as $basketCode => $quantity)
				{
					$nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productId, $quantity, $userGroups);
					if (!empty($nearestQuantity))
					{
						if (!empty($productData[Base::FLAT_QUANTITY_LIST]))
						{
							$productsQuantityList[$productId][Base::FLAT_QUANTITY_LIST][$basketCode]['QUANTITY'] = $nearestQuantity;
						}
						else
						{
							$productsQuantityList[$productId]['QUANTITY'] = $nearestQuantity;
						}

						$quantityCorrected = true;
					}
				}
			}

			if ($quantityCorrected)
			{
				$priceDataList = CCatalogProduct::GetOptimalPriceList(
					$productsQuantityList,
					$userGroups,
					'N',
					[],
					($config['IS_ADMIN_SECTION'] ? $config['SITE_ID'] : false)
				);
			}

		}

		PriceCalculation::popConfig();

		if ($config['IS_ADMIN_SECTION'])
		{
			if ($config['USER_ID'] > 0)
			{
				CCatalogDiscountSave::ClearDiscountUserID();
			}
			else
			{
				CCatalogDiscountSave::Enable();
			}
		}

		if (!empty($priceDataList))
		{
			foreach ($priceDataList as $productId => $priceBasketDataList)
			{
				foreach ($priceBasketDataList as $basketCode => $priceData)
				{
					if ($priceData === false)
					{
						continue;
					}

					if (empty($priceData['DISCOUNT_LIST']) && !empty($priceData['DISCOUNT']) && is_array($priceData['DISCOUNT']))
					{
						$priceDataList[$productId][$basketCode]['DISCOUNT_LIST'] = [$priceData['DISCOUNT']];
					}

					if (empty($priceData['PRICE']['CATALOG_GROUP_NAME']))
					{
						if (!empty($priceData['PRICE']['CATALOG_GROUP_ID']))
						{
							$priceName = self::getPriceTitle($priceData['PRICE']['CATALOG_GROUP_ID']);
							if ($priceName !== '')
							{
								$priceDataList[$productId][$basketCode]['PRICE']['CATALOG_GROUP_NAME'] = $priceName;
							}
							unset($priceName);
						}
					}
				}
			}
		}

		return $priceDataList;
	}