• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/v2/Section/SectionCollection.php
  • Класс: BitrixCatalogv2SectionSectionCollection
  • Вызов: SectionCollection::setValues
public function setValues(array $values): self
{
	// ToDo recalculate already loaded properties on section modifications?
	$currentValues = $this->getValues();
	$filteredValues = $this->filterValues($values);

	$oldValuesToRemove = array_diff($currentValues, $filteredValues);

	if (!empty($oldValuesToRemove))
	{
		$oldSections = [];

		/** @var BitrixCatalogv2SectionSection $item */
		foreach ($this->getIterator() as $item)
		{
			if (in_array($item->getValue(), $oldValuesToRemove, true))
			{
				$oldSections[] = $item;
			}
		}

		$this->remove(...$oldSections);
	}

	$newValuesToAdd = array_diff($filteredValues, $currentValues);

	if (!empty($newValuesToAdd))
	{
		$newSections = [];

		foreach ($newValuesToAdd as $value)
		{
			$newSections[] = $this
				->factory
				->createEntity()
				->setValue($value)
			;
		}

		$this->add(...$newSections);
	}

	return $this;
}