• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/discountbase.php
  • Класс: BitrixSaleDiscountBase
  • Вызов: DiscountBase::executeDiscountList
protected function executeDiscountList()
{
	$result = new Result;

	$roundApply = true;
	$saleDiscountOnly = $this->useOnlySaleDiscounts();
	$useMode = $this->getUseMode();
	if ($saleDiscountOnly)
	{
		if ($useMode == self::USE_MODE_FULL && $this->isRoundMode(self::ROUND_MODE_SALE_DISCOUNT))
			$roundApply = false;
	}

	$this->discountIds = array();
	if (empty($this->saleDiscountCacheKey) || empty($this->saleDiscountCache[$this->saleDiscountCacheKey]))
	{
		if (!$roundApply)
		{
			$this->roundFullBasketPriceByIndex(array(
				'DISCOUNT_INDEX' => -1,
				'DISCOUNT_ID' => 0
			));
		}
		return $result;
	}

	$currentList = $this->saleDiscountCache[$this->saleDiscountCacheKey];
	$this->discountIds = array_keys($currentList);
	$this->extendOrderData();

	DiscountActions::clearAction();

	$blackList = array(
		self::getExecuteFieldName('UNPACK') => true,
		self::getExecuteFieldName('APPLICATION') => true,
		self::getExecuteFieldName('PREDICTIONS_APP') => true
	);

	$index = -1;
	$skipPriorityLevel = null;
	foreach ($currentList as $discountIndex => $discount)
	{
		if($skipPriorityLevel == $discount['PRIORITY'])
		{
			continue;
		}
		$skipPriorityLevel = null;

		$this->fillCurrentStep(array(
			'discount' => $discount,
			'cacheIndex' => $discountIndex
		));
		if (!$this->checkDiscountConditions())
			continue;

		$index++;
		if (!$roundApply && $discount['EXECUTE_MODULE'] == 'sale')
		{
			$this->roundFullBasketPriceByIndex(array(
				'DISCOUNT_INDEX' => $index,
				'DISCOUNT_ID' => $discount['ID']
			));
			$roundApply = true;
		}

		if ($useMode == self::USE_MODE_FULL && !isset($this->fullDiscountList[$discount['ID']]))
			$this->fullDiscountList[$discount['ID']] = array_diff_key($discount, $blackList);

		$actionsResult = $this->applySaleDiscount();
		if (!$actionsResult->isSuccess())
		{
			$result->addErrors($actionsResult->getErrors());
			unset($actionsResult);
			return $result;
		}

		if ($this->currentStep['stop'])
			break;

		if (isset($this->currentStep['stopLevel']) && $this->currentStep['stopLevel'])
		{
			$skipPriorityLevel = $discount['PRIORITY'];
		}
	}
	unset($discount, $currentList);
	$this->fillEmptyCurrentStep();

	if (!$roundApply)
	{
		$index++;
		$this->roundFullBasketPriceByIndex(array(
			'DISCOUNT_INDEX' => $index,
			'DISCOUNT_ID' => 0
		));
	}

	return $result;
}