• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/grid/productaction.php
  • Класс: BitrixCatalogGridProductAction
  • Вызов: ProductAction::updateSectionList
static function updateSectionList(int $iblockId, array $sections, array $fields): MainResult
{
	$result = new MainResult();

	if ($iblockId <= 0)
	{
		$result->addError(new MainError(
			Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_IBLOCK_ID')
		));
		return $result;
	}

	$catalog = CCatalogSku::GetInfoByIBlock($iblockId);
	if (empty($catalog))
	{
		$result->addError(new MainError(
			Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_CATALOG')
		));
		return $result;
	}

	if (empty($fields))
	{
		$result->addError(new MainError(
			Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_EMPTY_FIELDS')
		));
		return $result;
	}

	$filter = [];
	$allowedTypes = static::getAllowedProductTypes($catalog, $fields);
	if (empty($allowedTypes))
	{
		$result->addError(new MainError(
			Loc::getMessage('BX_CATALOG_PRODUCT_ACTION_ERR_BAD_FIELDS')
		));
		return $result;
	}
	$filter['@TYPE'] = $allowedTypes;
	unset($allowedTypes);

	$sectionElements = self::getSectionProducts($iblockId, $sections, $filter);
	if (empty($sectionElements))
	{
		return $result;
	}

	$sectionIdList = array_keys($sectionElements);
	$sectionNames = [];
	$iterator = IblockSectionTable::getList([
		'select' => [
			'ID',
			'NAME',
		],
		'filter' => [
			'@ID' => $sectionIdList,
			'=IBLOCK_ID' => $iblockId,
		],
		'order' => ['ID' => 'ASC'],
	]);
	while ($row = $iterator->fetch())
	{
		$row['ID'] = (int)$row['ID'];
		$sectionNames[$row['ID']] = $row['NAME'];
	}
	unset($row, $iterator);

	foreach ($sectionIdList as $sectionId)
	{
		$elementResult = static::updateElementList(
			$iblockId,
			$sectionElements[$sectionId],
			$fields
		);
		if (!$elementResult->isSuccess())
		{
			$result->addError(new MainError(
				Loc::getMessage(
					'BX_CATALOG_PRODUCT_ACTION_ERR_SECTION_PRODUCTS_UPDATE',
					['#ID#' => $sectionId, '#NAME#' => $sectionNames[$sectionId]]
				),
				$sectionId
			));
		}
	}
	unset($sectionId);
	unset($sectionNames, $sectionIdList, $sectionElements);

	return $result;
}