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

	/** @var BitrixCatalogv2PriceBasePrice $entity */
	foreach ($entities as $entity)
	{
		if (!$entity->hasPrice())
		{
			if (!$entity->isNew())
			{
				$res = $this->deleteInternal($entity->getId());

				if ($res->isSuccess())
				{
					$entity->setField('ID', null);
				}
				else
				{
					$result->addErrors($res->getErrors());
				}
			}

			continue;
		}

		if (!$entity->getProductId())
		{
			$productId = $this->getProductId($entity);

			if ($productId)
			{
				$entity->setProductId($productId);
			}
			else
			{
				$result->addError(new Error('Wrong product id'));
				continue;
			}
		}

		if ($entityId = $entity->getId())
		{
			$res = $this->updateInternal($entityId, $entity->getChangedFields());

			if (!$res->isSuccess())
			{
				$result->addErrors($res->getErrors());
			}
		}
		else
		{
			$res = $this->addInternal($entity->getFields());

			if ($res->isSuccess())
			{
				$entity->setId($res->getData()['ID']);
			}
			else
			{
				$result->addErrors($res->getErrors());
			}
		}
	}

	return $result;
}