• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/helpers/admin/product.php
  • Класс: BitrixSaleHelpersAdminProduct
  • Вызов: Product::fillIblockData
private function fillIblockData()
{
	$select = array("ID", "NAME", "IBLOCK_ID", "IBLOCK_SECTION_ID", "DETAIL_PICTURE", "PREVIEW_PICTURE", "XML_ID", "IBLOCK_EXTERNAL_ID");
	$blockedFields = array(
		'QUANTITY' => true,
		'AVAILABLE' => true,
		'PRICE' => true
	);
	foreach ($this->columnsList as $field)
	{
		if (isset($blockedFields[$field]))
			continue;
		$select[] = $field;
	}

	if (!empty($this->productsIds))
	{
		$parentList = CCatalogSku::getProductList($this->productsIds);
		if (!is_array($parentList))
			$parentList = array();
		$simpleProducts = array();
		foreach ($this->productsIds as $id)
		{
			if (isset($parentList[$id]))
			{
				$info = $parentList[$id];

				$this->resultData[$id] = array(
					"PRODUCT_ID" => $info["ID"],
					"IBLOCK_ID" => $info["IBLOCK_ID"],
					"OFFERS_IBLOCK_ID" => $info["OFFER_IBLOCK_ID"]
				);
				$this->parentsIds[] = $info["ID"];

				if(!isset($this->groupByIblock[$info['OFFER_IBLOCK_ID']]))
					$this->groupByIblock[$info['OFFER_IBLOCK_ID']] = array();

				$this->groupByIblock[$info['OFFER_IBLOCK_ID']][] = $id;

				if(!isset($this->groupByIblock[$info['IBLOCK_ID']]))
					$this->groupByIblock[$info['IBLOCK_ID']] = array();

				$this->groupByIblock[$info['IBLOCK_ID']][] = $info["ID"];

				unset($info);
			}
			else
			{
				$simpleProducts[$id] = $id;
			}
		}
		unset($id);
		unset($parentList);

		if (!empty($simpleProducts))
		{
			$simpleIblock = CIBlockElement::GetIBlockByIDList($simpleProducts);
			foreach ($simpleIblock as $id => $iblockId)
			{
				$this->resultData[$id] = array(
					"PRODUCT_ID" => $id,
					"IBLOCK_ID" => $iblockId,
					"OFFERS_IBLOCK_ID" => 0
				);

				if(!isset($this->groupByIblock[$iblockId]))
					$this->groupByIblock[$iblockId] = array();

				$this->groupByIblock[$iblockId][] = $id;
			}
			unset($id, $iblockId, $simpleIblock);
		}
		unset($simpleProducts);
	}

	$this->iblockData = array();
	$ppData = getProductProps(array_merge($this->productsIds, $this->parentsIds), $select);

	foreach($ppData as $id => $fields)
	{
		if(empty($ppData[$id]))
			continue;

		foreach($fields as $k => $v)
			if(mb_substr($k, 0, 1) == '~')
				$fields[mb_substr($k, 1)] = $v;

		$this->iblockData[$id] = $ppData[$id];
		$this->iblockData[$id]["PRODUCT_PROPS_VALUES"] = $this->createProductPropsValues($id);

		if(!in_array($id, $this->productsIds))
			continue;

		$this->resultData[$id] = array_merge(
			$this->resultData[$id],
			array_intersect_key(
				$this->iblockData[$id],
				array_flip(
					$this->columnsList
		)));

		$this->resultData[$id]["OFFER_ID"] = $id;
		$this->resultData[$id]["NAME"] = $fields["NAME"];
		$this->resultData[$id]["PRODUCT_XML_ID"] = $fields["XML_ID"];
		$this->resultData[$id]["CATALOG_XML_ID"] = $fields["~IBLOCK_EXTERNAL_ID"];
		$this->resultData[$id]["PRODUCT_PROPS_VALUES"] = $this->iblockData[$id]["PRODUCT_PROPS_VALUES"];
		$this->resultData[$id]['EDIT_PAGE_URL'] = $this->createEditPageUrl($fields);
	}

	$notFound = array_diff($this->productsIds, array_keys($this->iblockData));

	if(!empty($notFound))
	{
		foreach($notFound as $id)
		{
			unset($this->resultData[$id]);
			unset(
				$this->productsIds[
					array_search(
						$id,
						$this->productsIds
					)
				]
			);
		}
	}
	return;
}