• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/v2/Sku/SkuRepository.php
  • Класс: BitrixCatalogv2SkuSkuRepository
  • Вызов: SkuRepository::getSkuIteratorEagerLoading
private function getSkuIteratorEagerLoading(BaseProduct $product, array $params = []): Generator
{
	if ($product->isSimple())
	{
		if ($product->getSkuCollection()->isEmpty())
		{
			yield $this->createEntity();
		}
	}
	elseif (!$product->isNew())
	{
		$params['filter']['PROPERTY_' . $this->iblockInfo->getSkuPropertyId()] = $product->getId();
		$params['order']['ID'] = 'DESC';

		$items = [];
		foreach ($this->getList($params) as $item)
		{
			$items[$item['ID']] = $item;
		}

		$skuIds = array_keys($items);

		$propertySettings = $this->propertyRepository->getPropertiesSettingsByFilter([
			'=IBLOCK_ID' => $this->iblockInfo->getSkuIblockId(),
		]);

		$propertyElementMap = $this->getPropertyMapBySkuIds($skuIds, $propertySettings);

		foreach ($items as $skuId => $item)
		{
			$propertyCollection = $this->propertyRepository->createCollection();

			foreach ($propertySettings as $setting)
			{
				if (isset($propertyElementMap[$skuId][$setting['ID']]))
				{
					$propertyItem = $propertyElementMap[$skuId][$setting['ID']];
				}
				else
				{
					$propertyItem = $this->propertyRepository->createEntity([], $setting);
				}

				if ($propertyItem)
				{
					$propertyCollection->add($propertyItem);
				}
			}

			yield $this->createEntity($item, $propertyCollection);
		}
	}
}