• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/component/base.php
  • Класс: BitrixIblockComponentBase
  • Вызов: Base::checkProductSection
protected function checkProductSection($productId, $sectionId = 0, $sectionCode = '')
{
	$successfulAdd = true;
	$errorMsg = '';

	if (!empty($productId) && ($sectionId > 0 || !empty($sectionCode)))
	{
		$productsMap = $this->getProductIdMap([$productId]);

		if (!empty($productsMap[$productId]))
		{
			$sectionId = (int)$sectionId;
			$sectionCode = (string)$sectionCode;

			$filter = ['ID' => $productsMap[$productId]];

			$element = false;
			if ($sectionId > 0)
			{
				$filter['SECTION_ID'] = $sectionId;
				$filter['INCLUDE_SUBSECTIONS'] = 'Y';
				$elementIterator = CIBlockElement::GetList(array(), $filter, false, false, array('ID'));
				$element = $elementIterator->Fetch();
				unset($elementIterator);
			}
			elseif ($sectionCode != '')
			{
				$iblockId = (int)CIBlockElement::GetIBlockByID($productsMap[$productId]);
				if ($iblockId > 0)
				{
					$sectionIterator = CIBlockSection::GetList(
						[],
						['IBLOCK_ID' => $iblockId, '=CODE' => $sectionCode],
						false,
						['ID', 'IBLOCK_ID']
					);
					$section = $sectionIterator->Fetch();
					unset($sectionIterator);
					if (!empty($section))
					{
						$filter['SECTION_ID'] = (int)$section['ID'];
						$filter['INCLUDE_SUBSECTIONS'] = 'Y';
						$elementIterator = CIBlockElement::GetList(array(), $filter, false, false, array('ID'));
						$element = $elementIterator->Fetch();
						unset($elementIterator);
					}
					unset($section);
				}
				unset($iblockId);
			}

			if (empty($element))
			{
				$successfulAdd = false;
				$errorMsg = Loc::getMessage('CATALOG_PRODUCT_NOT_FOUND');
			}
		}
	}

	return [$successfulAdd, $errorMsg];
}