33 throw new \OutOfRangeException($id);
42 return reset($entities) ?:
null;
50 foreach ($this->
getList((array)$params) as $item)
67 foreach ($entities as $section)
69 if ($parentEntity && $parentEntity !== $section->getParent())
71 $result->addError(
new Error(
'Saving should only be done with sections of a common parent.'));
74 if ($parentEntity ===
null)
76 $parentEntity = $section->getParent();
79 $sections[] = $section->getValue();
84 $result->addError(
new Error(
'Parent entity not found while saving sections.'));
87 if (!($parentEntity instanceof BaseProduct))
89 $result->addError(
new Error(sprintf(
90 'Parent entity of section must be an instance of {%s}.',
95 if (!empty($sections) && $result->isSuccess())
97 \CIBlockElement::setElementSection(
98 $parentEntity->getId(),
100 $parentEntity->isNew(),
116 if ($product->
isNew())
130 $sectionIdsIterator = \CIBlockElement::getElementGroups(
135 while ($section = $sectionIdsIterator->fetch())
138 'VALUE' => (int)$section[
'ID'],
146 protected function getList(array $params): array
153 $entity = $this->factory->createEntity();
162 $collection = $this->factory->createCollection();
164 foreach ($entityFields as $fields)
167 $collection->add($section);