• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/orderbase.php
  • Класс: BitrixSaleOrderBase
  • Вызов: OrderBase::save
public function save()
{
	if ($this->isSaveExecuting)
	{
		trigger_error("Order saving in recursion", E_USER_WARNING);
	}

	$this->isSaveExecuting = true;

	$result = new Result();

	$id = $this->getId();
	$this->isNew = ($id == 0);
	$needUpdateDateInsert = $this->getDateInsert() === null;

	$r = $this->callEventOnBeforeOrderSaved();
	if (!$r->isSuccess())
	{
		$this->isSaveExecuting = false;
		return $r;
	}

	$r = $this->verify();
	if (!$r->isSuccess())
	{
		$result->addWarnings($r->getErrors());
	}

	$r = $this->onBeforeSave();
	if (!$r->isSuccess())
	{
		$this->isSaveExecuting = false;
		return $r;
	}
	elseif ($r->hasWarnings())
	{
		$result->addWarnings($r->getWarnings());
	}

	if ($id > 0)
	{
		$r = $this->update();
	}
	else
	{
		$r = $this->add();
		if ($r->getId() > 0)
		{
			$id = $r->getId();
		}
	}

	if ($r->hasWarnings())
	{
		$result->addWarnings($r->getWarnings());
	}

	if (!$r->isSuccess())
	{
		$this->isSaveExecuting = false;
		return $r;
	}

	if ($id > 0)
	{
		$result->setId($id);
	}

	$this->callEventOnSaleOrderEntitySaved();

	$r = $this->saveEntities();
	if (!$r->isSuccess())
	{
		$result->addWarnings($r->getErrors());
	}

	if ($r->hasWarnings())
	{
		$result->addWarnings($r->getWarnings());
	}

	/** @var Discount $discount */
	$discount = $this->getDiscount();

	/** @var Result $r */
	$r = $discount->save();
	if (!$r->isSuccess())
	{
		$result->addWarnings($r->getErrors());
	}

	$r = $this->completeSaving($needUpdateDateInsert);
	if (!$r->isSuccess())
	{
		$result->addWarnings($r->getErrors());
	}

	$this->callEventOnSaleOrderSaved();
	$this->callDelayedEvents();

	$this->onAfterSave();

	$this->isNew = false;
	$this->isSaveExecuting = false;
	$this->clearChanged();

	return $result;
}