• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/landingsource/dataloader.php
  • Класс: BitrixIblockLandingSourceDataLoader
  • Вызов: DataLoader::loadPrices
private function loadPrices(array &$result)
	{
		$priceTypes = $this->getPriceTypes();
		if (!empty($priceTypes))
		{
			$productIds = array_keys($result);
			$prices = [];
			$priceFilter = [
				'@PRODUCT_ID' => array_keys($result),
				'@CATALOG_GROUP_ID' => $priceTypes,
				[
					'LOGIC' => 'OR',
					'<=QUANTITY_FROM' => 1,
					'=QUANTITY_FROM' => null
				],
				[
					'LOGIC' => 'OR',
					'>=QUANTITY_TO' => 1,
					'=QUANTITY_TO' => null
				]
			];

			$iterator = CatalogPriceTable::getList([
				'select' => ['ID', 'PRODUCT_ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY'],
				'filter' => $priceFilter
			]);

			while ($price = $iterator->fetch())
			{
				$id = (int)$price['PRODUCT_ID'];
				$priceTypeId = (int)$price['CATALOG_GROUP_ID'];
				$prices[$id][$priceTypeId] = $price;
				unset($priceTypeId, $id);
			}
			unset($price, $iterator);

			$calculationConfig = [
				'CURRENCY' => CurrencyCurrencyManager::getBaseCurrency(),
				'USE_DISCOUNTS' => true,
				'RESULT_WITH_VAT' => true,
				'RESULT_MODE' => CatalogProductPriceCalculation::RESULT_MODE_COMPONENT
			];

			if ($this->saleIncluded)
			{
				$saleDiscountOnly = (string)MainConfigOption::get('sale', 'use_sale_discount_only') == 'Y';
				if ($saleDiscountOnly)
					$calculationConfig['PRECISION'] = (int)MainConfigOption::get('sale', 'value_precision');
			}
			CatalogProductPriceCalculation::pushConfig();
			CatalogProductPriceCalculation::setConfig($calculationConfig);
			unset($calculationConfig);

			foreach ($productIds as $id)
			{
				$minimalPrice = CCatalogProduct::GetOptimalPrice(
					$id,
					1,
					[2],
					'N',
					$prices[$id],
					false,
					[]
				);
				$result[$id]['SORT_ORDER'] = 0;
				if (!empty($minimalPrice))
				{
					$minimalPrice = $minimalPrice['RESULT_PRICE'];
					$result[$id]['PRICE'] = CCurrencyLang::CurrencyFormat(
						$minimalPrice['DISCOUNT_PRICE'],
						$minimalPrice['CURRENCY'],
						true
					);
					if ($minimalPrice['BASE_PRICE'] > $minimalPrice['DISCOUNT_PRICE'])
					{
						$result[$id]['PRICE'] .= ' '.
							CCurrencyLang::CurrencyFormat(
								$minimalPrice['BASE_PRICE'],
								$minimalPrice['CURRENCY'],
								true
							).
							'';
					}
					$result[$id]['SORT_ORDER'] = $minimalPrice['DISCOUNT_PRICE'];
				}
				unset($minimalPrice);
			}

			CatalogProductPriceCalculation::popConfig();
		}
		unset($priceTypes);
	}