• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/tradebindingentity.php
  • Класс: BitrixSaleTradeBindingEntity
  • Вызов: TradeBindingEntity::save
public function save()
{
	$result = new Result();

	if (!$this->isChanged())
	{
		return $result;
	}

	$id = $this->getId();

	if ($id > 0)
	{
		$fields = $this->getFields()->getChangedValues();
		$r = $this->updateInternal($id, $fields);
		$result->setId($r->getId());
	}
	else
	{
		/** @var TradeBindingCollection $collection */
		$collection = $this->getCollection();

		/** @var Order $order */
		$order = $collection->getOrder();

		$this->setFieldNoDemand('ORDER_ID', $order->getId());

		if ((int)$this->getField('EXTERNAL_ORDER_ID') <= 0)
		{
			$this->setFieldNoDemand('EXTERNAL_ORDER_ID', $order->getId());
		}

		$fields = $this->getFields()->getValues();
		$r = $this->addInternal($fields);
		if ($r->isSuccess())
		{
			$id = $r->getId();
			$this->setFieldNoDemand('ID', $id);
		}
	}

	if (!$r->isSuccess())
	{
		$result->addErrors($r->getErrors());
		return $result;
	}

	$result->setId($id);

	return $result;
}