- Модуль: catalog
- Путь к файлу: ~/bitrix/modules/catalog/lib/v2/Property/PropertyRepository.php
- Класс: BitrixCatalogv2PropertyPropertyRepository
- Вызов: PropertyRepository::save
public function save(BaseEntity ...$entities): Result
{
$result = new Result();
/** @var BitrixCatalogv2BaseIblockElementEntity $parentEntity */
$parentEntity = null;
$props = [];
/** @var BitrixCatalogv2PropertyProperty $property */
foreach ($entities as $property)
{
if ($parentEntity && $parentEntity !== $property->getParent())
{
$result->addError(new Error('Saving should only be done with properties of a common parent.'));
}
if ($parentEntity === null)
{
$parentEntity = $property->getParent();
}
$valueCollection = $property->getPropertyValueCollection();
$props[$property->getId()] = $valueCollection->toArray();
if ($property->getPropertyType() === PropertyTable::TYPE_FILE)
{
foreach ($props[$property->getId()] as $id => $prop)
{
if (is_numeric($id))
{
$props[$property->getId()][$id] = CIBlock::makeFilePropArray(
$prop,
$prop['VALUE'] === '',
$prop['DESCRIPTION'],
['allow_file_id' => true]
);
}
}
foreach ($valueCollection->getRemovedItems() as $removed)
{
if ($removed->isNew())
{
continue;
}
$fieldsToDelete = CIBlock::makeFilePropArray($removed->getFields(), true);
$props[$property->getId()][$removed->getId()] = $fieldsToDelete;
}
}
}
if (!$parentEntity)
{
$result->addError(new Error('Parent entity not found while saving properties.'));
}
if (!($parentEntity instanceof BaseIblockElementEntity))
{
$result->addError(new Error(sprintf(
'Parent entity of property must be an instance of {%s}.',
BaseIblockElementEntity::class
)));
}
if (!empty($props) && $result->isSuccess())
{
$element = new CIBlockElement();
$res = $element->update($parentEntity->getId(), [
'PROPERTY_VALUES' => $props,
]);
if (!$res)
{
$result->addError(new Error($element->LAST_ERROR));
}
}
return $result;
}