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

	if (!(isset($USER) && $USER instanceof CUser))
	{
		return null;
	}

	if (!AccessController::getCurrent()->check(ActionDictionary::ACTION_PRODUCT_EDIT))
	{
		return null;
	}

	if ($iblockId <= 0)
	{
		return null;
	}
	MainTypeCollection::normalizeArrayValuesByInt($sections, false);
	if (empty($sections))
	{
		return null;
	}

	$filter['IBLOCK_ID'] = $iblockId;
	$filter['INCLUDE_SUBSECTIONS'] = 'Y';
	$filter['CHECK_PERMISSIONS'] = 'Y';
	$filter['MIN_PERMISSION'] = 'R';

	$dublicates = [];
	$result = [];
	foreach ($sections as $sectionId)
	{
		$result[$sectionId] = [];
		$elements = [];
		$filter['SECTION_ID'] = $sectionId;
		$iterator = CIBlockElement::GetList(
			['ID' => 'ASC'],
			$filter,
			false,
			false,
			['ID']
		);
		while ($row = $iterator->fetch())
		{
			$id = (int)$row['ID'];
			if (isset($dublicates[$id]))
			{
				continue;
			}
			$dublicates[$id] = true;
			$elements[] = $id;
		}
		unset($id, $row, $iterator);

		if (!empty($elements))
		{
			$operations = CIBlockElementRights::UserHasRightTo(
				$iblockId,
				$elements,
				'',
				CIBlockRights::RETURN_OPERATIONS
			);
			foreach ($elements as $elementId)
			{
				if (
					isset($operations[$elementId]['element_edit'])
					&& isset($operations[$elementId]['element_edit_price'])
				)
				{
					$result[$sectionId][] = $elementId;
				}
			}
			unset($elementId);
			unset($operations);
		}
		unset($elements);

		if (empty($result[$sectionId]))
		{
			unset($result[$sectionId]);
		}
	}
	unset($sectionId);
	unset($dublicates);

	return (!empty($result) ? $result : null);
}