• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/v2/Section/SectionRepository.php
  • Класс: BitrixCatalogv2SectionSectionRepository
  • Вызов: SectionRepository::save
public function save(BaseEntity ...$entities): Result
{
	$result = new Result();

	/** @var BitrixCatalogv2ProductBaseProduct $parentEntity */
	$parentEntity = null;
	$sections = [];

	/** @var BitrixCatalogv2SectionSection $section */
	foreach ($entities as $section)
	{
		if ($parentEntity && $parentEntity !== $section->getParent())
		{
			$result->addError(new Error('Saving should only be done with sections of a common parent.'));
		}

		if ($parentEntity === null)
		{
			$parentEntity = $section->getParent();
		}

		$sections[] = $section->getValue();
	}

	if (!$parentEntity)
	{
		$result->addError(new Error('Parent entity not found while saving sections.'));
	}

	if (!($parentEntity instanceof BaseProduct))
	{
		$result->addError(new Error(sprintf(
			'Parent entity of section must be an instance of {%s}.',
			BaseProduct::class
		)));
	}

	if (!empty($sections) && $result->isSuccess())
	{
		CIBlockElement::setElementSection(
			$parentEntity->getId(),
			$sections,
			$parentEntity->isNew(),
			0 // $arIBlock["RIGHTS_MODE"] === "E"? $arIBlock["ID"]: 0
		);
	}

	return $result;
}