• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/component/elementlist.php
  • Класс: BitrixIblockComponentElementList
  • Вызов: ElementList::editTemplateItems
protected function editTemplateItems(&$items)
{
	$enableCompatible = $this->isEnableCompatible();
	foreach ($items as $key => &$item)
	{
		$iblockParams = $this->storage['IBLOCK_PARAMS'][$item['IBLOCK_ID']];

		if (!isset($item['CATALOG_QUANTITY']))
		{
			$item['CATALOG_QUANTITY'] = 0;
		}

		$item['CATALOG_QUANTITY'] = $item['CATALOG_QUANTITY'] > 0 && is_float($item['ITEM_MEASURE_RATIOS'][$item['ITEM_MEASURE_RATIO_SELECTED']]['RATIO'])
			? (float)$item['CATALOG_QUANTITY']
			: (int)$item['CATALOG_QUANTITY'];

		$item['CATALOG'] = false;
		$item['CATALOG_SUBSCRIPTION'] = ($item['CATALOG_SUBSCRIPTION'] ?? '') === 'Y' ? 'Y' : 'N';

		$item['BIG_DATA'] = $this->getAction() === 'bigDataLoad';

		CIBlockPriceTools::getLabel($item, $iblockParams['LABEL_PROP']);
		$item['LABEL_PROP_MOBILE'] = $iblockParams['LABEL_PROP_MOBILE'];
		$item['PROPERTY_CODE_MOBILE'] = $iblockParams['PROPERTY_CODE_MOBILE'];
		static::checkEnlargedData($item, $iblockParams['ENLARGE_PROP']);

		if ($this->arParams['SHOW_SLIDER'] === 'Y')
		{
			$this->editTemplateProductSlider($item, $item['IBLOCK_ID'], 5, true, array($this->arResult['DEFAULT_PICTURE']));
		}

		$this->editTemplateProductPictures($item);
		$this->editTemplateCatalogInfo($item);

		if ($item['CATALOG'] && !empty($item['OFFERS']))
		{
			if ($this->arParams['PRODUCT_DISPLAY_MODE'] === 'Y')
			{
				$this->editTemplateOfferProps($item);
				$this->editTemplateJsOffers($item);
			}

			if ($this->arParams['CALCULATE_SKU_MIN_PRICE'] || $this->arParams['PRODUCT_DISPLAY_MODE'] !== 'Y')
			{
				$baseCurrency = '';
				if ($this->arResult['MODULES']['catalog'] && !isset($this->arResult['CONVERT_CURRENCY']['CURRENCY_ID']))
				{
					$baseCurrency = CurrencyCurrencyManager::getBaseCurrency();
				}

				$currency = $this->arResult['CONVERT_CURRENCY']['CURRENCY_ID'] ?? $baseCurrency;

				$item['ITEM_START_PRICE'] = null;
				$item['ITEM_START_PRICE_SELECTED'] = null;
				if ($enableCompatible)
					$item['MIN_PRICE'] = false;

				$minPrice = null;
				$minPriceIndex = null;
				foreach (array_keys($item['OFFERS']) as $index)
				{
					if (!$item['OFFERS'][$index]['CAN_BUY'] || $item['OFFERS'][$index]['ITEM_PRICE_SELECTED'] === null)
						continue;

					$currentPrice = $item['OFFERS'][$index]['ITEM_PRICES'][$item['OFFERS'][$index]['ITEM_PRICE_SELECTED']];
					if ($currentPrice['CURRENCY'] != $currency)
					{
						$priceScale = CCurrencyRates::ConvertCurrency(
							$currentPrice['RATIO_PRICE'],
							$currentPrice['CURRENCY'],
							$currency
						);
					}
					else
					{
						$priceScale = $currentPrice['RATIO_PRICE'];
					}
					if ($minPrice === null || $minPrice > $priceScale)
					{
						$minPrice = $priceScale;
						$minPriceIndex = $index;
					}
					unset($priceScale, $currentPrice);
				}
				unset($index);

				if ($minPriceIndex !== null)
				{
					$minOffer = $item['OFFERS'][$minPriceIndex];
					$item['ITEM_START_PRICE_SELECTED'] = $minPriceIndex;
					$item['ITEM_START_PRICE'] = $minOffer['ITEM_PRICES'][$minOffer['ITEM_PRICE_SELECTED']];
					if ($enableCompatible)
					{
						$item['MIN_PRICE'] = array(
							'CATALOG_MEASURE_RATIO' => $minOffer['ITEM_MEASURE_RATIOS'][$minOffer['ITEM_MEASURE_RATIO_SELECTED']]['RATIO'],
							'CATALOG_MEASURE' => $minOffer['ITEM_MEASURE']['ID'],
							'CATALOG_MEASURE_NAME' => $minOffer['ITEM_MEASURE']['TITLE'],
							'~CATALOG_MEASURE_NAME' => $minOffer['ITEM_MEASURE']['~TITLE'],
							'VALUE' => $item['ITEM_START_PRICE']['RATIO_BASE_PRICE'],
							'DISCOUNT_VALUE' => $item['ITEM_START_PRICE']['RATIO_PRICE'],
							'PRINT_VALUE' => $item['ITEM_START_PRICE']['PRINT_RATIO_BASE_PRICE'],
							'PRINT_DISCOUNT_VALUE' => $item['ITEM_START_PRICE']['PRINT_RATIO_PRICE'],
							'DISCOUNT_DIFF' => $item['ITEM_START_PRICE']['RATIO_DISCOUNT'],
							'PRINT_DISCOUNT_DIFF' => $item['ITEM_START_PRICE']['PRINT_RATIO_DISCOUNT'],
							'DISCOUNT_DIFF_PERCENT' => $item['ITEM_START_PRICE']['PERCENT'],
							'CURRENCY' => $item['ITEM_START_PRICE']['CURRENCY']
						);
					}
					unset($minOffer);
				}
				unset($minPriceIndex, $minPrice);

				unset($baseCurrency, $currency);
			}
		}

		if (
			$this->arResult['MODULES']['catalog']
			&& $item['CATALOG']
			&& (
				$item['CATALOG_TYPE'] == CatalogProductTable::TYPE_PRODUCT
				|| $item['CATALOG_TYPE'] == CatalogProductTable::TYPE_SET
			)
		)
		{
			if ($enableCompatible)
			{
				if ($item['ITEM_PRICE_SELECTED'] === null)
				{
					$item['RATIO_PRICE'] = null;
					$item['MIN_BASIS_PRICE'] = null;
				}
				else
				{
					$itemPrice = $item['ITEM_PRICES'][$item['ITEM_PRICE_SELECTED']];
					$item['RATIO_PRICE'] = array(
						'VALUE' => $itemPrice['RATIO_BASE_PRICE'],
						'DISCOUNT_VALUE' => $itemPrice['RATIO_PRICE'],
						'PRINT_VALUE' => $itemPrice['PRINT_RATIO_BASE_PRICE'],
						'PRINT_DISCOUNT_VALUE' => $itemPrice['PRINT_RATIO_PRICE'],
						'DISCOUNT_DIFF' => $itemPrice['RATIO_DISCOUNT'],
						'PRINT_DISCOUNT_DIFF' => $itemPrice['PRINT_RATIO_DISCOUNT'],
						'DISCOUNT_DIFF_PERCENT' => $itemPrice['PERCENT'],
						'CURRENCY' => $itemPrice['CURRENCY']
					);
					$item['MIN_BASIS_PRICE'] = array(
						'VALUE' => $itemPrice['BASE_PRICE'],
						'DISCOUNT_VALUE' => $itemPrice['PRICE'],
						'PRINT_VALUE' => $itemPrice['PRINT_BASE_PRICE'],
						'PRINT_DISCOUNT_VALUE' => $itemPrice['PRINT_PRICE'],
						'DISCOUNT_DIFF' => $itemPrice['DISCOUNT'],
						'PRINT_DISCOUNT_DIFF' => $itemPrice['PRINT_DISCOUNT'],
						'DISCOUNT_DIFF_PERCENT' => $itemPrice['PERCENT'],
						'CURRENCY' => $itemPrice['CURRENCY']
					);
					unset($itemPrice);
				}
			}
		}

		if (!empty($item['DISPLAY_PROPERTIES']))
		{
			foreach ($item['DISPLAY_PROPERTIES'] as $propKey => $displayProp)
			{
				{
					if ($displayProp['PROPERTY_TYPE'] === 'F')
					{
						unset($item['DISPLAY_PROPERTIES'][$propKey]);
					}
				}
			}
		}

		$item['LAST_ELEMENT'] = 'N';
	}

	end($items);
	$items[key($items)]['LAST_ELEMENT'] = 'Y';
}