• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/helpers/controller/action/entity/order.php
  • Класс: BitrixSaleHelpersControllerActionEntityOrder
  • Вызов: Order::getCatalogProduct
static function getCatalogProduct(array $basketItemData): array
{
	$result = [];

	$repositoryFacade = Catalogv2IoCServiceContainer::getRepositoryFacade();
	$product = $repositoryFacade->loadVariation($basketItemData['PRODUCT_ID']);
	if ($product)
	{
		$result = $product->getFields();

		$result['TYPE'] = ($result['TYPE'] === CatalogProductTable::TYPE_SERVICE) ? 'service' : 'product';

		$result['PREVIEW_PICTURE'] ??= null;
		if ((int)$result['PREVIEW_PICTURE'] > 0)
		{
			$result['PREVIEW_PICTURE_SRC'] = CFile::GetPath($result['PREVIEW_PICTURE']);
		}

		$result['DETAIL_PICTURE'] ??= null;
		if ((int)$result['DETAIL_PICTURE'] > 0)
		{
			$result['DETAIL_PICTURE_SRC'] = CFile::GetPath($result['DETAIL_PICTURE']);
		}

		$result['AVAILABLE_QUANTITY'] = $result['QUANTITY'];
		unset($result['QUANTITY']);

		if ($result['QUANTITY_TRACE'] === CatalogProductTable::STATUS_DEFAULT)
		{
			$result['QUANTITY_TRACE'] = (MainConfigOption::get('catalog', 'default_quantity_trace') === 'Y') ? 'Y' : 'N';
		}
		if ($result['CAN_BUY_ZERO'] === CatalogProductTable::STATUS_DEFAULT)
		{
			$result['CAN_BUY_ZERO'] = (MainConfigOption::get('catalog', 'default_can_buy_zero') === 'Y') ? 'Y' : 'N';
		}

		$checkMaxQuantity = ($result['QUANTITY_TRACE'] === 'Y' && $result['CAN_BUY_ZERO'] === 'N') ? 'Y' : 'N';
		$result['CHECK_MAX_QUANTITY'] = $checkMaxQuantity;

		$result['RATIO'] = 1;
		$ratioItem = $product->getMeasureRatioCollection()->findDefault();
		if (!$ratioItem)
		{
			$ratioItem = $product->getMeasureRatioCollection()->getFirst();
		}

		if ($ratioItem)
		{
			$result['RATIO'] = $ratioItem->getRatio();
		}

		/** @var Catalogv2PropertyPropertyCollection|Catalogv2PropertyProperty[] $propertyCollection */
		$propertyCollection = $product->getPropertyCollection();
		foreach ($propertyCollection as $propertyItem)
		{
			$values = $propertyItem->getPropertyValueCollection()->getValues();

			if ($propertyItem->getPropertyType() === IblockPropertyTable::TYPE_LIST)
			{
				$enumPropData = IblockPropertyEnumerationTable::getList([
					'select' => ['ID', 'VALUE', 'SORT', 'XML_ID'],
					'filter' => [
						'=ID' => $values,
						'=PROPERTY_ID' => $propertyItem->getId(),
					],
				])->fetchAll();

				if ($enumPropData)
				{
					if (!$propertyItem->isMultiple())
					{
						$values = reset($enumPropData);
					}
				}
				else
				{
					$values = null;
				}
			}
			elseif ($propertyItem->getPropertyType() === IblockPropertyTable::TYPE_FILE)
			{
				$imageSrcValues = null;
				if ($propertyItem->isMultiple())
				{
					$imageSrcValues = [];
					foreach ($values as $value)
					{
						$imageSrcValues[] = [
							'FILE_ID' => $value,
							'SRC' => CFile::GetPath($value),
						];
					}
				}
				else
				{
					$imageSrcValues = [
						'FILE_ID' => $values,
						'SRC' => CFile::GetPath($values),
					];
				}

				$values = $imageSrcValues;
			}

			$result['PRODUCT_PROPERTIES'][$propertyItem->getId()] = [
				'TYPE' => $propertyItem->getPropertyType(),
				'CODE' => $propertyItem->getCode(),
				'NAME' => $propertyItem->getName(),
				'VALUES' => $values,
			];
		}

		/** @var Catalogv2ImageImageCollection|Catalogv2ImageBaseImage[] $imageCollection */
		$imageCollection = $product->getImageCollection();
		$frontImage = $imageCollection->getFrontImage();

		$frontImageData = null;
		if ($frontImage)
		{
			$frontImageData = $frontImage->getFields();
		}
		else
		{
			/** @var Catalogv2ProductProduct $parent */
			$parent = $product->getParent();
			if ($parent)
			{
				$imageCollection = $parent->getImageCollection();
				$parentFrontImage = $imageCollection->getFrontImage();
				if ($parentFrontImage)
				{
					$frontImageData = $parentFrontImage->getFields();
				}
			}
		}

		$result['FRONT_IMAGE'] = $frontImageData;

		$result['IMAGE_COLLECTION'] = [];
		foreach ($imageCollection as $imageItem)
		{
			$result['IMAGE_COLLECTION'][] = $imageItem->getFields();
		}

		$result['SKU'] = self::getSkuTree($product->getIblockId(), $product->getId());
	}

	return $result;
}