ProductRow::normalizeDiscountForPercentage

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. ProductRow
  4. normalizeDiscountForPercentage
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/productrow.php
  • Класс: Bitrix\Crm\ProductRow
  • Вызов: ProductRow::normalizeDiscountForPercentage
protected function normalizeDiscountForPercentage(Result $result): void
{
	if (is_null($this->getDiscountRate()))
	{
		$result->addError(new Error(
			'Discount Rate (DISCOUNT_RATE) is required if '
			. "Percentage Discount Type (DISCOUNT_TYPE_ID) is used. ID = {$this->getId()}",
			static::ERROR_CODE_NORMALIZATION_DISCOUNT_RATE_REQUIRED,
		));

		return;
	}

	if ($this->getDiscountRate() === 100.0)
	{
		$discountSum = $this->getDiscountSum();
		if ($discountSum === 0.0 || is_null($discountSum))
		{
			// impossible to calculate discount sum, since price with 100% discount is exactly zero
			$result->addError(new Error(
				'Discount Sum (DISCOUNT_SUM) is required if '
				. 'Percentage Discount Type (DISCOUNT_TYPE_ID) is used and Discount Rate (DISCOUNT_RATE) is 100%. '
				. "ID = {$this->getId()}",
				static::ERROR_CODE_NORMALIZATION_DISCOUNT_SUM_REQUIRED,
			));

			return;
		}
	}
	else
	{
		$discountSum = Discount::calculateDiscountSum($this->getPriceExclusive(), $this->getDiscountRate());
	}

	$this->setDiscountSum($discountSum);
}

Добавить комментарий