• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/discount/preset/basepreset.php
  • Класс: BitrixSaleDiscountPresetBasePreset
  • Вызов: BasePreset::exec
public function exec()
{
	$isPost = $this->request->isPost();

	$stepName = $this->getStepName();
	$state = $this->getState();

	//edit existing discount
	if($stepName === $this->getFirstStepName() && !$isPost && $this->isDiscountEditing())
	{
		$state = $this->generateState($this->discount);
	}

	if($this->isRunningPrevStep())
	{
		$stepName = $state->getPrevStep();
	}

	if($isPost && !$this->isRunningPrevStep())
	{
		/** @var State $state */
		list($state, $nextStep) = $this->runStep($stepName, $state, self::MODE_SAVE);

		if($stepName != $nextStep)
		{
			$state->addStepChain($stepName);
		}

		$this->setNextStep($nextStep);
		if($nextStep === static::FINAL_STEP)
		{
			$discountFields = $this->generateDiscount($state);

			if($this->isDiscountEditing())
			{
				$this->updateDiscount($this->discount['ID'], $discountFields);
			}
			else
			{
				$this->addDiscount($discountFields);
			}

			if($this->hasErrors())
			{
				$stepName = $step = $state->popStepChain();

				$this->setNextStep($step);
			}
		}

		if(!$this->hasErrors())
		{
			$stepName = $nextStep;
		}
	}
	elseif($this->isRunningPrevStep())
	{
		$step = $state->popStepChain();

		$this->setNextStep($step);
	}

	$this->stepResult = $this->runStep($stepName, $state, self::MODE_SHOW);
	$this->stepResultState = $state;

	return $this;
}