Bitrix-D7  20.5.0
Класс DiscountBase
Граф наследования:DiscountBase:
Discount

Открытые члены

 __destruct ()
 
 createClone (\SplObjectStorage $cloneEntity)
 Clone entity. Подробнее...
 
 isClone ()
 Returns true if discount entity is cloned. Подробнее...
 
 setOrderRefresh ($state)
 Set full refresh status from edit order form. Подробнее...
 
 isOrderRefresh ()
 Returns full refresh status value. Подробнее...
 
 isOrderNew ()
 Returns new order flag value. Подробнее...
 
 setUseMode ($useMode)
 Set calculate mode. Подробнее...
 
 getUseMode ()
 Return calculate mode. Подробнее...
 
 setExecuteModuleFilter (array $moduleList)
 Sets list of execute module which will be used to filter discount. Подробнее...
 
 calculate ()
 Calculate discounts. Подробнее...
 
 setApplyResult ($applyResult)
 Change applied discount list. Подробнее...
 
 getApplyResult ($extMode=false)
 Return discount list description. Подробнее...
 
 verify ()
 Verifies discounts before order save. Подробнее...
 
 save ()
 Save discount result. Подробнее...
 
 isValidState ()
 
 getOrder ()
 Return order. Подробнее...
 
 isOrderExists ()
 Return flag is order exists. Подробнее...
 
 getShowPrices ()
 Returns show prices for public components. Подробнее...
 

Открытые статические члены

static buildFromOrder (OrderBase $order)
 Builds discounts from order. Подробнее...
 
static buildFromBasket (BasketBase $basket, Context\BaseContext $context)
 Builds discounts from basket. Подробнее...
 
static setOrder (BasketBase $basket)
 Get discount by order basket. Подробнее...
 
static getApplyModeList ($extendedMode=false)
 Return apply mode list. Подробнее...
 
static getApplyMode ()
 Returns current sale discount apply mode. Подробнее...
 
static getRegistryType ()
 Return parent entity type. Подробнее...
 
static getEmptyApplyBlock ()
 Return empty apply block. Подробнее...
 
static calculateDiscountPercent ($basePrice, $discount)
 Calculate discount percent for public components. Подробнее...
 

Поля данных

const EVENT_EXTEND_ORDER_DATA = 'onExtendOrderData'
 
const USE_MODE_FULL = 0x00001
 
const USE_MODE_APPLY = 0x0002
 
const USE_MODE_MIXED = 0x0004
 
const USE_MODE_COUPONS = 0x0008
 
const EXECUTE_FIELD_PREFIX = 'EXECUTE_'
 
const ERROR_ID = 'BX_SALE_DISCOUNT'
 
const APPLY_MODE_ADD = 0x0001
 
const APPLY_MODE_DISABLE = 0x0002
 
const APPLY_MODE_LAST = 0x0004
 
const APPLY_MODE_FULL_DISABLE = 0x0008
 
const APPLY_MODE_FULL_LAST = 0x0010
 
const ROUND_MODE_BASKET_DISCOUNT = 0x0001
 
const ROUND_MODE_SALE_DISCOUNT = 0x0002
 
const ROUND_MODE_FINAL_PRICE = 0x0004
 
const ENTITY_BASKET_ITEM = 'BASKET_ITEM'
 
const ENTITY_DELIVERY = 'DELIVERY'
 
const ENTITY_ORDER = 'ORDER'
 

Защищенные члены

 __construct ()
 
 setNewOrder ()
 Set new order flag. Подробнее...
 
 isLoaded ()
 Returns true if the data for calculations is loaded. Подробнее...
 
 setValidState ($value)
 
 initInstanceData ()
 Initial instance data. Подробнее...
 
 initInstanceFromOrder ()
 Initial instance data after set order. Подробнее...
 
 stopCalculate ()
 Return is allow discount calculate. Подробнее...
 
 useOnlySaleDiscounts ()
 Return true, if only sale discounts is allowed. Подробнее...
 
 getBasket ()
 Return current basket. Подробнее...
 
 isBasketExist ()
 Return exists basket. Подробнее...
 
 isBasketNotEmpty ()
 Returns the existence of a non-empty basket. Подробнее...
 
 initUseMode ()
 Initialization of the discount calculation mode. Подробнее...
 
 loadOrderData ()
 Load order information. Подробнее...
 
 fillEmptyOrderData ()
 Fill empty order data. Подробнее...
 
 loadBasket ()
 Get basket data from owner entity. Подробнее...
 
 getBasketItemFields (BasketItemBase $basketItem)
 Returns array with basket item field values. Подробнее...
 
 loadOrderConfig ()
 Load order config for exists order. Подробнее...
 
 getModuleSettings ()
 Returns the current module settings required for calculating discounts. Подробнее...
 
 loadDefaultOrderConfig ()
 Load default order config for order. Подробнее...
 
 validateLoadedOrderConfig ($config)
 Validate loaded order config. Подробнее...
 
 applyLoadedOrderConfig (array $data)
 Set loaded order settings. Подробнее...
 
 loadOrderDiscounts ()
 Load discounts for exists order. Подробнее...
 
 loadBasketStoredData ()
 Load basket stored data for order. Подробнее...
 
 getBasketItemValue ($code, $field)
 Return basket item data value from provider. Подробнее...
 
 getBasketItemValueList ($code, array $fields)
 Return basket item data from provider. Подробнее...
 
 calculateFull ()
 Calculate discount by new order. Подробнее...
 
 calculateApply ()
 Calculate discount by exist order. Подробнее...
 
 calculateMixed ()
 Calculate discount by exist order with new items. Подробнее...
 
 saveFull ()
 Save discount result for new order. Подробнее...
 
 getOrderConfig ()
 Returns order configuration for save to database. Подробнее...
 
 saveBasketStoredData (array $basketCodeList)
 Save basket items stored data. Подробнее...
 
 saveApply ()
 Save discount result for exist order. Подробнее...
 
 saveMixed ()
 Save discount result for mixed order. Подробнее...
 
 saveCoupons ()
 Save coupons for order. Подробнее...
 
 saveLastApplyBlock ()
 Save result last apply block discount. Подробнее...
 
 normalizeNewResultRows (array &$rows)
 Fill common system fields for new discount results. Подробнее...
 
 checkDiscountConditions ()
 Check duscount conditions. Подробнее...
 
 applySaleDiscount ()
 Apply discount rules. Подробнее...
 
 checkBasketDiscounts ()
 Check product discount list for basket items. Подробнее...
 
 calculateFullBasketDiscount ()
 Apply basket discount in new order. Подробнее...
 
 calculateApplyBasketDiscount ()
 Apply basket discount in exist order. Подробнее...
 
 calculateApplyDiscountBlock ()
 Calculate discount block for existing order. Подробнее...
 
 calculateApplyAdditionalCoupons ()
 Applyed additional coupons. Подробнее...
 
 calculateFullSaleDiscountResult ()
 Calculate step discount result by new order. Подробнее...
 
 tryToRevertApplyStatusInBlocks (array $stepResult)
 Tries to revert apply status of discounts. Подробнее...
 
 revertApplyBlockForBasketItem ($basketItemId)
 Reverts apply flag in blocks for basket items which has for example cumulative discount which cancels previous discounts on item. Подробнее...
 
 calculateApplySaleDiscountResult ()
 Calculate step discount result by exist order. Подробнее...
 
 getRoundMode ()
 Return order round apply mode. Подробнее...
 
 isRoundMode ($mode)
 Return true, if selected check round apply mode. Подробнее...
 
 loadRoundConfig ()
 Load round apply config for exist order. Подробнее...
 
 setRoundIndex ($entity, array $index)
 Set discount index for use round. Подробнее...
 
 getRoundIndex ($entity, $applyCounter=null)
 Return index data for use round. Подробнее...
 
 roundFullBasketPrices ()
 Round prices. Подробнее...
 
 roundApplyBasketPrices ()
 Round prices. Подробнее...
 
 roundChangedBasketPrices ()
 Round only changed prices. Подробнее...
 
 roundFullBasketPriceByIndex (array $index)
 Round prices in sale discount mode for new order. Подробнее...
 
 roundApplyBasketPricesByIndex (array $index)
 Round prices in sale discount mode for exist order. Подробнее...
 
 convertDiscount ($discount)
 Convert discount for saving in order. Подробнее...
 
 convertCoupon ($coupon, $discount)
 Convert coupon for saving in order. Подробнее...
 
 correctStepResult (&$stepResult, $discount)
 Correct data for exotic coupon. Подробнее...
 
 setDiscountStoredActionData ($orderDiscountId, array $data)
 Fill additional discount data. Подробнее...
 
 getDiscountStoredActionData ($orderDiscountId)
 Returns stored action data for discount. Подробнее...
 
 isBasketApplyResultExist ()
 Return true, if exist apply result from form for basket. Подробнее...
 
 getApplyDiscounts ()
 Returns discount and coupon list. Подробнее...
 
 getApplyPrices ()
 Fill prices in apply results. Подробнее...
 
 remakingDiscountResult ()
 Change result format. Подробнее...
 
 getBasketTables ()
 Create correspondence between basket ids and basket codes. Подробнее...
 
 getEntitySaveIdentifier (array $entity)
 Returns data for save to database. Подробнее...
 
 isCustomPriceByCode ($code)
 Returns exist custom price for basket item code. Подробнее...
 
 isInSetByCode ($code)
 Returns check item in set for basket item code. Подробнее...
 
 isNewBasketItemByCode ($code)
 Returns check new basket item for basket item code. Подробнее...
 
 isFreezedBasketItemByCode ($code)
 Returns true, if allowed apply discounts to basket item. Подробнее...
 
 isBasketItemChanged ($code)
 Return true if ordered basket item changed (change PRODUCT_ID). Подробнее...
 
 isExistBasketItem ($code)
 Return true, if basket item exists. Подробнее...
 
 isOrderChanged ()
 Returns true, if changed children order entities. Подробнее...
 
 isMixedBasket ()
 Returns exist new item in basket. Подробнее...
 
 isOrderedBasketChanged ()
 Return true if basket saved order changed (change PRODUCT_ID). Подробнее...
 
 getBasketCodes ($full=true)
 Returns basket codes for calculate. Подробнее...
 
 getAllowedBasketCodeList ()
 
 mergeDiscountActionResult ($index, $stepResult)
 Merge discount actions result with old data. Подробнее...
 
 fillEmptyDiscountResult ()
 Fill empty discount result list. Подробнее...
 
 fillDiscountResult ()
 Fill result order data. Подробнее...
 
 clearCurrentApplyBlock ()
 Internal. Подробнее...
 
 fillEmptyCurrentStep ()
 Internal. Подробнее...
 
 fillCurrentStep ($data)
 Internal. Подробнее...
 
 extendOrderData ()
 Extend order data for discounts. Подробнее...
 
 modifyOrderData (&$newData)
 Modify order data from handlers. Подробнее...
 
 resetOrderState ()
 Set order parameters to their original state before the start of calculations. Подробнее...
 
 resetPrices ()
 Fill prices from base prices. Подробнее...
 
 resetBasketPrices ()
 Fill basket prices from base prices. Подробнее...
 
 resetDiscountAppliedFlag ()
 Reset flag of applying discounts for basket items. Подробнее...
 
 executeDiscountList ()
 Execute sale discount list. Подробнее...
 
 fillBasketLastDiscount ()
 Fill last discount flag for basket items. Подробнее...
 
 isBasketLastDiscount ()
 Check last discount flag for basket items. Подробнее...
 
 clearAdditionalCoupons (array $coupons)
 Clear coupons from already used discounts. Подробнее...
 
 getAdditionalCoupons (array $filter=array())
 Return additional coupons for exist order. Подробнее...
 
 calculateApplyBasketAdditionalCoupons (array $applyCoupons)
 Calculate additional basket coupons. Подробнее...
 
 calculateApplySaleAdditionalCoupons (array $applyCoupons)
 Calculate additional sale coupons. Подробнее...
 
 getStatusApplyBasketDiscount ($basketCode, $orderDiscountId, $orderCouponId)
 Return apply status for basket discount. Подробнее...
 
 normalizeDiscountResult ()
 Round and correct discount calculation results. Подробнее...
 
 getSiteId ()
 Return site id for calculate. Подробнее...
 
 getCurrency ()
 Return order currency for calculate. Подробнее...
 
 getSiteCurrency ()
 Return site currency. Подробнее...
 
 getExecuteFieldList ()
 Return field list for eval. Подробнее...
 
 getConditionField ()
 Return field with discount condition code. Подробнее...
 
 loadDiscountByUserGroups (array $filter=array())
 Load from database discount id for user groups. Подробнее...
 
 loadDiscountModules (array $modules)
 Load discount modules. Подробнее...
 
 loadDiscountList ()
 Load sale discount from database. Подробнее...
 
 getOrderDiscountClassName ()
 Returns current order discount class name. Подробнее...
 
 getDiscountCouponClassName ()
 Returns current discount coupons manager class name. Подробнее...
 
 getShipmentClassName ()
 Return current shipment class name. Подробнее...
 

Защищенные статические члены

static getStepResult (array $order)
 Returns result after one discount. Подробнее...
 
static isCustomPrice (array $item)
 Returns exist custom price for basket item. Подробнее...
 
static isInSet (array $item)
 Returns check item in set for basket item. Подробнее...
 
static isNewBasketItem (array $item)
 Returns check new basket item for basket item. Подробнее...
 
static isFreezedBasketItem (array $item)
 Returns true, if allowed apply discounts to basket item. Подробнее...
 
static formatDescription ($descr)
 Return formatted discount description. Подробнее...
 
static instanceExists ($index)
 Returns true, if instance exist. Подробнее...
 
static getInstance ($index)
 Returns discount instance. Подробнее...
 
static migrateInstance ($oldIndex, $newIndex)
 
static removeInstance ($index)
 
static getInstanceIndexByOrder (OrderBase $order)
 Return instance index for order. Подробнее...
 
static getInstanceIndexByBasket (BasketBase $basket, Context\BaseContext $context=null)
 Return instance index for basket. Подробнее...
 
static getExecuteFieldName ($fieldName)
 Return field name for save eval result. Подробнее...
 
static getOrderPropertyCodes ()
 Return order property codes for translate to order fields. Подробнее...
 
static recursiveMerge (&$dest, $src)
 Added keys from source array to destination array. Подробнее...
 

Защищенные данные

 $isClone = false
 
 $orderRefresh = false
 
 $newOrder = null
 
 $useMode = null
 
 $context
 
 $order = null
 
 $executeModuleFilter = array('all', 'sale', 'catalog')
 
 $loadedModules = array()
 
 $discountIds = null
 
 $saleDiscountCache = array()
 
 $saleDiscountCacheKey = ''
 
 $basket = null
 
 $orderData = null
 
 $valid = true
 
 $saleOptions = array()
 
 $basketDiscountList = array()
 
 $basketItemsData = array()
 
 $discountsCache = array()
 
 $couponsCache = array()
 
 $discountResult = array()
 
 $discountResultCounter = 0
 
 $applyResult = array()
 
 $discountStoredActionData = array()
 
 $entityList = array()
 
 $entityResultCache = array()
 
 $currentStep = array()
 
 $forwardBasketTable = array()
 
 $reverseBasketTable = array()
 
 $roundApplyMode = self::ROUND_MODE_FINAL_PRICE
 
 $roundApplyConfig = array()
 
 $fullDiscountList = array()
 

Подробное описание

См. определение в файле discountbase.php строка 19

Конструктор(ы)

◆ __construct()

__construct ( )
protected

См. определение в файле discountbase.php строка 143

144  {
145 
146  }

◆ __destruct()

__destruct ( )

См. определение в файле discountbase.php строка 148

149  {
150 
151  }

Методы

◆ applyLoadedOrderConfig()

applyLoadedOrderConfig ( array  $data)
protected

Set loaded order settings.

Аргументы
array$dataOrder settings from database.
Возвращает
void

Переопределяется в Discount.

См. определение в файле discountbase.php строка 1076

1077  {
1078  if (!empty($data['OPTIONS']) && is_array($data['OPTIONS']))
1079  {
1080  foreach (array_keys($this->saleOptions) as $key)
1081  {
1082  if (isset($data['OPTIONS'][$key]))
1083  $this->saleOptions[$key] = $data['OPTIONS'][$key];
1084  }
1085  unset($key);
1086  }
1087  }

◆ applySaleDiscount()

applySaleDiscount ( )
protected

Apply discount rules.

Возвращает
Result

См. определение в файле discountbase.php строка 2180

2181  {
2182  $result = new Result;
2183 
2185 
2186  $discount = (
2187  isset($this->currentStep['discountIndex'])
2188  ? $this->discountsCache[$this->currentStep['discountId']]
2189  : $this->currentStep['discount']
2190  );
2191  if (isset($this->currentStep['discountIndex']))
2192  {
2193  if (!empty($discount['APPLICATION']) && !$this->loadDiscountModules($this->discountsCache[$this->currentStep['discountId']]['MODULES']))
2194  {
2195  $discount['APPLICATION'] = null;
2196  $result->addError(new Main\Entity\EntityError(
2197  Loc::getMessage('BX_SALE_DISCOUNT_ERR_SALE_DISCOUNT_MODULES_ABSENT'),
2198  self::ERROR_ID
2199  ));
2200  }
2201  }
2202 
2203  if (!empty($discount['APPLICATION']))
2204  {
2205  $executeKey = self::getExecuteFieldName('APPLICATION');
2206  if (!array_key_exists($executeKey, $discount))
2207  {
2208  $discount[$executeKey] = null;
2209 
2210  $evalCode = '$discount["'.$executeKey.'"] = '.$discount['APPLICATION'].';';
2211  if (PHP_MAJOR_VERSION >= 7)
2212  {
2213  try
2214  {
2215  eval($evalCode);
2216  }
2217  catch (\ParseError $e)
2218  {
2219  $this->showAdminError();
2220  }
2221  }
2222  else
2223  {
2224  eval($evalCode);
2225  }
2226  unset($evalCode);
2227  }
2228  if (is_callable($discount[$executeKey]))
2229  {
2230  $currentUseMode = $this->getUseMode();
2231  $this->currentStep['oldData'] = $this->orderData;
2232  if (
2233  $currentUseMode == self::USE_MODE_APPLY
2234  || $currentUseMode == self::USE_MODE_MIXED
2235  )
2236  {
2237  $discountStoredActionData = $this->getDiscountStoredActionData($this->currentStep['discountId']);
2238  if (!empty($discountStoredActionData) && is_array($discountStoredActionData))
2241  }
2242  $discount[$executeKey]($this->orderData);
2243  switch ($currentUseMode)
2244  {
2246  case self::USE_MODE_FULL:
2247  $actionsResult = $this->calculateFullSaleDiscountResult();
2248  break;
2249  case self::USE_MODE_APPLY:
2250  case self::USE_MODE_MIXED:
2251  $actionsResult = $this->calculateApplySaleDiscountResult();
2252  break;
2253  default:
2254  $actionsResult = new Result;
2255 
2256  }
2257  if (!$actionsResult->isSuccess())
2258  $result->addErrors($actionsResult->getErrors());
2259  unset($actionsResult);
2260  unset($currentUseMode);
2261  }
2262  }
2263  unset($discount);
2265 
2266  return $result;
2267  }
static getMessage($code, $replace=null, $language=null)
Returns translation by message code.
Definition: loc.php:29
static clearApplyCounter()
Clear apply counter.
static clearAction()
Clear actions description and result.
static setStoredData(array $data)
Fill data to store for discount.
calculateApplySaleDiscountResult()
Calculate step discount result by exist order.
static getExecuteFieldName($fieldName)
Return field name for save eval result.
loadDiscountModules(array $modules)
Load discount modules.
calculateFullSaleDiscountResult()
Calculate step discount result by new order.
getDiscountStoredActionData($orderDiscountId)
Returns stored action data for discount.
getUseMode()
Return calculate mode.

◆ buildFromBasket()

static buildFromBasket ( BasketBase  $basket,
Context\BaseContext  $context 
)
static

Builds discounts from basket.

Basket doesn't have to have a order. Context describes user and user groups which use in

Аргументы
BasketBase$basketBasket.
Context\BaseContext$contextContext.
Возвращает
DiscountBase|null
Исключения
Main

См. определение в файле discountbase.php строка 288

289  {
290  if ($basket->getOrder())
291  {
292  throw new Main\InvalidOperationException(
293  'Could not build discounts from basket which has the order. You have to use buildFromOrder.'
294  );
295  }
296 
297  if ($basket->count() == 0)
298  return null;
299 
300  $instanceIndex = static::getInstanceIndexByBasket($basket, $context);
301  $discount = static::getInstance($instanceIndex);
302  $discount->basket = $basket;
303  $discount->context = $context;
304  $discount->initInstanceData();
305  unset($discount);
306 
307  return static::getInstance($instanceIndex);
308  }

◆ buildFromOrder()

static buildFromOrder ( OrderBase  $order)
static

Builds discounts from order.

Аргументы
OrderBase$orderOrder object.
Возвращает
DiscountBase

См. определение в файле discountbase.php строка 263

264  {
265  $instanceIndex = static::getInstanceIndexByOrder($order);
266  if (!static::instanceExists($instanceIndex))
267  {
268  /** @var DiscountBase $discount */
269  $discount = static::getInstance($instanceIndex);
270  $discount->order = $order;
271  $discount->context = new Context\User($order->getUserId());
272  $discount->initInstanceData();
273  unset($discount);
274  }
275  return static::getInstance($instanceIndex);
276  }

◆ calculate()

calculate ( )

Calculate discounts.

Возвращает
Result

См. определение в файле discountbase.php строка 435

436  {
437  /** @var Result $result */
438  $result = new Result;
439  $process = true;
440 
441  if ($this->stopCalculate())
442  return $result;
443 
444  $this->discountsCache = array();
445  $this->couponsCache = array();
446 
447  if (Compatible\DiscountCompatibility::isUsed())
448  return $result;
449 
450  $this->initUseMode();
451 
452  /** @var DiscountCouponsManager $couponClassName */
453  $couponClassName = $this->getDiscountCouponClassName();
454  if ($this->isOrderExists() && !$this->isOrderNew())
455  {
456  if ($this->isOrderRefresh())
457  {
458  $this->setApplyResult(array());
459  $couponClassName::useSavedCouponsForApply(true);
460  }
461  }
462 
463  $this->orderData = null;
464  $orderResult = $this->loadOrderData();
465  if (!$orderResult->isSuccess())
466  {
467  $process = false;
468  $result->addErrors($orderResult->getErrors());
469  }
470  unset($orderResult);
471 
472  if (!$this->isValidState())
473  return $result;
474 
475  if ($process)
476  {
477  $couponClassName::setUseOnlySaleDiscounts($this->useOnlySaleDiscounts());
478  unset($couponClassName);
479 
480  $this->resetOrderState();
481  switch ($this->getUseMode())
482  {
484  $calculateResult = $this->calculateApply();
485  break;
487  $calculateResult = $this->calculateMixed();
488  break;
489  case self::USE_MODE_FULL:
490  $calculateResult = $this->calculateFull();
491  break;
492  default:
493  $calculateResult = new Result;
494  $calculateResult->addError(new Main\Entity\EntityError(
495  Loc::getMessage('BX_SALE_DISCOUNT_ERR_BAD_USE_MODE'),
496  self::ERROR_ID
497  ));
498  break;
499  }
500  if (!$calculateResult->isSuccess())
501  $result->addErrors($calculateResult->getErrors());
502  else
503  $result->setData($this->fillDiscountResult());
504  unset($calculateResult);
505  }
506 
507  return $result;
508  }
static isUsed()
Check used compatible calculate.
calculateApply()
Calculate discount by exist order.
initUseMode()
Initialization of the discount calculation mode.
loadOrderData()
Load order information.
fillDiscountResult()
Fill result order data.
useOnlySaleDiscounts()
Return true, if only sale discounts is allowed.
setApplyResult($applyResult)
Change applied discount list.
isOrderRefresh()
Returns full refresh status value.
isOrderNew()
Returns new order flag value.
calculateMixed()
Calculate discount by exist order with new items.
resetOrderState()
Set order parameters to their original state before the start of calculations.
getDiscountCouponClassName()
Returns current discount coupons manager class name.
isOrderExists()
Return flag is order exists.
stopCalculate()
Return is allow discount calculate.
calculateFull()
Calculate discount by new order.

◆ calculateApply()

calculateApply ( )
protected

Calculate discount by exist order.

Возвращает
Result

См. определение в файле discountbase.php строка 1343

1344  {
1345  $result = new Result;
1346  if (!$this->isOrderExists())
1347  return $result;
1348 
1349  if (!$this->isValidState())
1350  return $result;
1351 
1352  if (!empty($this->discountResult['APPLY_BLOCKS']))
1353  {
1355  Discount\Actions::MODE_MANUAL,
1356  array(
1357  'USE_BASE_PRICE' => $this->saleOptions['USE_BASE_PRICE'],
1358  'SITE_ID' => $this->orderData['SITE_ID'],
1359  'CURRENCY' => $this->orderData['CURRENCY']
1360  )
1361  );
1362 
1363  $currentCounter = $this->discountResultCounter;
1364 
1365  foreach (array_keys($this->discountResult['APPLY_BLOCKS']) as $counter)
1366  {
1367  $this->discountResultCounter = $counter;
1368  $blockResult = $this->calculateApplyDiscountBlock();
1369  if (!$blockResult->isSuccess())
1370  {
1371  $result->addErrors($blockResult->getErrors());
1372  unset($blockResult);
1373 
1374  return $result;
1375  }
1376  unset($blockResult);
1377  }
1378 
1379  $this->discountResultCounter = $currentCounter;
1380  unset($currentCounter);
1381  }
1382 
1383  if ($result->isSuccess())
1384  {
1386  Discount\Actions::MODE_CALCULATE,
1387  array(
1388  'USE_BASE_PRICE' => $this->saleOptions['USE_BASE_PRICE'],
1389  'SITE_ID' => $this->orderData['SITE_ID'],
1390  'CURRENCY' => $this->orderData['CURRENCY']
1391  )
1392  );
1393 
1394  $this->clearCurrentApplyBlock();
1395 
1396  $couponsResult = $this->calculateApplyAdditionalCoupons();
1397  if (!$couponsResult->isSuccess())
1398  {
1399  $result->addErrors($couponsResult->getErrors());
1400  unset($couponsResult);
1401  return $result;
1402  }
1403  unset($couponsResult);
1404 
1405  if ($this->isRoundMode(self::ROUND_MODE_FINAL_PRICE))
1406  $this->roundChangedBasketPrices();
1407  }
1408 
1409  return $result;
1410  }
static setUseMode($mode, array $config=array())
Set use actions mode.
calculateApplyAdditionalCoupons()
Applyed additional coupons.
roundChangedBasketPrices()
Round only changed prices.
calculateApplyDiscountBlock()
Calculate discount block for existing order.
isRoundMode($mode)
Return true, if selected check round apply mode.

◆ calculateApplyAdditionalCoupons()

calculateApplyAdditionalCoupons ( )
protected

Applyed additional coupons.

Возвращает
Result

См. определение в файле discountbase.php строка 2675

2676  {
2677  $result = new Result;
2678 
2679  $useMode = $this->getUseMode();
2680  if ($useMode != self::USE_MODE_APPLY && $useMode != self::USE_MODE_MIXED)
2681  return $result;
2682 
2683  if (!$this->useOnlySaleDiscounts())
2684  {
2685  $couponList = $this->getAdditionalCoupons(array('!MODULE_ID' => 'sale'));
2686  if (!empty($couponList))
2687  {
2688  $params = array(
2689  'USE_BASE_PRICE' => $this->saleOptions['USE_BASE_PRICE'],
2690  'USER_ID' => $this->orderData['USER_ID'],
2691  'SITE_ID' => $this->orderData['SITE_ID']
2692  );
2693  $couponsByModule = array();
2694  foreach ($couponList as &$coupon)
2695  {
2696  if (!isset($couponsByModule[$coupon['MODULE_ID']]))
2697  $couponsByModule[$coupon['MODULE_ID']] = array();
2698  $couponsByModule[$coupon['MODULE_ID']][] = array(
2699  'DISCOUNT_ID' => $coupon['DISCOUNT_ID'],
2700  'COUPON' => $coupon['COUPON']
2701  );
2702  }
2703  unset($coupon);
2704  if (!empty($couponsByModule))
2705  {
2706  /** @var OrderDiscount $storageClassName */
2707  $storageClassName = $this->getOrderDiscountClassName();
2708  foreach ($couponsByModule as $moduleId => $moduleCoupons)
2709  {
2710  if ($useMode == self::USE_MODE_APPLY)
2711  {
2712  $currentBasket = $this->orderData['BASKET_ITEMS'];
2713  }
2714  else
2715  {
2716  $currentBasket = array();
2717  $basketCodeList = $this->getBasketCodes(false);
2718  foreach ($basketCodeList as $basketCode)
2719  $currentBasket[$basketCode] = $this->orderData['BASKET_ITEMS'][$basketCode];
2720  unset($basketCode, $basketCodeList);
2721  }
2722  if (empty($currentBasket))
2723  continue;
2724  $couponsApply = $storageClassName::calculateApplyCoupons(
2725  $moduleId,
2726  $moduleCoupons,
2727  $currentBasket,
2728  $params
2729  );
2730  unset($currentBasket);
2731  if (!empty($couponsApply))
2732  {
2733  $couponsApplyResult = $this->calculateApplyBasketAdditionalCoupons($couponsApply);
2734  if (!$couponsApplyResult->isSuccess())
2735  $result->addErrors($couponsApplyResult->getErrors());
2736  unset($couponsApplyResult);
2737  }
2738  unset($couponsApply);
2739  }
2740  unset($moduleId, $moduleCoupons);
2741  }
2742  unset($couponsByModule, $params);
2743  }
2744  unset($couponList);
2745  }
2746 
2747  $couponList = $this->getAdditionalCoupons(array('MODULE_ID' => 'sale'));
2748  if (!empty($couponList))
2749  {
2750  $couponsApplyResult = $this->calculateApplySaleAdditionalCoupons($couponList);
2751  if (!$couponsApplyResult->isSuccess())
2752  $result->addErrors($couponsApplyResult->getErrors());
2753  unset($couponsApplyResult);
2754  }
2755  unset($couponList);
2756 
2757  return $result;
2758  }
getOrderDiscountClassName()
Returns current order discount class name.
calculateApplyBasketAdditionalCoupons(array $applyCoupons)
Calculate additional basket coupons.
getAdditionalCoupons(array $filter=array())
Return additional coupons for exist order.
getBasketCodes($full=true)
Returns basket codes for calculate.
calculateApplySaleAdditionalCoupons(array $applyCoupons)
Calculate additional sale coupons.

◆ calculateApplyBasketAdditionalCoupons()

calculateApplyBasketAdditionalCoupons ( array  $applyCoupons)
protected

Calculate additional basket coupons.

Аргументы
array$applyCouponsApply discount coupons data.
Возвращает
Result

См. определение в файле discountbase.php строка 4886

4887  {
4888  $result = new Result;
4889 
4890  if ($this->useOnlySaleDiscounts())
4891  return $result;
4892  if (empty($applyCoupons))
4893  return $result;
4894 
4895  /** @var DiscountCouponsManager $couponClassName */
4896  $couponClassName = $this->getDiscountCouponClassName();
4897 
4898  $applyBlock = &$this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['BASKET'];
4899 
4900  $applyExist = $this->isBasketApplyResultExist();
4901 
4902  $basketCodeList = $this->getBasketCodes(false);
4903  foreach ($basketCodeList as &$basketCode)
4904  {
4905  if (array_key_exists($basketCode, $applyBlock))
4906  unset($applyBlock[$basketCode]);
4907  if (empty($applyCoupons[$basketCode]))
4908  continue;
4909 
4910  $itemData = array(
4911  'MODULE_ID' => $this->orderData['BASKET_ITEMS'][$basketCode]['MODULE'],
4912  'PRODUCT_ID' => $this->orderData['BASKET_ITEMS'][$basketCode]['PRODUCT_ID'],
4913  'BASKET_ID' => $basketCode
4914  );
4915  $this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE_TMP'] = $this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE'];
4916  $this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE'] = $this->orderData['BASKET_ITEMS'][$basketCode]['PRICE'];
4917  foreach ($applyCoupons[$basketCode] as $index => $discount)
4918  {
4919  $discountResult = $this->convertDiscount($discount);
4920  if (!$discountResult->isSuccess())
4921  {
4922  $result->addErrors($discountResult->getErrors());
4923  unset($discountResult);
4924  return $result;
4925  }
4926  $orderDiscountId = $discountResult->getId();
4927  $discountData = $discountResult->getData();
4928  $applyCoupons[$basketCode][$index]['ORDER_DISCOUNT_ID'] = $orderDiscountId;
4929 
4930  if (empty($discount['COUPON']))
4931  {
4932  $result->addError(new Main\Entity\EntityError(
4933  Loc::getMessage('BX_SALE_DISCOUNT_ERR_DISCOUNT_WITHOUT_COUPON'),
4934  self::ERROR_ID
4935  ));
4936  return $result;
4937  }
4938  $couponResult = $this->convertCoupon($discount['COUPON'], $orderDiscountId);
4939  if (!$couponResult->isSuccess())
4940  {
4941  $result->addErrors($couponResult->getErrors());
4942  unset($couponResult);
4943  return $result;
4944  }
4945  $orderCouponId = $couponResult->getId();
4946 
4947  $couponClassName::setApplyByProduct($itemData, array($orderCouponId));
4948  unset($couponResult);
4949 
4950  unset($discountData, $discountResult);
4951  if (!isset($applyBlock[$basketCode]))
4952  $applyBlock[$basketCode] = array();
4953  $applyBlock[$basketCode][$index] = array(
4954  'DISCOUNT_ID' => $orderDiscountId,
4955  'COUPON_ID' => $orderCouponId,
4956  'RESULT' => array(
4957  'APPLY' => 'Y',
4958  'DESCR' => false,
4959  'DESCR_DATA' => false
4960  )
4961  );
4962 
4963  $currentProduct = $this->orderData['BASKET_ITEMS'][$basketCode];
4964  $orderApplication = (
4965  !empty($this->discountsCache[$orderDiscountId]['APPLICATION'])
4966  ? $this->discountsCache[$orderDiscountId]['APPLICATION']
4967  : null
4968  );
4969  if (!empty($orderApplication))
4970  {
4971  $this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT'] = (
4972  !empty($this->discountsCache[$orderDiscountId]['ACTIONS_DESCR_DATA'])
4973  ? $this->discountsCache[$orderDiscountId]['ACTIONS_DESCR_DATA']
4974  : false
4975  );
4976 
4977  $applyProduct = null;
4978  eval('$applyProduct='.$orderApplication.';');
4979  if (is_callable($applyProduct))
4980  $applyProduct($this->orderData['BASKET_ITEMS'][$basketCode]);
4981  unset($applyProduct);
4982 
4983  if (!empty($this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT']))
4984  {
4985  $applyBlock[$basketCode][$index]['RESULT']['DESCR_DATA'] = $this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT']['BASKET'];
4986  $applyBlock[$basketCode][$index]['RESULT']['DESCR'] = $this->formatDescription($this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT']);
4987  }
4988  unset($this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT']);
4989  }
4990  unset($orderApplication);
4991 
4992  if ($applyExist && !$this->getStatusApplyBasketDiscount($basketCode, $orderDiscountId, $orderCouponId))
4993  {
4994  $this->orderData['BASKET_ITEMS'][$basketCode] = $currentProduct;
4995  $applyBlock[$basketCode][$index]['RESULT']['APPLY'] = 'N';
4996  }
4997  unset($currentProduct);
4998  if ($applyBlock[$basketCode][$index]['RESULT']['APPLY'] == 'Y')
4999  $this->orderData['BASKET_ITEMS'][$basketCode]['ACTION_APPLIED'] = 'Y';
5000  }
5001  unset($discount, $index);
5002  $this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE'] = $this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE_TMP'];
5003  unset($this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE_TMP']);
5004  }
5005  unset($basketCode, $basketCodeList);
5006 
5007  unset($applyBlock);
5008 
5009  return $result;
5010  }
static formatDescription($descr)
Return formatted discount description.
getStatusApplyBasketDiscount($basketCode, $orderDiscountId, $orderCouponId)
Return apply status for basket discount.
isBasketApplyResultExist()
Return true, if exist apply result from form for basket.
convertDiscount($discount)
Convert discount for saving in order.
convertCoupon($coupon, $discount)
Convert coupon for saving in order.

◆ calculateApplyBasketDiscount()

calculateApplyBasketDiscount ( )
protected

Apply basket discount in exist order.

Возвращает
Result

См. определение в файле discountbase.php строка 2440

2441  {
2442  $result = new Result;
2443 
2444  if ($this->useOnlySaleDiscounts())
2445  return $result;
2446  if (empty($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['BASKET']))
2447  return $result;
2448 
2449  $applyExist = $this->isBasketApplyResultExist();
2450 
2451  $applyBlock = &$this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['BASKET'];
2452 
2453  foreach ($this->getBasketCodes(false) as $basketCode)
2454  {
2455  if ($this->isCustomPriceByCode($basketCode))
2456  {
2457  if (isset($applyBlock[$basketCode]))
2458  unset($applyBlock[$basketCode]);
2459  continue;
2460  }
2461  if (empty($applyBlock[$basketCode]))
2462  continue;
2463 
2464  foreach ($applyBlock[$basketCode] as $index => $discount)
2465  {
2466  $currentProduct = $this->orderData['BASKET_ITEMS'][$basketCode];
2467  $orderDiscountId = $discount['DISCOUNT_ID'];
2468  $orderCouponId = $discount['COUPON_ID'];
2469 
2470  if (!isset($this->discountsCache[$orderDiscountId]))
2471  {
2472  $result->addError(new Main\Entity\EntityError(
2473  Loc::getMessage('BX_SALE_DISCOUNT_ERR_APPLY_WITHOUT_EXT_DISCOUNT'),
2474  self::ERROR_ID
2475  ));
2476  return $result;
2477  }
2478 
2479  $orderApplication = (
2480  !empty($this->discountsCache[$orderDiscountId]['APPLICATION'])
2481  ? $this->discountsCache[$orderDiscountId]['APPLICATION']
2482  : null
2483  );
2484  if (!empty($orderApplication) && !$this->loadDiscountModules($this->discountsCache[$orderDiscountId]['MODULES']))
2485  $orderApplication = null;
2486 
2487  if (!empty($orderApplication))
2488  {
2489  $this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT'] = (
2490  !empty($this->discountsCache[$orderDiscountId]['ACTIONS_DESCR_DATA'])
2491  ? $this->discountsCache[$orderDiscountId]['ACTIONS_DESCR_DATA']
2492  : false
2493  );
2494 
2495  $applyProduct = null;
2496  eval('$applyProduct='.$orderApplication.';');
2497  if (is_callable($applyProduct))
2498  $applyProduct($this->orderData['BASKET_ITEMS'][$basketCode]);
2499  unset($applyProduct);
2500 
2501  if (!empty($this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT']))
2502  {
2503  $applyBlock[$basketCode][$index]['RESULT']['DESCR_DATA'] = $this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT'];
2504  $applyBlock[$basketCode][$index]['RESULT']['DESCR'] = $this->formatDescription($this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT']);
2505  }
2506  unset($this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT']);
2507  }
2508  unset($orderApplication);
2509 
2510  $disable = ($applyBlock[$basketCode][$index]['RESULT']['APPLY'] == 'N');
2511  if ($applyExist)
2512  {
2513  $applyDisable = !$this->getStatusApplyBasketDiscount($basketCode, $orderDiscountId, $orderCouponId);
2514  if ($applyDisable != $disable)
2515  $disable = $applyDisable;
2516  unset($applyDisable);
2517  }
2518  if ($disable)
2519  {
2520  $this->orderData['BASKET_ITEMS'][$basketCode] = $currentProduct;
2521  $applyBlock[$basketCode][$index]['RESULT']['APPLY'] = 'N';
2522  }
2523  else
2524  {
2525  $applyBlock[$basketCode][$index]['RESULT']['APPLY'] = 'Y';
2526  $this->orderData['BASKET_ITEMS'][$basketCode]['ACTION_APPLIED'] = 'Y';
2527  }
2528  unset($disable, $currentProduct);
2529 
2530  }
2531  unset($index, $discount);
2532  }
2533  unset($basketCode);
2534 
2535  unset($applyBlock);
2536 
2537  return $result;
2538  }
isCustomPriceByCode($code)
Returns exist custom price for basket item code.

◆ calculateApplyDiscountBlock()

calculateApplyDiscountBlock ( )
protected

Calculate discount block for existing order.

Возвращает
Result

См. определение в файле discountbase.php строка 2545

2546  {
2547  $result = new Result;
2548 
2549  $basketDiscountResult = $this->calculateApplyBasketDiscount();
2550  if (!$basketDiscountResult->isSuccess())
2551  {
2552  $result->addErrors($basketDiscountResult->getErrors());
2553  unset($basketDiscountResult);
2554 
2555  return $result;
2556  }
2557  unset($basketDiscountResult);
2558 
2559  $roundApply = false;
2560  if ($this->isRoundMode(self::ROUND_MODE_BASKET_DISCOUNT))
2561  {
2562  $roundApply = true;
2563  $this->roundApplyBasketPrices();
2564  }
2565 
2566  if ($this->isRoundMode(self::ROUND_MODE_SALE_DISCOUNT) && !$roundApply)
2567  {
2568  $this->roundApplyBasketPricesByIndex(array(
2569  'DISCOUNT_INDEX' => -1,
2570  'DISCOUNT_ID' => 0
2571  ));
2572  }
2573  if (!empty($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER']))
2574  {
2575  $index = -1;
2576  foreach ($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'] as $indexDiscount => $discount)
2577  {
2578  $index++;
2579  $orderDiscountId = $discount['DISCOUNT_ID'];
2580  if (!isset($this->discountsCache[$orderDiscountId]))
2581  {
2582  $result->addError(new Main\Entity\EntityError(
2583  Loc::getMessage('BX_SALE_DISCOUNT_ERR_APPLY_WITHOUT_SALE_DISCOUNT'),
2584  self::ERROR_ID
2585  ));
2586  return $result;
2587  }
2589  if (!empty($discount['RESULT']['BASKET']))
2590  {
2591  if ($discount['ACTION_BLOCK_LIST'])
2592  {
2594  $blockList = array();
2595  foreach ($discount['RESULT']['BASKET'] as $basketCode => $basketItem)
2596  $blockList[$basketCode] = $basketItem['ACTION_BLOCK_LIST'];
2597  unset($basketCode, $basketItem);
2598  }
2599  else
2600  {
2601  if ($this->discountsCache[$orderDiscountId]['SIMPLE_ACTION'])
2602  {
2603  $applyResultMode = Discount\Actions::APPLY_RESULT_MODE_SIMPLE;
2604  $blockList = array_fill_keys(array_keys($discount['RESULT']['BASKET']), true);
2605  }
2606  else
2607  {
2608  $applyResultMode = Discount\Actions::APPLY_RESULT_MODE_DESCR;
2609  $blockList = array();
2610  foreach ($discount['RESULT']['BASKET'] as $basketCode => $basketItem)
2611  $blockList[$basketCode] = $basketItem['DESCR_DATA'];
2612  unset($basketCode, $basketItem);
2613  }
2614  }
2615  Discount\Actions::setApplyResultMode($applyResultMode);
2616  Discount\Actions::setApplyResult(array('BASKET' => $blockList));
2617  unset($blockList, $applyResultMode);
2618  }
2619  if ($this->isRoundMode(self::ROUND_MODE_SALE_DISCOUNT) && !$roundApply)
2620  {
2621  $this->roundApplyBasketPricesByIndex(array(
2622  'DISCOUNT_INDEX' => $index,
2623  'DISCOUNT_ID' => $orderDiscountId
2624  ));
2625  }
2626  $this->fillCurrentStep(array(
2627  'discountIndex' => $indexDiscount,
2628  'discountId' => $orderDiscountId,
2629  ));
2630  $actionsResult = $this->applySaleDiscount();
2631  if (!$actionsResult->isSuccess())
2632  {
2633  $result->addErrors($actionsResult->getErrors());
2634  unset($actionsResult);
2635  return $result;
2636  }
2637  unset($orderDiscountId);
2638  }
2639  if ($this->isRoundMode(self::ROUND_MODE_SALE_DISCOUNT) && !$roundApply)
2640  {
2641  $index++;
2642  $this->roundApplyBasketPricesByIndex(array(
2643  'DISCOUNT_INDEX' => $index,
2644  'DISCOUNT_ID' => 0
2645  ));
2646  $roundConfig = $this->getRoundIndex('BASKET_ROUND');
2647  if (is_array($roundConfig))
2648  {
2649  if ($roundConfig['DISCOUNT_INDEX'] > $index && $roundConfig['DISCOUNT_ID'] == 0)
2650  {
2651  $this->roundApplyBasketPricesByIndex(array(
2652  'DISCOUNT_INDEX' => $roundConfig['DISCOUNT_INDEX'],
2653  'DISCOUNT_ID' => 0
2654  ));
2655  }
2656  }
2657  unset($roundConfig);
2658  }
2659  unset($discount, $indexDiscount, $currentList);
2660  }
2661 
2662  if ($this->isRoundMode(self::ROUND_MODE_FINAL_PRICE))
2663  $this->roundApplyBasketPrices();
2664 
2665  $this->fillEmptyCurrentStep();
2666 
2667  return $result;
2668  }
static setApplyResult(array $applyResult)
Set apply result list.
static setApplyResultMode($mode)
Set apply result format mode.
roundApplyBasketPrices()
Round prices.
fillCurrentStep($data)
Internal.
roundApplyBasketPricesByIndex(array $index)
Round prices in sale discount mode for exist order.
applySaleDiscount()
Apply discount rules.
calculateApplyBasketDiscount()
Apply basket discount in exist order.
getRoundIndex($entity, $applyCounter=null)
Return index data for use round.

◆ calculateApplySaleAdditionalCoupons()

calculateApplySaleAdditionalCoupons ( array  $applyCoupons)
protected

Calculate additional sale coupons.

Аргументы
array$applyCouponsCoupons data.
Возвращает
Result

См. определение в файле discountbase.php строка 5018

5019  {
5020  $result = new Result;
5021 
5022  if (empty($applyCoupons))
5023  return $result;
5024 
5025  $this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'] = array();
5026 
5027  $discountId = array();
5028  foreach ($applyCoupons as $coupon)
5029  $discountId[] = $coupon['DISCOUNT_ID'];
5030  unset($coupon);
5031 
5032  $currentUseMode = $this->getUseMode();
5033  $this->setUseMode(self::USE_MODE_COUPONS);
5034 
5035  $this->loadDiscountByUserGroups(array('@DISCOUNT_ID' => $discountId));
5036  unset($discountId);
5037 
5038  $basketCodeList = $this->getBasketCodes(false);
5039  foreach ($basketCodeList as $basketCode)
5040  {
5041  $this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE_TMP'] = $this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE'];
5042  $this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE'] = $this->orderData['BASKET_ITEMS'][$basketCode]['PRICE'];
5043  }
5044  unset($basketCode);
5045 
5046  $this->loadDiscountList();
5047  $executeResult = $this->executeDiscountList();
5048  if (!$executeResult->isSuccess())
5049  $result->addErrors($executeResult->getErrors());
5050  unset($executeResult);
5051  $this->setUseMode($currentUseMode);
5052  unset($currentUseMode);
5053 
5054  foreach ($basketCodeList as $basketCode)
5055  {
5056  $this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE'] = $this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE_TMP'];
5057  unset($this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE_TMP']);
5058  }
5059  unset($basketCode);
5060  unset($basketCodeList);
5061 
5062  return $result;
5063  }
loadDiscountList()
Load sale discount from database.
loadDiscountByUserGroups(array $filter=array())
Load from database discount id for user groups.
setUseMode($useMode)
Set calculate mode.
executeDiscountList()
Execute sale discount list.

◆ calculateApplySaleDiscountResult()

calculateApplySaleDiscountResult ( )
protected

Calculate step discount result by exist order.

Возвращает
Result

См. определение в файле discountbase.php строка 3005

3006  {
3007  $result = new Result;
3008 
3009  /** @var DiscountCouponsManager $couponClassName */
3010  $couponClassName = $this->getDiscountCouponClassName();
3011 
3012  $this->orderData['DISCOUNT_RESULT'] = Discount\Actions::getActionResult();
3013  if (!empty($this->orderData['DISCOUNT_RESULT']) && is_array($this->orderData['DISCOUNT_RESULT']))
3014  $stepResult = $this->getStepResult($this->orderData);
3015  else
3017  $this->orderData, $this->currentStep['oldData']
3018  );
3019  $applied = !empty($stepResult);
3020 
3021  $orderDiscountId = 0;
3022  $orderCouponId = '';
3023 
3024  if ($applied)
3025  {
3026  $this->correctStepResult($stepResult, $this->discountsCache[$this->currentStep['discountId']]);
3027 
3028  $orderDiscountId = $this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$this->currentStep['discountIndex']]['DISCOUNT_ID'];
3029  $orderCouponId = $this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$this->currentStep['discountIndex']]['COUPON_ID'];
3030  }
3031 
3032  unset($this->orderData['DISCOUNT_RESULT']);
3033 
3034  if ($applied)
3035  {
3036  if (
3037  (
3038  !empty($this->applyResult['DISCOUNT_LIST'][$orderDiscountId])
3039  && $this->applyResult['DISCOUNT_LIST'][$orderDiscountId] == 'N'
3040  )
3041  ||
3042  (
3043  $orderCouponId != ''
3044  && !empty($this->applyResult['COUPON_LIST'][$orderCouponId])
3045  && $this->applyResult['COUPON_LIST'][$orderCouponId] == 'N'
3046  )
3047  )
3048  {
3049  $this->orderData = $this->currentStep['oldData'];
3050  if (!empty($stepResult['BASKET']))
3051  {
3052  foreach ($stepResult['BASKET'] as &$basketItem)
3053  $basketItem['APPLY'] = 'N';
3054  unset($basketItem);
3055  }
3056  if (!empty($stepResult['DELIVERY']))
3057  $stepResult['DELIVERY']['APPLY'] = 'N';
3058  }
3059  else
3060  {
3061  if (!empty($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$this->currentStep['discountIndex']]['RESULT']))
3062  {
3063  $existDiscountResult = $this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$this->currentStep['discountIndex']]['RESULT'];
3064  if (!empty($existDiscountResult['BASKET']))
3065  {
3066  $basketCodeList = $this->getBasketCodes(false);
3067  if (!empty($basketCodeList))
3068  {
3069  foreach ($basketCodeList as &$basketCode)
3070  {
3071  if ($this->isCustomPriceByCode($basketCode))
3072  continue;
3073  if (isset($existDiscountResult['BASKET'][$basketCode]))
3074  {
3075  $disable = ($existDiscountResult['BASKET'][$basketCode]['APPLY'] == 'N');
3076  if (isset($this->applyResult['BASKET'][$basketCode][$orderDiscountId]))
3077  {
3078  $applyDisable = ($this->applyResult['BASKET'][$basketCode][$orderDiscountId] == 'N');
3079  if ($disable != $applyDisable)
3080  $disable = $applyDisable;
3081  unset($applyDisable);
3082  }
3083  if ($disable)
3084  {
3085  $stepResult['BASKET'][$basketCode]['APPLY'] = 'N';
3086  $this->orderData['BASKET_ITEMS'][$basketCode] = $this->currentStep['oldData']['BASKET_ITEMS'][$basketCode];
3087  }
3088  else
3089  {
3090  $stepResult['BASKET'][$basketCode]['APPLY'] = 'Y';
3091  $this->orderData['BASKET_ITEMS'][$basketCode]['ACTION_APPLIED'] = 'Y';
3092  }
3093  }
3094  }
3095  unset($disable, $basketCode);
3096  }
3097  }
3098  if (!empty($existDiscountResult['DELIVERY']))
3099  {
3100  $disable = ($existDiscountResult['DELIVERY']['APPLY'] == 'N');
3101  if (!empty($this->applyResult['DELIVERY'][$orderDiscountId]))
3102  {
3103  $applyDisable = ($this->applyResult['DELIVERY'][$orderDiscountId] == 'N');
3104  if ($disable != $applyDisable)
3105  $disable = $applyDisable;
3106  unset($applyDisable);
3107  }
3108  if ($disable)
3109  {
3110  $this->orderData['PRICE_DELIVERY'] = $this->currentStep['oldData']['PRICE_DELIVERY'];
3111  $this->orderData['PRICE_DELIVERY_DIFF'] = $this->currentStep['oldData']['PRICE_DELIVERY_DIFF'];
3112  $stepResult['DELIVERY']['APPLY'] = 'N';
3113  }
3114  else
3115  {
3116  $stepResult['DELIVERY']['APPLY'] = 'Y';
3117  }
3118  unset($disable);
3119  }
3120  }
3121  }
3122  }
3123 
3124  if ($applied && $orderCouponId != '')
3125  {
3126  $couponApply = $couponClassName::setApply($this->couponsCache[$orderCouponId]['COUPON'], $stepResult);
3127  unset($couponApply);
3128  }
3129 
3130  if ($applied)
3131  {
3132  $this->mergeDiscountActionResult($this->currentStep['discountIndex'], $stepResult);
3133  }
3134  else
3135  {
3136  if (!empty($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$this->currentStep['discountIndex']]))
3137  $this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$this->currentStep['discountIndex']]['RESULT'] = array();
3138  }
3139 
3140  return $result;
3141  }
static getActionResult()
Return all actions results.
static getStepResult(array $currentOrder, array $oldOrder)
Returns result after apply one discount in old format.
correctStepResult(&$stepResult, $discount)
Correct data for exotic coupon.
mergeDiscountActionResult($index, $stepResult)
Merge discount actions result with old data.
static getStepResult(array $order)
Returns result after one discount.

◆ calculateDiscountPercent()

static calculateDiscountPercent (   $basePrice,
  $discount 
)
static

Calculate discount percent for public components.

Аргументы
int | float$basePriceBase price.
int | float$discountDiscount value (for an extra can be negative).
Возвращает
float|int|null

См. определение в файле discountbase.php строка 5681

5682  {
5683  $basePrice = (float)$basePrice;
5684  if ($basePrice <= 0)
5685  return null;
5686  $discount = (float)$discount;
5687  if ($discount > $basePrice)
5688  return null;
5689 
5690  $result = round(100*$discount/$basePrice, 0);
5691  if ($result < 0)
5692  $result = 0;
5693  return $result;
5694  }

◆ calculateFull()

calculateFull ( )
protected

Calculate discount by new order.

Возвращает
Result

См. определение в файле discountbase.php строка 1287

1288  {
1289  $result = new Result;
1290  if (!$this->isBasketNotEmpty())
1291  return $result;
1292 
1293  $this->discountIds = array();
1295  Discount\Actions::MODE_CALCULATE,
1296  array(
1297  'USE_BASE_PRICE' => $this->saleOptions['USE_BASE_PRICE'],
1298  'SITE_ID' => $this->orderData['SITE_ID'],
1299  'CURRENCY' => $this->orderData['CURRENCY']
1300  )
1301  );
1302 
1303  $this->fillEmptyDiscountResult();
1304  $this->getRoundForBasePrices();
1305  $this->checkBasketDiscounts();
1306 
1307  /** @var DiscountCouponsManager $couponClassName */
1308  $couponClassName = $this->getDiscountCouponClassName();
1309  $couponClassName::clearApply();
1310  $basketDiscountResult = $this->calculateFullBasketDiscount();
1311  if (!$basketDiscountResult->isSuccess())
1312  $result->addErrors($basketDiscountResult->getErrors());
1313  unset($basketDiscountResult);
1314  if (!$result->isSuccess())
1315  return $result;
1316 
1317  if ($this->isRoundMode(self::ROUND_MODE_BASKET_DISCOUNT))
1318  $this->roundFullBasketPrices();
1319 
1320  if (!$this->isBasketLastDiscount())
1321  {
1322  $this->loadDiscountByUserGroups();
1323  $this->loadDiscountList();
1324  $executeResult = $this->executeDiscountList();
1325  if (!$executeResult->isSuccess())
1326  $result->addErrors($executeResult->getErrors());
1327  unset($executeResult);
1328  if (!$result->isSuccess())
1329  return $result;
1330  }
1331 
1332  if ($this->isRoundMode(self::ROUND_MODE_FINAL_PRICE))
1333  $this->roundFullBasketPrices();
1334 
1335  return $result;
1336  }
roundFullBasketPrices()
Round prices.
checkBasketDiscounts()
Check product discount list for basket items.
isBasketLastDiscount()
Check last discount flag for basket items.
isBasketNotEmpty()
Returns the existence of a non-empty basket.
fillEmptyDiscountResult()
Fill empty discount result list.
calculateFullBasketDiscount()
Apply basket discount in new order.

◆ calculateFullBasketDiscount()

calculateFullBasketDiscount ( )
protected

Apply basket discount in new order.

Возвращает
Result

См. определение в файле discountbase.php строка 2312

2313  {
2314  $result = new Result;
2315 
2316  if ((string)Main\Config\Option::get('sale', 'use_sale_discount_only') == 'Y')
2317  return $result;
2318  if (empty($this->basketDiscountList))
2319  return $result;
2320 
2321  /** @var DiscountCouponsManager $couponClassName */
2322  $couponClassName = $this->getDiscountCouponClassName();
2323 
2324  $applyExist = $this->isBasketApplyResultExist();
2325 
2326  $applyBlock = &$this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['BASKET'];
2327 
2328  foreach ($this->getBasketCodes(true) as $basketCode)
2329  {
2330  if ($this->isOrderNew() && array_key_exists($basketCode, $applyBlock))
2331  unset($applyBlock[$basketCode]);
2332  if (empty($this->basketDiscountList[$basketCode]))
2333  continue;
2334 
2335  $itemData = array(
2336  'MODULE_ID' => $this->orderData['BASKET_ITEMS'][$basketCode]['MODULE'],
2337  'PRODUCT_ID' => $this->orderData['BASKET_ITEMS'][$basketCode]['PRODUCT_ID'],
2338  'BASKET_ID' => $basketCode
2339  );
2340  foreach ($this->basketDiscountList[$basketCode] as $index => $discount)
2341  {
2342  $discountResult = $this->convertDiscount($discount);
2343  if (!$discountResult->isSuccess())
2344  {
2345  $result->addErrors($discountResult->getErrors());
2346  unset($discountResult);
2347  return $result;
2348  }
2349  $orderDiscountId = $discountResult->getId();
2350  $discountData = $discountResult->getData();
2351  $orderCouponId = '';
2352  $this->basketDiscountList[$basketCode][$index]['ORDER_DISCOUNT_ID'] = $orderDiscountId;
2353  if ($discountData['USE_COUPONS'] == 'Y')
2354  {
2355  if (empty($discount['COUPON']))
2356  {
2357  $result->addError(new Main\Entity\EntityError(
2358  Loc::getMessage('BX_SALE_DISCOUNT_ERR_DISCOUNT_WITHOUT_COUPON'),
2359  self::ERROR_ID
2360  ));
2361  return $result;
2362  }
2363  $couponResult = $this->convertCoupon($discount['COUPON'], $orderDiscountId);
2364  if (!$couponResult->isSuccess())
2365  {
2366  $result->addErrors($couponResult->getErrors());
2367  unset($couponResult);
2368  return $result;
2369  }
2370  $orderCouponId = $couponResult->getId();
2371 
2372  $couponClassName::setApplyByProduct($itemData, array($orderCouponId));
2373  unset($couponResult);
2374  }
2375  unset($discountData, $discountResult);
2376  if (!isset($applyBlock[$basketCode]))
2377  $applyBlock[$basketCode] = array();
2378  $applyBlock[$basketCode][$index] = array(
2379  'DISCOUNT_ID' => $orderDiscountId,
2380  'COUPON_ID' => $orderCouponId,
2381  'RESULT' => array(
2382  'APPLY' => 'Y',
2383  'DESCR' => false,
2384  'DESCR_DATA' => false
2385  )
2386  );
2387 
2388  $currentProduct = $this->orderData['BASKET_ITEMS'][$basketCode];
2389  $orderApplication = (
2390  !empty($this->discountsCache[$orderDiscountId]['APPLICATION'])
2391  ? $this->discountsCache[$orderDiscountId]['APPLICATION']
2392  : null
2393  );
2394  if (!empty($orderApplication))
2395  {
2396  $this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT'] = (
2397  !empty($this->discountsCache[$orderDiscountId]['ACTIONS_DESCR_DATA'])
2398  ? $this->discountsCache[$orderDiscountId]['ACTIONS_DESCR_DATA']
2399  : false
2400  );
2401 
2402  $applyProduct = null;
2403  eval('$applyProduct='.$orderApplication.';');
2404  if (is_callable($applyProduct))
2405  $applyProduct($this->orderData['BASKET_ITEMS'][$basketCode]);
2406  unset($applyProduct);
2407 
2408  if (!empty($this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT']))
2409  {
2410  $applyBlock[$basketCode][$index]['RESULT']['DESCR_DATA'] = $this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT']['BASKET'];
2411  $applyBlock[$basketCode][$index]['RESULT']['DESCR'] = $this->formatDescription($this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT']);
2412  }
2413  unset($this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_RESULT']);
2414  }
2415  unset($orderApplication);
2416 
2417  if ($applyExist && !$this->getStatusApplyBasketDiscount($basketCode, $orderDiscountId, $orderCouponId))
2418  {
2419  $this->orderData['BASKET_ITEMS'][$basketCode] = $currentProduct;
2420  $applyBlock[$basketCode][$index]['RESULT']['APPLY'] = 'N';
2421  }
2422  unset($disable, $currentProduct);
2423  if ($applyBlock[$basketCode][$index]['RESULT']['APPLY'] == 'Y')
2424  $this->orderData['BASKET_ITEMS'][$basketCode]['ACTION_APPLIED'] = 'Y';
2425  }
2426  unset($discount, $index);
2427  }
2428  unset($basketCode);
2429 
2430  unset($applyBlock);
2431 
2432  return $result;
2433  }
static get($moduleId, $name, $default="", $siteId=false)
Returns a value of an option.

◆ calculateFullSaleDiscountResult()

calculateFullSaleDiscountResult ( )
protected

Calculate step discount result by new order.

Возвращает
Result

См. определение в файле discountbase.php строка 2765

2766  {
2767  $result = new Result;
2768 
2769  /** @var DiscountCouponsManager $couponClassName */
2770  $couponClassName = $this->getDiscountCouponClassName();
2771 
2772  $this->orderData['DISCOUNT_RESULT'] = Discount\Actions::getActionResult();
2773  $this->orderData['DISCOUNT_DESCR'] = Discount\Actions::getActionDescription();
2774  if (!empty($this->orderData['DISCOUNT_RESULT']) && is_array($this->orderData['DISCOUNT_RESULT']))
2775  {
2776  $stepResult = $this->getStepResult($this->orderData);
2777  }
2778  else
2779  {
2781  $this->orderData,
2782  $this->currentStep['oldData']
2783  );
2784  if (!empty($stepResult))
2785  {
2786  if (empty($this->orderData['DISCOUNT_DESCR']) || !is_array($this->orderData['DISCOUNT_DESCR']))
2787  $this->orderData['DISCOUNT_DESCR'] = Discount\Result\CompatibleFormat::getDiscountDescription($stepResult);
2788  }
2789  }
2790 
2791  Discount\Actions::fillCompatibleFields($this->orderData);
2792  $applied = !empty($stepResult);
2793 
2794  $orderDiscountId = 0;
2795  $orderCouponId = '';
2796 
2797  if ($applied)
2798  {
2799  $this->correctStepResult($stepResult, $this->currentStep['discount']);
2800 
2801  $this->currentStep['discount']['ACTIONS_DESCR'] = $this->orderData['DISCOUNT_DESCR'];
2802  $discountResult = $this->convertDiscount($this->currentStep['discount']);
2803  if (!$discountResult->isSuccess())
2804  {
2805  $result->addErrors($discountResult->getErrors());
2806  return $result;
2807  }
2808  $orderDiscountId = $discountResult->getId();
2809  $discountData = $discountResult->getData();
2810 
2811  $this->currentStep['discount']['ORDER_DISCOUNT_ID'] = $orderDiscountId;
2812 
2813  if ($discountData['USE_COUPONS'] == 'Y')
2814  {
2815  if (empty($this->currentStep['discount']['COUPON']))
2816  {
2817  $result->addError(new Main\Entity\EntityError(
2818  Loc::getMessage('BX_SALE_DISCOUNT_ERR_DISCOUNT_WITHOUT_COUPON'),
2819  self::ERROR_ID
2820  ));
2821 
2822  return $result;
2823  }
2824  $couponResult = $this->convertCoupon($this->currentStep['discount']['COUPON']['COUPON'], $orderDiscountId);
2825  if (!$couponResult->isSuccess())
2826  {
2827  $result->addErrors($couponResult->getErrors());
2828  unset($couponResult);
2829 
2830  return $result;
2831  }
2832  $orderCouponId = $couponResult->getId();
2833  $couponClassName::setApply($orderCouponId, $stepResult);
2834  unset($couponResult);
2835  }
2836  $this->setDiscountStoredActionData($orderDiscountId, Discount\Actions::getStoredData());
2837  }
2838  unset($this->orderData['DISCOUNT_DESCR'], $this->orderData['DISCOUNT_RESULT']);
2839 
2840  if ($applied)
2841  {
2842  if (
2843  (
2844  !empty($this->applyResult['DISCOUNT_LIST'][$orderDiscountId])
2845  && $this->applyResult['DISCOUNT_LIST'][$orderDiscountId] == 'N'
2846  )
2847  ||
2848  (
2849  $orderCouponId != ''
2850  && !empty($this->applyResult['COUPON_LIST'][$orderCouponId])
2851  && $this->applyResult['COUPON_LIST'][$orderCouponId] == 'N'
2852  )
2853  )
2854  {
2855  $this->orderData = $this->currentStep['oldData'];
2856  if (!empty($stepResult['BASKET']))
2857  {
2858  foreach ($stepResult['BASKET'] as &$basketItem)
2859  $basketItem['APPLY'] = 'N';
2860  unset($basketItem);
2861  }
2862  if (!empty($stepResult['DELIVERY']))
2863  $stepResult['DELIVERY']['APPLY'] = 'N';
2864  }
2865  else
2866  {
2867  if (!empty($this->applyResult['BASKET']) && is_array($this->applyResult['BASKET']))
2868  {
2869  foreach ($this->applyResult['BASKET'] as $basketCode => $discountList)
2870  {
2871  if (
2872  is_array($discountList) && !empty($discountList[$orderDiscountId]) && $discountList[$orderDiscountId] == 'N'
2873  )
2874  {
2875  if (empty($stepResult['BASKET'][$basketCode]))
2876  continue;
2877  $stepResult['BASKET'][$basketCode]['APPLY'] = 'N';
2878  $this->orderData['BASKET_ITEMS'][$basketCode] = $this->currentStep['oldData']['BASKET_ITEMS'][$basketCode];
2879  }
2880  }
2881  unset($basketCode, $discountList);
2882  }
2883  if (!empty($this->applyResult['DELIVERY']))
2884  {
2885  if (
2886  is_array($this->applyResult['DELIVERY']) && !empty($this->applyResult['DELIVERY'][$orderDiscountId]) && $this->applyResult['DELIVERY'][$orderDiscountId] == 'N'
2887  )
2888  {
2889  $this->orderData['PRICE_DELIVERY'] = $this->currentStep['oldData']['PRICE_DELIVERY'];
2890  $this->orderData['PRICE_DELIVERY_DIFF'] = $this->currentStep['oldData']['PRICE_DELIVERY_DIFF'];
2891  $stepResult['DELIVERY']['APPLY'] = 'N';
2892  }
2893  }
2894  }
2895  }
2896 
2897  if ($applied && $orderCouponId != '')
2898  {
2899  $couponApply = $couponClassName::setApply($this->couponsCache[$orderCouponId]['COUPON'], $stepResult);
2900  unset($couponApply);
2901  }
2902 
2903  if ($applied)
2904  {
2905  $this->tryToRevertApplyStatusInBlocks($stepResult);
2906 
2907  if (!empty($stepResult['BASKET']))
2908  {
2909  foreach ($stepResult['BASKET'] as $basketCode => $itemResult)
2910  {
2911  if ($itemResult['APPLY'] == 'Y')
2912  $this->orderData['BASKET_ITEMS'][$basketCode]['ACTION_APPLIED'] = 'Y';
2913  }
2914  unset($basketCode, $itemResult);
2915  }
2916 
2917  $this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][] = array(
2918  'DISCOUNT_ID' => $orderDiscountId,
2919  'COUPON_ID' => $orderCouponId,
2920  'RESULT' => $stepResult
2921  );
2922  if ($this->currentStep['discount']['LAST_DISCOUNT'] == 'Y')
2923  $this->currentStep['stop'] = true;
2924 
2925  if ($this->currentStep['discount']['LAST_LEVEL_DISCOUNT'] == 'Y')
2926  $this->currentStep['stopLevel'] = true;
2927  }
2928 
2929  return $result;
2930  }
static fillCompatibleFields(array &$order)
Fill compatible fields for old public api.
static getActionDescription()
Return all actions description.
static getStoredData()
Return stored data after discount calculation.
static getDiscountDescription(array $stepResult)
Returns description for old discount.
setDiscountStoredActionData($orderDiscountId, array $data)
Fill additional discount data.
tryToRevertApplyStatusInBlocks(array $stepResult)
Tries to revert apply status of discounts.

◆ calculateMixed()

calculateMixed ( )
protected

Calculate discount by exist order with new items.

Возвращает
Result

См. определение в файле discountbase.php строка 1417

1418  {
1419  $result = new Result;
1420 
1421  if (!$this->isOrderExists())
1422  return $result;
1423 
1424  if (!$this->isValidState())
1425  return $result;
1426 
1427  if (!empty($this->discountResult['APPLY_BLOCKS']))
1428  {
1430  Discount\Actions::MODE_MANUAL,
1431  array(
1432  'USE_BASE_PRICE' => $this->saleOptions['USE_BASE_PRICE'],
1433  'SITE_ID' => $this->orderData['SITE_ID'],
1434  'CURRENCY' => $this->orderData['CURRENCY']
1435  )
1436  );
1437 
1438  $currentCounter = $this->discountResultCounter;
1439 
1440  foreach (array_keys($this->discountResult['APPLY_BLOCKS']) as $counter)
1441  {
1442  $this->discountResultCounter = $counter;
1443  $blockResult = $this->calculateApplyDiscountBlock();
1444  if (!$blockResult->isSuccess())
1445  {
1446  $result->addErrors($blockResult->getErrors());
1447  unset($blockResult);
1448 
1449  return $result;
1450  }
1451  unset($blockResult);
1452  }
1453 
1454  $this->discountResultCounter = $currentCounter;
1455  unset($currentCounter);
1456  }
1457 
1458  if ($result->isSuccess())
1459  {
1461  Discount\Actions::MODE_CALCULATE,
1462  array(
1463  'USE_BASE_PRICE' => $this->saleOptions['USE_BASE_PRICE'],
1464  'SITE_ID' => $this->orderData['SITE_ID'],
1465  'CURRENCY' => $this->orderData['CURRENCY']
1466  )
1467  );
1468 
1469  $this->clearCurrentApplyBlock();
1470 
1471  $this->getRoundForBasePrices();
1472  $this->checkBasketDiscounts();
1473 
1474  $basketDiscountResult = $this->calculateFullBasketDiscount();
1475  if (!$basketDiscountResult->isSuccess())
1476  {
1477  $result->addErrors($basketDiscountResult->getErrors());
1478  unset($basketDiscountResult);
1479  return $result;
1480  }
1481  unset($basketDiscountResult);
1482 
1483  if ($this->isRoundMode(self::ROUND_MODE_BASKET_DISCOUNT))
1484  $this->roundFullBasketPrices();
1485 
1486  $couponsResult = $this->calculateApplyAdditionalCoupons();
1487  if (!$couponsResult->isSuccess())
1488  {
1489  $result->addErrors($couponsResult->getErrors());
1490  unset($couponsResult);
1491  return $result;
1492  }
1493  unset($couponsResult);
1494 
1495  if ($this->isRoundMode(self::ROUND_MODE_FINAL_PRICE))
1496  $this->roundChangedBasketPrices();
1497  }
1498 
1499  return $result;
1500  }

◆ checkBasketDiscounts()

checkBasketDiscounts ( )
protected

Check product discount list for basket items.

См. определение в файле discountbase.php строка 2275

2276  {
2277  $useMode = $this->getUseMode();
2278  if (
2279  $useMode === self::USE_MODE_FULL
2280  || $useMode == self::USE_MODE_MIXED
2281  )
2282  {
2283  $basketCodeList = $this->getBasketCodes(true);
2284  if (!empty($basketCodeList))
2285  {
2286  $basket = $this->getBasket();
2287  foreach ($basketCodeList as $code)
2288  {
2289  $basketItem = $basket->getItemByBasketCode($code);
2290  if ($basketItem instanceof BasketItemBase)
2291  {
2292  if (!isset($this->basketDiscountList[$code]))
2293  {
2294  $this->basketDiscountList[$code] = $basketItem->getField('DISCOUNT_LIST');
2295  if ($this->basketDiscountList[$code] === null)
2296  unset($this->basketDiscountList[$code]);
2297  }
2298  }
2299  }
2300  unset($basketItem, $code, $basket);
2301  }
2302  unset($basketCodeList);
2303  }
2304  unset($useMode);
2305  }
getBasket()
Return current basket.

◆ checkDiscountConditions()

checkDiscountConditions ( )
protected

Check duscount conditions.

Возвращает
bool

См. определение в файле discountbase.php строка 2121

2122  {
2123  if (
2124  !isset($this->currentStep['cacheIndex'])
2125  || !isset($this->saleDiscountCache[$this->saleDiscountCacheKey][$this->currentStep['cacheIndex']])
2126  )
2127  return false;
2128 
2129  $key = $this->getConditionField();
2130  $executeKey = self::getExecuteFieldName($key);
2131 
2132  if (empty($this->saleDiscountCache[$this->saleDiscountCacheKey][$this->currentStep['cacheIndex']][$key]))
2133  return false;
2134 
2135  $discountLink = &$this->saleDiscountCache[$this->saleDiscountCacheKey][$this->currentStep['cacheIndex']];
2136 
2137  if (!array_key_exists($executeKey, $discountLink))
2138  {
2139  $checkOrder = null;
2140 
2141  $evalCode = '$checkOrder='.$discountLink[$key].';';
2142  if (PHP_MAJOR_VERSION >= 7)
2143  {
2144  try
2145  {
2146  eval($evalCode);
2147  }
2148  catch (\ParseError $e)
2149  {
2150  $this->showAdminError();
2151  }
2152  }
2153  else
2154  {
2155  eval($evalCode);
2156  }
2157  unset($evalCode);
2158 
2159  if (!is_callable($checkOrder))
2160  return false;
2161  $result = $checkOrder($this->orderData);
2162  unset($checkOrder);
2163  }
2164  else
2165  {
2166  if (!is_callable($discountLink[$executeKey]))
2167  return false;
2168 
2169  $result = $discountLink[$executeKey]($this->orderData);
2170  }
2171  unset($discountLink);
2172  return $result;
2173  }
getConditionField()
Return field with discount condition code.

◆ clearAdditionalCoupons()

clearAdditionalCoupons ( array  $coupons)
protected

Clear coupons from already used discounts.

См. определение в файле discountbase.php строка 4773

4774  {
4775  if (empty($coupons))
4776  return array();
4777 
4778  if (empty($this->discountsCache))
4779  return $coupons;
4780 
4781  $result = array();
4782 
4783  foreach ($coupons as $couponCode => $couponData)
4784  {
4785  $found = false;
4786  foreach ($this->discountsCache as &$discount)
4787  {
4788  if (
4789  $discount['MODULE_ID'] == $couponData['MODULE_ID']
4790  && $discount['DISCOUNT_ID'] == $couponData['DISCOUNT_ID']
4791  && $discount['USE_COUPONS'] == 'N'
4792  )
4793  {
4794  $found = true;
4795  }
4796  }
4797  unset($discount);
4798 
4799  if (!$found && !empty($this->couponsCache))
4800  {
4801  foreach ($this->couponsCache as $existCouponCode => $existCouponData)
4802  {
4803  $discount = $this->discountsCache[$existCouponData['ORDER_DISCOUNT_ID']];
4804  if (
4805  $discount['MODULE_ID'] != $couponData['MODULE_ID']
4806  || $discount['DISCOUNT_ID'] != $couponData['DISCOUNT_ID']
4807  )
4808  continue;
4809  if ($couponCode == $existCouponCode)
4810  {
4811  if (
4812  $existCouponData['ID'] > 0 || $existCouponData['TYPE'] == Internals\DiscountCouponTable::TYPE_BASKET_ROW
4813  )
4814  $found = true;
4815  }
4816  else
4817  {
4818  if (
4819  $existCouponData['TYPE'] != Internals\DiscountCouponTable::TYPE_BASKET_ROW
4820  || $couponData['TYPE'] != Internals\DiscountCouponTable::TYPE_BASKET_ROW
4821  )
4822  {
4823  $found = true;
4824  }
4825  else
4826  {
4827  if ($discount['MODULE_ID'] == 'sale')
4828  $found = true;
4829  }
4830  }
4831  unset($discount);
4832  if ($found)
4833  break;
4834  }
4835  unset($existCouponCode, $existCouponData);
4836  }
4837 
4838  if (!$found)
4839  $result[$couponCode] = $couponData;
4840  unset($found);
4841  }
4842  unset($couponCode, $couponData);
4843 
4844  return $result;
4845  }

◆ clearCurrentApplyBlock()

clearCurrentApplyBlock ( )
protected

Internal.

Fill current apply block empty data.

Возвращает
void

См. определение в файле discountbase.php строка 4395

4396  {
4397  $this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter] = $this->getEmptyApplyBlock();
4398  }
static getEmptyApplyBlock()
Return empty apply block.

◆ convertCoupon()

convertCoupon (   $coupon,
  $discount 
)
protected

Convert coupon for saving in order.

Аргументы
string | array$couponCoupon.
int$discountOrder discount id.
Возвращает
Result

См. определение в файле discountbase.php строка 3565

3566  {
3567  $result = new Result;
3568 
3569  /** @var DiscountCouponsManager $couponClassName */
3570  $couponClassName = $this->getDiscountCouponClassName();
3571 
3572  if (!is_array($coupon))
3573  {
3574  $couponData = $couponClassName::getEnteredCoupon($coupon, true);
3575  if (empty($couponData))
3576  {
3577  $result->addError(new Main\Entity\EntityError(
3578  Loc::getMessage('BX_SALE_DISCOUNT_ERR_COUPON_NOT_FOUND'),
3579  self::ERROR_ID
3580  ));
3581  return $result;
3582  }
3583  $coupon = array(
3584  'COUPON' => $couponData['COUPON'],
3585  'TYPE' => $couponData['TYPE'],
3586  'COUPON_ID' => $couponData['ID'],
3587  'DATA' => $couponData
3588  );
3589  unset($couponData);
3590  }
3591  $coupon['ORDER_DISCOUNT_ID'] = $discount;
3592  $coupon['ID'] = 0;
3593 
3594  $orderCouponId = $coupon['COUPON'];
3595  if (!isset($this->couponsCache[$orderCouponId]))
3596  $this->couponsCache[$orderCouponId] = $coupon;
3597  $result->setId($orderCouponId);
3598  $result->setData($coupon);
3599  unset($coupon, $orderCouponId);
3600  return $result;
3601  }

◆ convertDiscount()

convertDiscount (   $discount)
protected

Convert discount for saving in order.

Аргументы
array$discountRaw discount data.
Возвращает
Result

См. определение в файле discountbase.php строка 3509

3510  {
3511  $result = new Result;
3512 
3513  /** @var OrderDiscount $storageClassName */
3514  $storageClassName = $this->getOrderDiscountClassName();
3515 
3516  $discountResult = $storageClassName::saveDiscount($discount, false);
3517  if (!$discountResult->isSuccess())
3518  {
3519  $result->addErrors($discountResult->getErrors());
3520  unset($discountResult);
3521  return $result;
3522  }
3523  $orderDiscountId = $discountResult->getId();
3524  $discountData = $discountResult->getData();
3525  $resultData = array(
3526  'ORDER_DISCOUNT_ID' => $orderDiscountId,
3527  'USE_COUPONS' => $discountData['USE_COUPONS'],
3528  'MODULE_ID' => $discountData['MODULE_ID'],
3529  'DISCOUNT_ID' => $discountData['DISCOUNT_ID']
3530  );
3531  if (!isset($this->discountsCache[$orderDiscountId]))
3532  {
3533  $discountData['ACTIONS_DESCR_DATA'] = false;
3534  if (!empty($discountData['ACTIONS_DESCR']) && is_array($discountData['ACTIONS_DESCR']))
3535  {
3536  $discountData['ACTIONS_DESCR_DATA'] = $discountData['ACTIONS_DESCR'];
3537  $discountData['ACTIONS_DESCR'] = $this->formatDescription($discountData['ACTIONS_DESCR']);
3538  }
3539  else
3540  {
3541  $discountData['ACTIONS_DESCR'] = false;
3542  }
3543  if (empty($discountData['ACTIONS_DESCR']))
3544  {
3545  $discountData['ACTIONS_DESCR'] = false;
3546  $discountData['ACTIONS_DESCR_DATA'] = false;
3547  }
3548  $this->discountsCache[$orderDiscountId] = $discountData;
3549  }
3550 
3551  $result->setId($orderDiscountId);
3552  $result->setData($resultData);
3553  unset($discountData, $resultData, $orderDiscountId);
3554 
3555  return $result;
3556  }

◆ correctStepResult()

correctStepResult ( $stepResult,
  $discount 
)
protected

Correct data for exotic coupon.

Аргументы
array&$stepResultCurrenct discount result.
array$discountDiscount data.
Возвращает
void

См. определение в файле discountbase.php строка 3645

3646  {
3647  if ($discount['USE_COUPONS'] == 'Y' && !empty($discount['COUPON']))
3648  {
3649  if (
3650  $discount['COUPON']['TYPE'] == Internals\DiscountCouponTable::TYPE_BASKET_ROW &&
3651  (!empty($stepResult['BASKET']) && count($stepResult['BASKET']) > 1)
3652  )
3653  {
3654  $maxPrice = 0;
3655  $maxKey = -1;
3656  $basketKeys = array();
3657  foreach ($stepResult['BASKET'] as $key => $row)
3658  {
3659  $basketKeys[$key] = $key;
3660  if ($maxPrice < $this->currentStep['oldData']['BASKET_ITEMS'][$key]['PRICE'])
3661  {
3662  $maxPrice = $this->currentStep['oldData']['BASKET_ITEMS'][$key]['PRICE'];
3663  $maxKey = $key;
3664  }
3665  }
3666  unset($basketKeys[$maxKey]);
3667  foreach ($basketKeys as $key => $row)
3668  {
3669  unset($stepResult['BASKET'][$key]);
3670  $this->orderData['BASKET_ITEMS'][$row] = $this->currentStep['oldData']['BASKET_ITEMS'][$row];
3671  }
3672  unset($row, $key);
3673  }
3674  }
3675  }

◆ createClone()

createClone ( \SplObjectStorage  $cloneEntity)

Clone entity.

Переопределяется в Discount.

См. определение в файле discountbase.php строка 163

164  {
165  if ($this->isClone() && $cloneEntity->contains($this))
166  return $cloneEntity[$this];
167 
168  $discountClone = clone $this;
169  $discountClone->isClone = true;
170 
171  if (!$cloneEntity->contains($this))
172  $cloneEntity[$this] = $discountClone;
173 
174  if ($this->isOrderExists())
175  {
176  if ($cloneEntity->contains($this->order))
177  $discountClone->order = $cloneEntity[$this->order];
178  }
179  elseif ($this->isBasketExist())
180  {
181  if ($cloneEntity->contains($this->basket))
182  $discountClone->basket = $cloneEntity[$this->basket];
183  }
184 
185  return $discountClone;
186  }
isBasketExist()
Return exists basket.
isClone()
Returns true if discount entity is cloned.

◆ executeDiscountList()

executeDiscountList ( )
protected

Execute sale discount list.

Возвращает
Result

См. определение в файле discountbase.php строка 4593

4594  {
4595  $result = new Result;
4596 
4597  $roundApply = true;
4598  $saleDiscountOnly = $this->useOnlySaleDiscounts();
4599  $useMode = $this->getUseMode();
4600  if ($saleDiscountOnly)
4601  {
4602  if ($useMode == self::USE_MODE_FULL && $this->isRoundMode(self::ROUND_MODE_SALE_DISCOUNT))
4603  $roundApply = false;
4604  }
4605 
4606  $this->discountIds = array();
4607  if (empty($this->saleDiscountCacheKey) || empty($this->saleDiscountCache[$this->saleDiscountCacheKey]))
4608  {
4609  if (!$roundApply)
4610  {
4611  $this->roundFullBasketPriceByIndex(array(
4612  'DISCOUNT_INDEX' => -1,
4613  'DISCOUNT_ID' => 0
4614  ));
4615  }
4616  return $result;
4617  }
4618 
4619  $currentList = $this->saleDiscountCache[$this->saleDiscountCacheKey];
4620  $this->discountIds = array_keys($currentList);
4621  $this->extendOrderData();
4622 
4624 
4625  $blackList = array(
4626  self::getExecuteFieldName('UNPACK') => true,
4627  self::getExecuteFieldName('APPLICATION') => true,
4628  self::getExecuteFieldName('PREDICTIONS_APP') => true
4629  );
4630 
4631  $index = -1;
4632  $skipPriorityLevel = null;
4633  foreach ($currentList as $discountIndex => $discount)
4634  {
4635  if($skipPriorityLevel == $discount['PRIORITY'])
4636  {
4637  continue;
4638  }
4639  $skipPriorityLevel = null;
4640 
4641  $this->fillCurrentStep(array(
4642  'discount' => $discount,
4643  'cacheIndex' => $discountIndex
4644  ));
4645  if (!$this->checkDiscountConditions())
4646  continue;
4647 
4648  $index++;
4649  if (!$roundApply && $discount['EXECUTE_MODULE'] == 'sale')
4650  {
4651  $this->roundFullBasketPriceByIndex(array(
4652  'DISCOUNT_INDEX' => $index,
4653  'DISCOUNT_ID' => $discount['ID']
4654  ));
4655  $roundApply = true;
4656  }
4657 
4658  if ($useMode == self::USE_MODE_FULL && !isset($this->fullDiscountList[$discount['ID']]))
4659  $this->fullDiscountList[$discount['ID']] = array_diff_key($discount, $blackList);
4660 
4661  $actionsResult = $this->applySaleDiscount();
4662  if (!$actionsResult->isSuccess())
4663  {
4664  $result->addErrors($actionsResult->getErrors());
4665  unset($actionsResult);
4666  return $result;
4667  }
4668 
4669  if ($this->currentStep['stop'])
4670  break;
4671 
4672  if ($this->currentStep['stopLevel'])
4673  {
4674  $skipPriorityLevel = $discount['PRIORITY'];
4675  }
4676  }
4677  unset($discount, $currentList);
4678  $this->fillEmptyCurrentStep();
4679 
4680  if (!$roundApply)
4681  {
4682  $index++;
4683  $this->roundFullBasketPriceByIndex(array(
4684  'DISCOUNT_INDEX' => $index,
4685  'DISCOUNT_ID' => 0
4686  ));
4687  }
4688 
4689  return $result;
4690  }
checkDiscountConditions()
Check duscount conditions.
roundFullBasketPriceByIndex(array $index)
Round prices in sale discount mode for new order.
extendOrderData()
Extend order data for discounts.

◆ extendOrderData()

extendOrderData ( )
protected

Extend order data for discounts.

Возвращает
void

См. определение в файле discountbase.php строка 4438

4439  {
4440  if (empty($this->discountIds))
4441  return;
4442 
4443  $entityCacheKey = md5(serialize($this->discountIds));
4444  if (!isset($this->entityResultCache[$entityCacheKey]))
4445  {
4446  $this->entityResultCache[$entityCacheKey] = array();
4447  $this->entityList = RuntimeCache\DiscountCache::getInstance()->getDiscountEntities($this->discountIds);
4448  if (empty($this->entityList))
4449  return;
4450 
4451  $event = new Main\Event(
4452  'sale',
4453  self::EVENT_EXTEND_ORDER_DATA,
4454  array(
4455  'ORDER' => $this->orderData,
4456  'ENTITY' => $this->entityList
4457  )
4458  );
4459  $event->send();
4460  $this->entityResultCache[$entityCacheKey] = $event->getResults();
4461  }
4462  $resultList = $this->entityResultCache[$entityCacheKey];
4463  if (empty($resultList) || !is_array($resultList))
4464  return;
4465  /** @var Main\EventResult $eventResult */
4466  foreach ($resultList as &$eventResult)
4467  {
4468  if ($eventResult->getType() != Main\EventResult::SUCCESS)
4469  continue;
4470 
4471  $newData = $eventResult->getParameters();
4472  if (empty($newData) || !is_array($newData))
4473  continue;
4474 
4475  $this->modifyOrderData($newData);
4476  }
4477  unset($newData, $eventResult, $resultList);
4478  }
modifyOrderData(&$newData)
Modify order data from handlers.

◆ fillBasketLastDiscount()

fillBasketLastDiscount ( )
protected

Fill last discount flag for basket items.

Only for basket or new order or refreshed order.

Возвращает
void

См. определение в файле discountbase.php строка 4697

4698  {
4699  if ($this->getUseMode() != self::USE_MODE_FULL)
4700  return;
4701  $applyMode = self::getApplyMode();
4702  if ($applyMode == self::APPLY_MODE_ADD)
4703  return;
4704 
4705  $codeList = array_keys($this->orderData['BASKET_ITEMS']);
4706  switch ($applyMode)
4707  {
4710  foreach ($codeList as &$code)
4711  {
4712  if (isset($this->basketDiscountList[$code]) && !empty($this->basketDiscountList[$code]))
4713  $this->orderData['BASKET_ITEMS'][$code]['LAST_DISCOUNT'] = 'Y';
4714  }
4715  unset($code);
4716  break;
4717  case self::APPLY_MODE_LAST:
4719  foreach ($codeList as &$code)
4720  {
4721  if (!isset($this->basketDiscountList[$code]) || empty($this->basketDiscountList[$code]))
4722  continue;
4723  $lastDiscount = end($this->basketDiscountList[$code]);
4724  if (!empty($lastDiscount['LAST_DISCOUNT']) && $lastDiscount['LAST_DISCOUNT'] == 'Y')
4725  $this->orderData['BASKET_ITEMS'][$code]['LAST_DISCOUNT'] = 'Y';
4726  }
4727  unset($code);
4728  break;
4729  }
4730  unset($codeList, $applyMode);
4731  }
static getApplyMode()
Returns current sale discount apply mode.

◆ fillCurrentStep()

fillCurrentStep (   $data)
protected

Internal.

Fill current step data.

Аргументы
array$dataOnly not empty keys.
Возвращает
void

См. определение в файле discountbase.php строка 4422

4423  {
4424  $this->fillEmptyCurrentStep();
4425  if (!empty($data) && is_array($data))
4426  {
4427  foreach ($data as $key => $value)
4428  $this->currentStep[$key] = $value;
4429  unset($value, $key);
4430  }
4431  }

◆ fillDiscountResult()

fillDiscountResult ( )
protected

Fill result order data.

Возвращает
array

Переопределяется в Discount.

См. определение в файле discountbase.php строка 4367

4368  {
4369  $this->normalizeDiscountResult();
4370  $basketKeys = ['PRICE', 'DISCOUNT_PRICE', 'VAT_RATE', 'VAT_VALUE', 'CURRENCY'];
4371  $result = [
4372  'BASKET_ITEMS' => [],
4373  'CURRENCY' => $this->orderData['CURRENCY']
4374  ];
4375  foreach ($this->orderData['BASKET_ITEMS'] as $index => $basketItem)
4376  {
4377  $result['BASKET_ITEMS'][$index] = [];
4378  foreach ($basketKeys as $key)
4379  {
4380  if (isset($basketItem[$key]))
4381  $result['BASKET_ITEMS'][$index][$key] = $basketItem[$key];
4382  }
4383  unset($key);
4384  }
4385  unset($index, $basketItem);
4386 
4387  return $result;
4388  }
normalizeDiscountResult()
Round and correct discount calculation results.

◆ fillEmptyCurrentStep()

fillEmptyCurrentStep ( )
protected

Internal.

Clear current step data.

Возвращает
void

См. определение в файле discountbase.php строка 4404

4405  {
4406  $this->currentStep = array(
4407  'oldData' => array(),
4408  'discount' => array(),
4409  'discountIndex' => null,
4410  'discountId' => 0,
4411  'result' => array(),
4412  'stop' => false,
4413  );
4414  }

◆ fillEmptyDiscountResult()

fillEmptyDiscountResult ( )
protected

Fill empty discount result list.

Возвращает
void

Переопределяется в Discount.

См. определение в файле discountbase.php строка 4348

4349  {
4350  $this->discountResultCounter = 0;
4351  $this->discountResult = [
4352  'APPLY_BLOCKS' => [],
4353  'DISCOUNT_LIST' => [],
4354  'COUPON_LIST' => []
4355  ];
4356  $this->clearCurrentApplyBlock();
4357  $this->discountStoredActionData = [];
4358  $this->basketItemsData = [];
4359  $this->entityResultCache = [];
4360  }

◆ fillEmptyOrderData()

fillEmptyOrderData ( )
protected

Fill empty order data.

Возвращает
void

Переопределяется в Discount.

См. определение в файле discountbase.php строка 890

891  {
892  /** @var BasketBase $basket*/
893  $basket = $this->getBasket();
894  $siteId = $this->getSiteId();
895  $this->orderData = [
896  'ID' => 0,
897  'USER_ID' => $this->context->getUserId(),
898  'USER_GROUPS' => $this->context->getUserGroups(),
899  'SITE_ID' => $siteId,
900  'LID' => $siteId, // compatibility only
901  'ORDER_PRICE' => $basket->getPrice(),
902  'ORDER_WEIGHT' => $basket->getWeight(),
903  'CURRENCY' => $this->getCurrency(),
904  'PERSON_TYPE_ID' => 0,
905  'RECURRING_ID' => null,
906  'BASKET_ITEMS' => [],
907  'ORDER_PROP' => []
908  ];
909 
910  if ($this->isOrderExists())
911  {
912  $order = $this->getOrder();
913 
914  $this->orderData['ID'] = $order->getId();
915  $this->orderData['USER_ID'] = $order->getUserId();
916  $this->orderData['ORDER_PRICE'] = $order->getPrice();
917  $this->orderData['PERSON_TYPE_ID'] = $order->getPersonTypeId();
918  $this->orderData['RECURRING_ID'] = $order->getField('RECURRING_ID');
919 
920  /** @var \Bitrix\Sale\PropertyValueCollection $propertyCollection */
921  $propertyCollection = $order->getPropertyCollection();
922  /** @var \Bitrix\Sale\PropertyValue $orderProperty */
923  foreach ($propertyCollection as $orderProperty)
924  $this->orderData['ORDER_PROP'][$orderProperty->getPropertyId()] = $orderProperty->getValue();
925  unset($orderProperty);
926  foreach ($this->getOrderPropertyCodes() as $propertyCode => $attribute)
927  {
928  $this->orderData[$propertyCode] = '';
929  $orderProperty = $propertyCollection->getAttribute($attribute);
930  if ($orderProperty instanceof PropertyValue)
931  $this->orderData[$propertyCode] = $orderProperty->getValue();
932  unset($orderProperty);
933  }
934  unset($propertyCode, $attribute);
935  unset($propertyCollection);
936 
937  unset($order);
938  }
939  unset($siteId);
940  unset($basket);
941  }
static getOrderPropertyCodes()
Return order property codes for translate to order fields.
getSiteId()
Return site id for calculate.
getCurrency()
Return order currency for calculate.

◆ formatDescription()

static formatDescription (   $descr)
staticprotected

Return formatted discount description.

Аргументы
array$descrDescription.
Возвращает
array

См. определение в файле discountbase.php строка 4498

4499  {
4500  $result = array();
4501  if (empty($descr) || !is_array($descr))
4502  return $result;
4503  if (isset($descr['DELIVERY']))
4504  {
4505  $result['DELIVERY'] = array();
4506  foreach ($descr['DELIVERY'] as $index => $value)
4507  {
4508  if (!is_array($value))
4509  continue;
4510  $result['DELIVERY'][$index] = Discount\Formatter::formatRow($value);
4511  if ($result['DELIVERY'][$index] === null)
4512  unset($result['DELIVERY'][$index]);
4513  }
4514  unset($value, $index);
4515  if (!empty($result['DELIVERY']))
4516  $result['DELIVERY'] = implode(', ', $result['DELIVERY']);
4517  }
4518  if (isset($descr['BASKET']))
4519  {
4520  $result['BASKET'] = array();
4521  foreach ($descr['BASKET'] as $index => $value)
4522  {
4523  if (!is_array($value))
4524  continue;
4525  $result['BASKET'][$index] = Discount\Formatter::formatRow($value);
4526  if ($result['BASKET'][$index] === null)
4527  unset($result['BASKET'][$index]);
4528  }
4529  unset($value, $index);
4530  if (!empty($result['BASKET']))
4531  $result['BASKET'] = implode(', ', $result['BASKET']);
4532  }
4533  return $result;
4534  }
static formatRow(array $action)
Returns format action or result description.

◆ getAdditionalCoupons()

getAdditionalCoupons ( array  $filter = array())
protected

Return additional coupons for exist order.

См. определение в файле discountbase.php строка 4854

4855  {
4856  if ($this->useOnlySaleDiscounts())
4857  {
4858  if (isset($filter['MODULE_ID']) && $filter['MODULE_ID'] != 'sale')
4859  return array();
4860  if (isset($filter['!MODULE_ID']) && $filter['!MODULE_ID'] == 'sale')
4861  return array();
4862  $filter['MODULE_ID'] = 'sale';
4863  }
4864 
4865  /** @var DiscountCouponsManager $couponClassName */
4866  $couponClassName = $this->getDiscountCouponClassName();
4867 
4868  $useOrderCoupons = $couponClassName::isUsedOrderCouponsForApply();
4869  $couponClassName::useSavedCouponsForApply(false);
4870  $coupons = $couponClassName::getForApply($filter, array(), true);
4871  $couponClassName::useSavedCouponsForApply($useOrderCoupons);
4872  unset($useOrderCoupons);
4873 
4874  if (empty($coupons))
4875  return array();
4876 
4877  return $this->clearAdditionalCoupons($coupons);
4878  }
clearAdditionalCoupons(array $coupons)
Clear coupons from already used discounts.

◆ getAllowedBasketCodeList()

getAllowedBasketCodeList ( )
protected

См. определение в файле discountbase.php строка 4296

4297  {
4298  $result = [];
4299  if (empty($this->orderData['BASKET_ITEMS']))
4300  return $result;
4301 
4302  foreach ($this->orderData['BASKET_ITEMS'] as $code => $item)
4303  {
4304  if ($this->isFreezedBasketItem($item))
4305  continue;
4306  $result[] = $code;
4307  }
4308  unset($code, $item);
4309 
4310  return $result;
4311  }
static isFreezedBasketItem(array $item)
Returns true, if allowed apply discounts to basket item.

◆ getApplyDiscounts()

getApplyDiscounts ( )
protected

Returns discount and coupon list.

Возвращает
void

См. определение в файле discountbase.php строка 3734

3735  {
3736  $discountApply = array();
3737  $couponApply = array();
3738 
3739  if (!empty($this->discountsCache))
3740  {
3741  foreach ($this->discountsCache as $id => $discount)
3742  {
3743  $this->discountResult['DISCOUNT_LIST'][$id] = array(
3744  'ID' => $id,
3745  'NAME' => $discount['NAME'],
3746  'MODULE_ID' => $discount['MODULE_ID'],
3747  'DISCOUNT_ID' => $discount['ID'],
3748  'REAL_DISCOUNT_ID' => $discount['DISCOUNT_ID'],
3749  'USE_COUPONS' => $discount['USE_COUPONS'],
3750  'ACTIONS_DESCR' => $discount['ACTIONS_DESCR'],
3751  'ACTIONS_DESCR_DATA' => $discount['ACTIONS_DESCR_DATA'],
3752  'APPLY' => 'N',
3753  'EDIT_PAGE_URL' => $discount['EDIT_PAGE_URL']
3754  );
3755  $discountApply[$id] = &$this->discountResult['DISCOUNT_LIST'][$id];
3756  }
3757  unset($id, $discount);
3758  }
3759 
3760  if (!empty($this->couponsCache))
3761  {
3762  foreach ($this->couponsCache as $id => $coupon)
3763  {
3764  $this->discountResult['COUPON_LIST'][$id] = $coupon;
3765  $this->discountResult['COUPON_LIST'][$id]['APPLY'] = 'N';
3766  $couponApply[$id] = &$this->discountResult['COUPON_LIST'][$id];
3767  }
3768  unset($id, $coupon);
3769  }
3770 
3771  if (empty($this->discountResult['APPLY_BLOCKS']))
3772  {
3773  unset($discountApply, $couponApply);
3774  return;
3775  }
3776 
3777  foreach ($this->discountResult['APPLY_BLOCKS'] as $counter => $applyBlock)
3778  {
3779  if (!empty($applyBlock['BASKET']))
3780  {
3781  foreach ($applyBlock['BASKET'] as $basketCode => $discountList)
3782  {
3783  foreach ($discountList as $discount)
3784  {
3785  if ($discount['RESULT']['APPLY'] == 'Y')
3786  {
3787  if (isset($discountApply[$discount['DISCOUNT_ID']]))
3788  $discountApply[$discount['DISCOUNT_ID']]['APPLY'] = 'Y';
3789  if (isset($couponApply[$discount['COUPON_ID']]))
3790  $couponApply[$discount['COUPON_ID']]['APPLY'] = 'Y';
3791  }
3792  }
3793  unset($discount);
3794  }
3795  unset($basketCode, $discountList);
3796  }
3797 
3798  if (!empty($applyBlock['ORDER']))
3799  {
3800  foreach ($applyBlock['ORDER'] as $discount)
3801  {
3802  if (!empty($discount['RESULT']['BASKET']))
3803  {
3804  foreach ($discount['RESULT']['BASKET'] as $basketCode => $applyList)
3805  {
3806  if ($applyList['APPLY'] == 'Y')
3807  {
3808  if (isset($discountApply[$discount['DISCOUNT_ID']]))
3809  $discountApply[$discount['DISCOUNT_ID']]['APPLY'] = 'Y';
3810  if (isset($couponApply[$discount['COUPON_ID']]))
3811  $couponApply[$discount['COUPON_ID']]['APPLY'] = 'Y';
3812  }
3813  }
3814  unset($basketCode, $applyList);
3815  }
3816  if (!empty($discount['RESULT']['DELIVERY']) && $discount['RESULT']['DELIVERY']['APPLY'] == 'Y')
3817  {
3818  if (isset($discountApply[$discount['DISCOUNT_ID']]))
3819  $discountApply[$discount['DISCOUNT_ID']]['APPLY'] = 'Y';
3820  if (isset($couponApply[$discount['COUPON_ID']]))
3821  $couponApply[$discount['COUPON_ID']]['APPLY'] = 'Y';
3822  }
3823  }
3824  unset($discount);
3825  }
3826  }
3827  unset($counter, $applyBlock);
3828 
3829  unset($discountApply, $couponApply);
3830  }

◆ getApplyMode()

static getApplyMode ( )
static

Returns current sale discount apply mode.

Возвращает
int
Исключения
Main

См. определение в файле discountbase.php строка 418

419  {
420  $applyMode = self::APPLY_MODE_ADD;
421  if ((string)Main\Config\Option::get('sale', 'use_sale_discount_only') != 'Y')
422  {
423  $applyMode = (int)Main\Config\Option::get('sale', 'discount_apply_mode');
424  if (!in_array($applyMode, self::getApplyModeList(false)))
425  $applyMode = self::APPLY_MODE_ADD;
426  }
427  return $applyMode;
428  }

◆ getApplyModeList()

static getApplyModeList (   $extendedMode = false)
static

Return apply mode list.

Аргументы
bool$extendedModeGet mode list with names.
Возвращает
array

См. определение в файле discountbase.php строка 390

391  {
392  $extendedMode = ($extendedMode === true);
393  if ($extendedMode)
394  {
395  return array(
396  self::APPLY_MODE_ADD => Loc::getMessage('BX_SALE_DISCOUNT_APPLY_MODE_ADD_EXT'),
397  self::APPLY_MODE_LAST => Loc::getMessage('BX_SALE_DISCOUNT_APPLY_MODE_LAST_EXT'),
398  self::APPLY_MODE_DISABLE => Loc::getMessage('BX_SALE_DISCOUNT_APPLY_MODE_DISABLE_EXT'),
399  self::APPLY_MODE_FULL_LAST => Loc::getMessage('BX_SALE_DISCOUNT_APPLY_MODE_FULL_LAST'),
400  self::APPLY_MODE_FULL_DISABLE => Loc::getMessage('BX_SALE_DISCOUNT_APPLY_MODE_FULL_DISABLE')
401  );
402  }
403  return array(
404  self::APPLY_MODE_ADD,
405  self::APPLY_MODE_LAST,
406  self::APPLY_MODE_DISABLE,
407  self::APPLY_MODE_FULL_LAST,
408  self::APPLY_MODE_FULL_DISABLE
409  );
410  }

◆ getApplyPrices()

getApplyPrices ( )
protected

Fill prices in apply results.

Возвращает
void

Переопределяется в Discount.

См. определение в файле discountbase.php строка 3837

3838  {
3839  $this->normalizeDiscountResult();
3840 
3841  $basket = [];
3842  if (!empty($this->orderData['BASKET_ITEMS']))
3843  {
3844  foreach ($this->orderData['BASKET_ITEMS'] as $basketCode => $basketItem)
3845  {
3846  $basket[$basketCode] = [
3847  'BASE_PRICE' => $basketItem['BASE_PRICE'],
3848  'PRICE' => $basketItem['PRICE'],
3849  'DISCOUNT' => $basketItem['DISCOUNT_PRICE']
3850  ];
3851  }
3852  unset($basketCode, $basketItem);
3853  }
3854 
3855  $this->discountResult['PRICES'] = [
3856  'BASKET' => $basket
3857  ];
3858  unset($basket);
3859  }

◆ getApplyResult()

getApplyResult (   $extMode = false)

Return discount list description.

Аргументы
bool$extModeExtended mode.
Возвращает
array

Переопределяется в Discount.

См. определение в файле discountbase.php строка 551

552  {
553  $extMode = ($extMode === true);
554 
555  if (!$this->isOrderNew() && !$this->isLoaded())
556  {
557  $this->initUseMode();
558  $this->loadOrderData();
559  }
560 
561  $this->getApplyDiscounts();
562  $this->getApplyPrices();
563  if ($extMode)
564  $this->remakingDiscountResult();
565 
566  $result = $this->discountResult;
567  $result['FULL_DISCOUNT_LIST'] = $this->fullDiscountList;
568 
569  if ($extMode)
570  unset($result['APPLY_BLOCKS']);
571 
572  return $result;
573  }
isLoaded()
Returns true if the data for calculations is loaded.
remakingDiscountResult()
Change result format.
getApplyPrices()
Fill prices in apply results.
getApplyDiscounts()
Returns discount and coupon list.

◆ getBasket()

getBasket ( )
protected

Return current basket.

Возвращает
BasketBase

См. определение в файле discountbase.php строка 774

775  {
776  if ($this->isOrderExists())
777  return $this->getOrder()->getBasket();
778  else
779  return $this->basket;
780  }

◆ getBasketCodes()

getBasketCodes (   $full = true)
protected

Returns basket codes for calculate.

Аргументы
bool$fullFull or apply mode.
Возвращает
array

См. определение в файле discountbase.php строка 4232

4233  {
4234  $result = [];
4235  if (empty($this->orderData['BASKET_ITEMS']))
4236  return $result;
4237  switch ($this->getUseMode())
4238  {
4239  case self::USE_MODE_FULL:
4241  foreach ($this->orderData['BASKET_ITEMS'] as $code => $item)
4242  {
4243  if ($this->isFreezedBasketItem($item))
4244  continue;
4245  $result[] = $code;
4246  }
4247  unset($code, $item);
4248  break;
4249  case self::USE_MODE_APPLY:
4250  foreach ($this->orderData['BASKET_ITEMS'] as $code => $item)
4251  {
4252  if (
4253  $this->isFreezedBasketItem($item)
4254  || $this->isNewBasketItem($item)
4255  || $this->isBasketItemChanged($code)
4256  )
4257  continue;
4258  $result[] = $code;
4259  }
4260  unset($code, $item);
4261  break;
4262  case self::USE_MODE_MIXED:
4263  $full = ($full === true);
4264  if ($full)
4265  {
4266  foreach ($this->orderData['BASKET_ITEMS'] as $code => $item)
4267  {
4268  if (
4269  !$this->isFreezedBasketItem($item)
4270  && ($this->isNewBasketItem($item) || $this->isBasketItemChanged($code))
4271  )
4272  $result[] = $code;
4273  }
4274  unset($code, $item);
4275  }
4276  else
4277  {
4278  foreach ($this->orderData['BASKET_ITEMS'] as $code => $item)
4279  {
4280  if (
4281  $this->isFreezedBasketItem($item)
4282  || $this->isNewBasketItem($item)
4283  || $this->isBasketItemChanged($code)
4284  )
4285  continue;
4286  $result[] = $code;
4287  }
4288  unset($code, $item);
4289  }
4290  break;
4291  }
4292 
4293  return $result;
4294  }
static isNewBasketItem(array $item)
Returns check new basket item for basket item.
isBasketItemChanged($code)
Return true if ordered basket item changed (change PRODUCT_ID).

◆ getBasketItemFields()

getBasketItemFields ( BasketItemBase  $basketItem)
protected

Returns array with basket item field values.

Аргументы
BasketItemBase$basketItemBasket collection item.
Возвращает
array

См. определение в файле discountbase.php строка 978

979  {
980  $item = $basketItem->getFieldValues();
981  $item['BASE_PRICE'] = $basketItem->getField('BASE_PRICE');
982  unset($item['DATE_INSERT']);
983  unset($item['DATE_UPDATE']);
984  unset($item['DATE_REFRESH']);
985  $item['PROPERTIES'] = $basketItem->getPropertyCollection()->getPropertyValues();
986  if (!isset($item['DISCOUNT_PRICE']))
987  $item['DISCOUNT_PRICE'] = 0;
988  if ($item['BASE_PRICE'] === null)
989  $item['BASE_PRICE'] = $item['PRICE'] + $item['DISCOUNT_PRICE'];
990  $item['ACTION_APPLIED'] = 'N';
991  return $item;
992  }

◆ getBasketItemValue()

getBasketItemValue (   $code,
  $field 
)
protected

Return basket item data value from provider.

См. определение в файле discountbase.php строка 1249

1250  {
1251  if (!isset($this->basketItemsData[$code]))
1252  return null;
1253  return (isset($this->basketItemsData[$code][$field]) ? $this->basketItemsData[$code][$field] : null);
1254  }

◆ getBasketItemValueList()

getBasketItemValueList (   $code,
array  $fields 
)
protected

Return basket item data from provider.

См. определение в файле discountbase.php строка 1264

1265  {
1266  if (!isset($this->basketItemsData[$code]) || empty($fields))
1267  return null;
1268 
1269  $result = array();
1270  foreach ($fields as $fieldName)
1271  {
1272  $result[$fieldName] = (
1273  isset($this->basketItemsData[$code][$fieldName])
1274  ? $this->basketItemsData[$code][$fieldName]
1275  : null
1276  );
1277  }
1278  unset($fieldName);
1279  return $result;
1280  }

◆ getBasketTables()

getBasketTables ( )
protected

Create correspondence between basket ids and basket codes.

Возвращает
Result

См. определение в файле discountbase.php строка 3932

3933  {
3934  $result = new Result;
3935 
3936  $this->forwardBasketTable = array();
3937  $this->reverseBasketTable = array();
3938 
3939  if (!$this->isBasketNotEmpty())
3940  return $result;
3941 
3942  $basket = $this->getBasket();
3943  /** @var BasketItem $basketItem */
3944  foreach ($basket as $basketItem)
3945  {
3946  $code = $basketItem->getBasketCode();
3947  $id = $basketItem->getField('ID');
3948  $this->forwardBasketTable[$code] = $id;
3949  $this->reverseBasketTable[$id] = $code;
3950  unset($id, $code);
3951 
3952  if ($basketItem->isBundleParent())
3953  {
3954  $bundle = $basketItem->getBundleCollection();
3955  if (empty($bundle))
3956  {
3957  $result->addError(new Main\Entity\EntityError(
3958  Loc::getMessage('BX_SALE_DISCOUNT_ERR_BASKET_BUNDLE_EMPTY'),
3959  self::ERROR_ID
3960  ));
3961  break;
3962  }
3963  /** @var BasketItem $bundleItem */
3964  foreach ($bundle as $bundleItem)
3965  {
3966  $code = $bundleItem->getBasketCode();
3967  $id = $bundleItem->getField('ID');
3968  $this->forwardBasketTable[$code] = $id;
3969  $this->reverseBasketTable[$id] = $code;
3970  unset($id, $code);
3971  }
3972  unset($bundle, $bundleItem);
3973  }
3974  }
3975  unset($basketItem, $basket);
3976 
3977  return $result;
3978  }

◆ getConditionField()

getConditionField ( )
protected

Return field with discount condition code.

Переопределяется в Discount.

См. определение в файле discountbase.php строка 5353

5354  {
5355  return 'UNPACK';
5356  }

◆ getCurrency()

getCurrency ( )
protected

Return order currency for calculate.

См. определение в файле discountbase.php строка 5278

5279  {
5280  if ($this->isOrderExists())
5281  return $this->order->getCurrency();
5282  $result = null;
5283  if ($this->isBasketExist())
5284  {
5285  if ($this->isBasketNotEmpty())
5286  {
5287  /** @var BasketItemBase $basketItem */
5288  $basketItem = $this->basket->rewind();
5289  $result = $basketItem->getCurrency();
5290  unset($basketItem);
5291  }
5292  else
5293  {
5294  $result = $this->getSiteCurrency();
5295  }
5296  }
5297  return $result;
5298  }
getSiteCurrency()
Return site currency.

◆ getDiscountCouponClassName()

getDiscountCouponClassName ( )
protected

Returns current discount coupons manager class name.

Возвращает
string
Исключения
Main

См. определение в файле discountbase.php строка 5549

5550  {
5551  $registry = Registry::getInstance(static::getRegistryType());
5552  return $registry->getDiscountCouponClassName();
5553  }

◆ getDiscountStoredActionData()

getDiscountStoredActionData (   $orderDiscountId)
protected

Returns stored action data for discount.

Аргументы
int$orderDiscountIdConverted discount id.
Возвращает
array|null

См. определение в файле discountbase.php строка 3705

3706  {
3707  $orderDiscountId = (int)$orderDiscountId;
3708  if (isset($this->discountStoredActionData[$this->discountResultCounter][$orderDiscountId]))
3709  return $this->discountStoredActionData[$this->discountResultCounter][$orderDiscountId];
3710  return null;
3711  }

◆ getEmptyApplyBlock()

static getEmptyApplyBlock ( )
static

Return empty apply block.

Возвращает
array

См. определение в файле discountbase.php строка 5665

5666  {
5667  return array(
5668  'BASKET' => array(),
5669  'BASKET_ROUND' => array(),
5670  'ORDER' => array()
5671  );
5672  }

◆ getEntitySaveIdentifier()

getEntitySaveIdentifier ( array  $entity)
protected

Returns data for save to database.

Аргументы
array$entity
Возвращает
array|null

Переопределяется в Discount.

См. определение в файле discountbase.php строка 3986

3987  {
3988  $result = null;
3989 
3990  switch ($entity['ENTITY_TYPE'])
3991  {
3993  $basketCode = $entity['ENTITY_CODE'];
3994  if (isset($this->forwardBasketTable[$basketCode]))
3995  {
3996  $result = [
3997  'ENTITY_TYPE' => self::ENTITY_BASKET_ITEM,
3998  'ENTITY_ID' => (int)$this->forwardBasketTable[$basketCode],
3999  'ENTITY_VALUE' => (string)$this->forwardBasketTable[$basketCode]
4000  ];
4001  }
4002  unset($basketCode);
4003  break;
4004  case self::ENTITY_ORDER:
4005  $result = [
4006  'ENTITY_TYPE' => self::ENTITY_ORDER,
4007  'ENTITY_ID' => (int)$entity['ENTITY_CODE'],
4008  'ENTITY_VALUE' => (string)$entity['ENTITY_CODE']
4009  ];
4010  break;
4011  }
4012 
4013  return $result;
4014  }

◆ getExecuteFieldList()

getExecuteFieldList ( )
protected

Return field list for eval.

Переопределяется в Discount.

См. определение в файле discountbase.php строка 5341

5342  {
5343  return ['UNPACK', 'APPLICATION'];
5344  }

◆ getExecuteFieldName()

static getExecuteFieldName (   $fieldName)
staticfinalprotected

Return field name for save eval result.

Only for core.

См. определение в файле discountbase.php строка 5329

5330  {
5331  return self::EXECUTE_FIELD_PREFIX.$fieldName;
5332  }

◆ getInstance()

static getInstance (   $index)
staticprotected

Returns discount instance.

Аргументы
string$indexEntity instance identifier.
Возвращает
DiscountBase

См. определение в файле discountbase.php строка 5162

5163  {
5164  $className = get_called_class();
5165  if (!isset(self::$instances[$className]))
5166  self::$instances[$className] = array();
5167  if (!isset(self::$instances[$className][$index]))
5168  self::$instances[$className][$index] = self::createObject();
5169 
5170  return self::$instances[$className][$index];
5171  }

◆ getInstanceIndexByBasket()

static getInstanceIndexByBasket ( BasketBase  $basket,
Context\BaseContext  $context = null 
)
staticprotected

Return instance index for basket.

См. определение в файле discountbase.php строка 5228

5229  {
5230  if (!$context)
5231  return '0|'.$basket->getFUserId(false).'|'.$basket->getSiteId();
5232  return '0|-1|'.$basket->getSiteId().'|'.$context->getUserGroupsHash();
5233  }

◆ getInstanceIndexByOrder()

static getInstanceIndexByOrder ( OrderBase  $order)
staticprotected

Return instance index for order.

См. определение в файле discountbase.php строка 5213

5214  {
5215  return $order->getInternalId().'|0'.'|'.$order->getSiteId();
5216  }

◆ getModuleSettings()

getModuleSettings ( )
protected

Returns the current module settings required for calculating discounts.

Возвращает
array
Исключения
Main

См. определение в файле discountbase.php строка 1036

1037  {
1038  return array(
1039  'USE_BASE_PRICE' => Main\Config\Option::get('sale', 'get_discount_percent_from_base_price'),
1040  'SALE_DISCOUNT_ONLY' => Main\Config\Option::get('sale', 'use_sale_discount_only'),
1041  'APPLY_MODE' => Main\Config\Option::get('sale', 'discount_apply_mode')
1042  );
1043  }

◆ getOrder()

getOrder ( )

Return order.

Возвращает
OrderBase|null

См. определение в файле discountbase.php строка 5242

5243  {
5244  return $this->order;
5245  }

◆ getOrderConfig()

getOrderConfig ( )
protected

Returns order configuration for save to database.

Возвращает
array

Переопределяется в Discount.

См. определение в файле discountbase.php строка 1630

1631  {
1632  return array(
1633  'OPTIONS' => $this->saleOptions,
1634  );
1635  }

◆ getOrderDiscountClassName()

getOrderDiscountClassName ( )
protected

Returns current order discount class name.

Возвращает
string
Исключения
Main

См. определение в файле discountbase.php строка 5535

5536  {
5537  $registry = Registry::getInstance(static::getRegistryType());
5538  return $registry->getOrderDiscountClassName();
5539  }

◆ getOrderPropertyCodes()

static getOrderPropertyCodes ( )
staticprotected

Return order property codes for translate to order fields.

Возвращает
array

См. определение в файле discountbase.php строка 5620

5621  {
5622  return [
5623  'DELIVERY_LOCATION' => 'IS_LOCATION',
5624  'USER_EMAIL' => 'IS_EMAIL',
5625  'PAYER_NAME' => 'IS_PAYER',
5626  'PROFILE_NAME' => 'IS_PROFILE_NAME',
5627  'DELIVERY_LOCATION_ZIP' => 'IS_ZIP'
5628  ];
5629  }

◆ getRegistryType()

static getRegistryType ( )
static

Return parent entity type.

The method must be overridden in the derived class.

Переопределяется в Discount.

См. определение в файле discountbase.php строка 5201

5202  {
5203  throw new Main\NotImplementedException();
5204  }

◆ getRoundIndex()

getRoundIndex (   $entity,
  $applyCounter = null 
)
protected

Return index data for use round.

См. определение в файле discountbase.php строка 3240

3241  {
3242  if (!$this->isRoundMode(self::ROUND_MODE_SALE_DISCOUNT))
3243  return null;
3244  if ($applyCounter === null)
3245  $applyCounter = $this->discountResultCounter;
3246  return (isset($this->roundApplyConfig[$applyCounter][$entity]) ? $this->roundApplyConfig[$applyCounter][$entity] : null);
3247  }

◆ getRoundMode()

getRoundMode ( )
protected

Return order round apply mode.

См. определение в файле discountbase.php строка 3151

3152  {
3153  return $this->roundApplyMode;
3154  }

◆ getShipmentClassName()

getShipmentClassName ( )
protected

Return current shipment class name.

Возвращает
string
Исключения
Main

См. определение в файле discountbase.php строка 5563

5564  {
5565  $registry = Registry::getInstance(static::getRegistryType());
5566  return $registry->getShipmentClassName();
5567  }

◆ getShowPrices()

getShowPrices ( )

Returns show prices for public components.

Возвращает
array

Переопределяется в Discount.

См. определение в файле discountbase.php строка 5701

5702  {
5703  if (!$this->isOrderNew() && !$this->isLoaded())
5704  {
5705  $this->initUseMode();
5706  $this->loadOrderData();
5707  }
5708 
5709  $result = [
5710  'BASKET' => []
5711  ];
5712 
5713  $checkRound = true;
5714  $useMode = $this->getUseMode();
5715  switch ($useMode)
5716  {
5717  case self::USE_MODE_APPLY:
5718  case self::USE_MODE_MIXED:
5719  if (!$this->isValidState())
5720  $checkRound = false;
5721  break;
5722  }
5723 
5724  if (!empty($this->orderData['BASKET_ITEMS']))
5725  {
5726  /** @var OrderDiscount $storageClassName */
5727  $storageClassName = $this->getOrderDiscountClassName();
5728 
5729  $basket = $this->orderData['BASKET_ITEMS'];
5731  unset($order['BASKET_ITEMS']);
5732 
5733  switch ($useMode)
5734  {
5735  case self::USE_MODE_FULL:
5736  case self::USE_MODE_APPLY:
5737  if ($checkRound)
5738  {
5739  $basketCodeList = $this->getBasketCodes(true);
5740  $existRound = array();
5741  $existRoundRules = array();
5742  foreach ($basketCodeList as $basketCode)
5743  {
5744  if (!empty($this->basketItemsData[$basketCode]['BASE_PRICE_ROUND_RULE']))
5745  {
5746  $existRound[$basketCode] = self::resetBasketItemPrice($basket[$basketCode]);
5747  $existRoundRules[$basketCode] = $this->basketItemsData[$basketCode]['BASE_PRICE_ROUND_RULE'];
5748  }
5749  }
5750  if (!empty($existRound))
5751  {
5752  $roundResult = $storageClassName::roundBasket(
5753  $existRound,
5754  $existRoundRules,
5755  $order
5756  );
5757  foreach ($roundResult as $basketCode => $row)
5758  {
5759  if (empty($row) || !is_array($row))
5760  continue;
5761  if (!isset($existRound[$basketCode]))
5762  continue;
5763  $basket[$basketCode]['BASE_PRICE'] = $row['PRICE'];
5764  $basket[$basketCode]['DISCOUNT_PRICE'] = $basket[$basketCode]['BASE_PRICE'] - $basket[$basketCode]['PRICE'];
5765  }
5766  }
5767  unset($existRoundRules, $existRound);
5768  }
5769  break;
5770  case self::USE_MODE_MIXED:
5771  if ($checkRound)
5772  {
5773  $existRound = array();
5774  $existRoundRules = array();
5775  foreach ($basket as $basketCode => $item)
5776  {
5777  if ($this->isFreezedBasketItem($item))
5778  continue;
5779  if (!empty($this->basketItemsData[$basketCode]['BASE_PRICE_ROUND_RULE']))
5780  {
5781  $existRound[$basketCode] = self::resetBasketItemPrice($basket[$basketCode]);
5782  $existRoundRules[$basketCode] = $this->basketItemsData[$basketCode]['BASE_PRICE_ROUND_RULE'];
5783  }
5784  }
5785  unset($code, $item);
5786  if (!empty($existRound))
5787  {
5788  $roundResult = $storageClassName::roundBasket(
5789  $existRound,
5790  $existRoundRules,
5791  $order
5792  );
5793  foreach ($roundResult as $basketCode => $row)
5794  {
5795  if (empty($row) || !is_array($row))
5796  continue;
5797  if (!isset($existRound[$basketCode]))
5798  continue;
5799  $basket[$basketCode]['BASE_PRICE'] = $row['PRICE'];
5800  $basket[$basketCode]['DISCOUNT_PRICE'] = $basket[$basketCode]['BASE_PRICE'] - $basket[$basketCode]['PRICE'];
5801  }
5802  }
5803  unset($existRoundRules, $existRound);
5804  }
5805  break;
5806  }
5807 
5808  foreach ($basket as $basketCode => $basketItem)
5809  {
5810  $result['BASKET'][$basketCode] = $this->getShowBasketItemPrice($basketCode, $basketItem);
5811  $result['BASKET'][$basketCode]['REAL_BASE_PRICE'] = $this->orderData['BASKET_ITEMS'][$basketCode]['BASE_PRICE'];
5812  $result['BASKET'][$basketCode]['REAL_PRICE'] = $this->orderData['BASKET_ITEMS'][$basketCode]['PRICE'];
5813  $result['BASKET'][$basketCode]['REAL_DISCOUNT'] = $this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_PRICE'];
5814  }
5815  unset($basketCode, $basketItem);
5816  }
5817 
5818  return $result;
5819  }

◆ getSiteCurrency()

getSiteCurrency ( )
protected

Return site currency.

См. определение в файле discountbase.php строка 5306

5307  {
5309  if (is_array($result))
5310  return $result['CURRENCY'];
5311  $result = (string)Main\Config\Option::get('sale', 'default_currency');
5312  if ($result !== '')
5313  return $result;
5315  if ($result !== '')
5316  return $result;
5317  return null;
5318  }
static getBaseCurrency()
Return base currency.
static getCurrency($siteId)
Returns site currency data.

◆ getSiteId()

getSiteId ( )
protected

Return site id for calculate.

См. определение в файле discountbase.php строка 5263

5264  {
5265  if ($this->isOrderExists())
5266  return $this->order->getSiteId();
5267  if ($this->isBasketExist())
5268  return $this->basket->getSiteId();
5269  return null;
5270  }

◆ getStatusApplyBasketDiscount()

getStatusApplyBasketDiscount (   $basketCode,
  $orderDiscountId,
  $orderCouponId 
)
protected

Return apply status for basket discount.

См. определение в файле discountbase.php строка 5078

5079  {
5080  $disable = false;
5081  if (
5082  $orderCouponId != ''
5083  && !empty($this->applyResult['COUPON_LIST'][$orderCouponId])
5084  && $this->applyResult['COUPON_LIST'][$orderCouponId] == 'N'
5085  )
5086  {
5087  $disable = true;
5088  }
5089  else
5090  {
5091  if (
5092  !empty($this->applyResult['DISCOUNT_LIST'][$orderDiscountId])
5093  && $this->applyResult['DISCOUNT_LIST'][$orderDiscountId] == 'N'
5094  )
5095  {
5096  $disable = true;
5097  }
5098  if (!empty($this->applyResult['BASKET'][$basketCode]))
5099  {
5100  if (is_string($this->applyResult['BASKET'][$basketCode]))
5101  $disable = ($this->applyResult['BASKET'][$basketCode] == 'N');
5102  elseif (!empty($this->applyResult['BASKET'][$basketCode][$orderDiscountId]))
5103  $disable = ($this->applyResult['BASKET'][$basketCode][$orderDiscountId] == 'N');
5104  }
5105  }
5106  return !$disable;
5107  }

◆ getStepResult()

static getStepResult ( array  $order)
staticprotected

Returns result after one discount.

Аргументы
array$orderOrder current data.
Возвращает
array

Переопределяется в Discount.

См. определение в файле discountbase.php строка 3609

3610  {
3611  $result = array();
3612  $stepResult = &$order['DISCOUNT_RESULT'];
3613  if (!empty($stepResult['BASKET']) && is_array($stepResult['BASKET']))
3614  {
3615  if (!isset($result['BASKET']))
3616  $result['BASKET'] = array();
3617  foreach ($stepResult['BASKET'] as $basketCode => $basketResult)
3618  {
3619  $result['BASKET'][$basketCode] = array(
3620  'APPLY' => 'Y',
3621  'DESCR' => Discount\Formatter::formatList($basketResult),
3622  'DESCR_DATA' => $basketResult,
3623  'MODULE' => $order['BASKET_ITEMS'][$basketCode]['MODULE'],
3624  'PRODUCT_ID' => $order['BASKET_ITEMS'][$basketCode]['PRODUCT_ID'],
3625  'BASKET_ID' => (isset($order['BASKET_ITEMS'][$basketCode]['ID']) ? $order['BASKET_ITEMS'][$basketCode]['ID'] : $basketCode),
3626  'ACTION_BLOCK_LIST' => array_keys($basketResult)
3627  );
3628  if (is_array($result['BASKET'][$basketCode]['DESCR']))
3629  $result['BASKET'][$basketCode]['DESCR'] = implode(', ', $result['BASKET'][$basketCode]['DESCR']);
3630  }
3631  unset($basketCode, $basketResult);
3632  }
3633  unset($stepResult);
3634 
3635  return $result;
3636  }

◆ getUseMode()

getUseMode ( )

Return calculate mode.

Возвращает
int

См. определение в файле discountbase.php строка 367

368  {
369  return $this->useMode;
370  }

◆ initInstanceData()

initInstanceData ( )
protected

Initial instance data.

Возвращает
void

См. определение в файле discountbase.php строка 714

715  {
716  $this->orderData = null;
717  $this->isClone = false;
718  $this->entityResultCache = array();
719  $this->setNewOrder();
720  $this->fillEmptyDiscountResult();
721 
722  $orderDiscountConfig = array(
723  'SITE_ID' => $this->getSiteId(),
724  'CURRENCY' => $this->getCurrency()
725  );
726  /** @var OrderDiscount $storageClassName */
727  $storageClassName = $this->getOrderDiscountClassName();
728  $storageClassName::setManagerConfig($orderDiscountConfig);
729  unset($storageClassName, $orderDiscountConfig);
730  }
setNewOrder()
Set new order flag.

◆ initInstanceFromOrder()

initInstanceFromOrder ( )
protected

Initial instance data after set order.

Возвращает
void

Переопределяется в Discount.

См. определение в файле discountbase.php строка 737

738  {
739  $this->setNewOrder();
740  }

◆ initUseMode()

initUseMode ( )
protected

Initialization of the discount calculation mode.

Возвращает
void

См. определение в файле discountbase.php строка 820

821  {
822  $this->setUseMode(self::USE_MODE_FULL);
823  if ($this->isOrderExists() && !$this->isOrderNew())
824  {
825  if ($this->isOrderRefresh())
826  $this->setUseMode(self::USE_MODE_FULL);
827  elseif ($this->isOrderChanged())
828  $this->setUseMode(self::USE_MODE_MIXED);
829  elseif ($this->getOrder()->getCalculateType() == $this->getOrder()::SALE_ORDER_CALC_TYPE_REFRESH)
830  $this->setUseMode(self::USE_MODE_FULL);
831  else
832  $this->setUseMode(self::USE_MODE_APPLY);
833  }
834  }
isOrderChanged()
Returns true, if changed children order entities.

◆ instanceExists()

static instanceExists (   $index)
staticprotected

Returns true, if instance exist.

Аргументы
string$indexEntity instance identifier.
Возвращает
bool

См. определение в файле discountbase.php строка 5148

5149  {
5150  $className = get_called_class();
5151  if (!isset(self::$instances[$className]))
5152  return false;
5153  return isset(self::$instances[$className][$index]);
5154  }

◆ isBasketApplyResultExist()

isBasketApplyResultExist ( )
protected

Return true, if exist apply result from form for basket.

Возвращает
bool

См. определение в файле discountbase.php строка 3720

3721  {
3722  return (
3723  !empty($this->applyResult['DISCOUNT_LIST'])
3724  || !empty($this->applyResult['COUPON_LIST'])
3725  || !empty($this->applyResult['BASKET'])
3726  );
3727  }

◆ isBasketExist()

isBasketExist ( )
protected

Return exists basket.

Возвращает
bool

См. определение в файле discountbase.php строка 787

788  {
789  if ($this->isOrderExists())
790  return ($this->getOrder()->getBasket() instanceof BasketBase);
791  else
792  return ($this->basket instanceof BasketBase);
793  }

◆ isBasketItemChanged()

isBasketItemChanged (   $code)
protected

Return true if ordered basket item changed (change PRODUCT_ID).

Аргументы
int$codeBasket code.
Возвращает
bool

См. определение в файле discountbase.php строка 4129

4130  {
4131  $result = false;
4132  if ($this->isOrderExists() && !$this->isOrderNew() && $this->isBasketNotEmpty())
4133  {
4134  $basketItem = $this->getBasket()->getItemByBasketCode($code);
4135  if ($basketItem instanceof BasketItem)
4136  {
4137  /** @noinspection PhpInternalEntityUsedInspection */
4138  if (in_array('PRODUCT_ID', $basketItem->getFields()->getChangedKeys()))
4139  $result = true;
4140  }
4141  }
4142  return $result;
4143  }

◆ isBasketLastDiscount()

isBasketLastDiscount ( )
protected

Check last discount flag for basket items.

Only for basket or new order or refreshed order.

Возвращает
bool

См. определение в файле discountbase.php строка 4738

4739  {
4740  $result = false;
4741 
4742  if ($this->getUseMode() != self::USE_MODE_FULL)
4743  return $result;
4744 
4745  $this->fillBasketLastDiscount();
4746  $applyMode = self::getApplyMode();
4747  if ($applyMode == self::APPLY_MODE_FULL_LAST || $applyMode == self::APPLY_MODE_FULL_DISABLE)
4748  {
4749  foreach ($this->orderData['BASKET_ITEMS'] as $basketItem)
4750  {
4751  if (isset($basketItem['LAST_DISCOUNT']) && $basketItem['LAST_DISCOUNT'] == 'Y')
4752  {
4753  $result = true;
4754  break;
4755  }
4756  }
4757  unset($basketItem);
4758  }
4759  unset($applyMode);
4760 
4761  return $result;
4762  }
fillBasketLastDiscount()
Fill last discount flag for basket items.

◆ isBasketNotEmpty()

isBasketNotEmpty ( )
protected

Returns the existence of a non-empty basket.

Возвращает
bool

См. определение в файле discountbase.php строка 800

801  {
802  if ($this->isOrderExists())
803  {
804  $basket = $this->getOrder()->getBasket();
805  $result = ($basket instanceof Basket && $basket->count() > 0);
806  unset($basket);
807  }
808  else
809  {
810  $result = ($this->basket instanceof Basket && $this->basket->count() > 0);
811  }
812  return $result;
813  }

◆ isClone()

isClone ( )

Returns true if discount entity is cloned.

Возвращает
bool

См. определение в файле discountbase.php строка 193

194  {
195  return $this->isClone;
196  }

◆ isCustomPrice()

static isCustomPrice ( array  $item)
staticprotected

Returns exist custom price for basket item.

Аргументы
array$itemBasket item.
Возвращает
bool

См. определение в файле discountbase.php строка 4037

4038  {
4039  if (!empty($item['CUSTOM_PRICE']) && $item['CUSTOM_PRICE'] == 'Y')
4040  return true;
4041  return false;
4042  }

◆ isCustomPriceByCode()

isCustomPriceByCode (   $code)
protected

Returns exist custom price for basket item code.

Аргументы
int$codeBasket code.
Возвращает
bool

См. определение в файле discountbase.php строка 4024

4025  {
4026  if (!$this->isExistBasketItem($code))
4027  return false;
4028  return $this->isCustomPrice($this->orderData['BASKET_ITEMS'][$code]);
4029  }
static isCustomPrice(array $item)
Returns exist custom price for basket item.
isExistBasketItem($code)
Return true, if basket item exists.

◆ isExistBasketItem()

isExistBasketItem (   $code)
protected

Return true, if basket item exists.

Аргументы
string | int$codeBasket item code.
Возвращает
bool

См. определение в файле discountbase.php строка 4151

4152  {
4153  if (!$this->isLoaded())
4154  return false;
4155  return isset($this->orderData['BASKET_ITEMS'][$code]);
4156  }

◆ isFreezedBasketItem()

static isFreezedBasketItem ( array  $item)
staticprotected

Returns true, if allowed apply discounts to basket item.

Аргументы
array$itemBasket item.
Возвращает
bool

См. определение в файле discountbase.php строка 4118

4119  {
4120  return (static::isCustomPrice($item) || static::isInSet($item));
4121  }

◆ isFreezedBasketItemByCode()

isFreezedBasketItemByCode (   $code)
protected

Returns true, if allowed apply discounts to basket item.

Аргументы
int | string$codeBasket code.
Возвращает
bool

См. определение в файле discountbase.php строка 4105

4106  {
4107  if (!$this->isExistBasketItem($code))
4108  return false;
4109  return $this->isFreezedBasketItem($this->orderData['BASKET_ITEMS'][$code]);
4110  }

◆ isInSet()

static isInSet ( array  $item)
staticprotected

Returns check item in set for basket item.

Аргументы
array$itemBasket item.
Возвращает
bool

См. определение в файле discountbase.php строка 4063

4064  {
4065  if (!empty($item['IN_SET']) && $item['IN_SET'] == 'Y')
4066  return true;
4067  return false;
4068  }

◆ isInSetByCode()

isInSetByCode (   $code)
protected

Returns check item in set for basket item code.

Аргументы
int$codeBasket code.
Возвращает
bool

См. определение в файле discountbase.php строка 4050

4051  {
4052  if (!$this->isExistBasketItem($code))
4053  return false;
4054  return $this->isInSet($this->orderData['BASKET_ITEMS'][$code]);
4055  }
static isInSet(array $item)
Returns check item in set for basket item.

◆ isLoaded()

isLoaded ( )
protected

Returns true if the data for calculations is loaded.

Возвращает
bool

См. определение в файле discountbase.php строка 250

251  {
252  return !empty($this->orderData);
253  }

◆ isMixedBasket()

isMixedBasket ( )
protected

Returns exist new item in basket.

Возвращает
bool

См. определение в файле discountbase.php строка 4173

4174  {
4175  $result = false;
4176  if (empty($this->orderData['BASKET_ITEMS']))
4177  return $result;
4178 
4179  foreach ($this->orderData['BASKET_ITEMS'] as $basketItem)
4180  {
4181  if (!isset($basketItem['ID']) || (int)$basketItem['ID'] <= 0)
4182  {
4183  $result = true;
4184  break;
4185  }
4186  }
4187  unset($basketItem);
4188 
4189  if (!$result)
4190  {
4191  if ($this->isOrderedBasketChanged())
4192  $result = true;
4193  }
4194 
4195  return $result;
4196  }
isOrderedBasketChanged()
Return true if basket saved order changed (change PRODUCT_ID).

◆ isNewBasketItem()

static isNewBasketItem ( array  $item)
staticprotected

Returns check new basket item for basket item.

Аргументы
array$itemBasket item.
Возвращает
bool

См. определение в файле discountbase.php строка 4091

4092  {
4093  return (
4094  !isset($item['ID'])
4095  || $item['ID'] <= 0
4096  );
4097  }

◆ isNewBasketItemByCode()

isNewBasketItemByCode (   $code)
protected

Returns check new basket item for basket item code.

Аргументы
int | string$codeBasket code.
Возвращает
bool

См. определение в файле discountbase.php строка 4076

4077  {
4078  return (
4079  $this->getUseMode() == self::USE_MODE_FULL
4080  || !isset($this->orderData['BASKET_ITEMS'][$code]['ID'])
4081  || $this->orderData['BASKET_ITEMS'][$code]['ID'] <= 0
4082  );
4083  }

◆ isOrderChanged()

isOrderChanged ( )
protected

Returns true, if changed children order entities.

Возвращает
bool

См. определение в файле discountbase.php строка 4163

4164  {
4165  return $this->isMixedBasket();
4166  }
isMixedBasket()
Returns exist new item in basket.

◆ isOrderedBasketChanged()

isOrderedBasketChanged ( )
protected

Return true if basket saved order changed (change PRODUCT_ID).

Возвращает
bool

См. определение в файле discountbase.php строка 4203

4204  {
4205  $result = false;
4206  if ($this->isOrderExists() && !$this->isOrderNew() && $this->isBasketNotEmpty())
4207  {
4208  $basket = $this->getBasket();
4209  /** @var BasketItem $basketItem */
4210  foreach ($basket as $basketItem)
4211  {
4212  if (!$basketItem->isChanged())
4213  continue;
4214  /** @noinspection PhpInternalEntityUsedInspection */
4215  if (in_array('PRODUCT_ID', $basketItem->getFields()->getChangedKeys()))
4216  {
4217  $result = true;
4218  break;
4219  }
4220  }
4221  unset($basketItem, $basket);
4222  }
4223  return $result;
4224  }

◆ isOrderExists()

isOrderExists ( )

Return flag is order exists.

Возвращает
bool

См. определение в файле discountbase.php строка 5252

5253  {
5254  return ($this->order instanceof OrderBase);
5255  }

◆ isOrderNew()

isOrderNew ( )

Returns new order flag value.

Возвращает
bool

См. определение в файле discountbase.php строка 226

227  {
228  return $this->newOrder;
229  }

◆ isOrderRefresh()

isOrderRefresh ( )

Returns full refresh status value.

Возвращает
bool

См. определение в файле discountbase.php строка 216

217  {
218  return $this->orderRefresh;
219  }

◆ isRoundMode()

isRoundMode (   $mode)
protected

Return true, if selected check round apply mode.

См. определение в файле discountbase.php строка 3163

3164  {
3165  return $this->roundApplyMode == $mode;
3166  }

◆ isValidState()

isValidState ( )

См. определение в файле discountbase.php строка 697

698  {
699  return $this->valid === true;
700  }

◆ loadBasket()

loadBasket ( )
protected

Get basket data from owner entity.

Возвращает
Result
Исключения
Main

Переопределяется в Discount.

См. определение в файле discountbase.php строка 949

950  {
951  $result = new Result;
952 
953  if (!$this->isBasketExist())
954  throw new Main\ObjectNotFoundException('Entity "Basket" not found');
955  elseif (!$this->isBasketNotEmpty())
956  return $result;
957 
958  /** @var BasketBase $basket */
959  $basket = $this->getBasket();
960  /** @var BasketItemBase $basketItem */
961  foreach ($basket as $basketItem)
962  {
963  if (!$basketItem->canBuy())
964  continue;
965  $this->orderData['BASKET_ITEMS'][$basketItem->getBasketCode()] = $this->getBasketItemFields($basketItem);
966  }
967  unset($basketItem, $basket);
968 
969  return $result;
970  }
getBasketItemFields(BasketItemBase $basketItem)
Returns array with basket item field values.
return[ 'LETTERS'=>['Ё'=> 'Е'], 'TITLES'=>['АУЛ', 'СЕЛО', 'C', 'ХУТОР', 'Х', 'ДЕРЕВНЯ', 'Д', 'ДЕР', 'СТАНИЦА', 'СТЦА', 'СТАН', 'РАБОЧИЙ ПОСЕЛОК', 'РП', 'ПОСЕЛОК ГОРОДСКОГО ТИПА', 'ПГТ', 'ПОСЕЛОК', 'П', 'ПОС', 'ГОРОД', 'ГОР', 'Г', 'РАЙОН', 'РН', 'РОН', 'АВТОНОМНАЯ ОБЛАСТЬ', 'ОБЛАСТЬ', 'ОБЛ', 'АВТОНОМНЫЙ ОКРУГ', 'АО', 'АВТ ОКРУГ', 'РЕСПУБЛИКА', 'РЕСП'], 'ALIASES'=>[]]

◆ loadBasketStoredData()

loadBasketStoredData ( )
protected

Load basket stored data for order.

Возвращает
Result

См. определение в файле discountbase.php строка 1197

1198  {
1199  $result = new Result;
1200 
1201  $this->basketItemsData = [];
1202 
1203  if (!$this->isOrderExists())
1204  return $result;
1205 
1206  $order = $this->getOrder();
1207  if ($this->isOrderNew() || $this->getUseMode() == self::USE_MODE_FULL)
1208  return $result;
1209 
1210  /** @var OrderDiscount $storageClassName */
1211  $storageClassName = $this->getOrderDiscountClassName();
1212  $basketData = $storageClassName::loadStoredDataFromDb(
1213  $order->getId(),
1214  $storageClassName::STORAGE_TYPE_BASKET_ITEM
1215  );
1216 
1217  if (empty($basketData))
1218  return $result;
1219 
1220  $basketCodeList = $this->getBasketCodes(false);
1221  if (!empty($basketCodeList))
1222  {
1223  foreach ($basketCodeList as $basketCode)
1224  {
1225  if (!isset($this->forwardBasketTable[$basketCode]))
1226  continue;
1227  $basketId = $this->forwardBasketTable[$basketCode];
1228  if (!isset($basketData[$basketId]) || !is_array($basketData[$basketId]))
1229  continue;
1230  $this->addBasketItemValues($basketCode, $basketData[$basketId]);
1231  }
1232  unset($basketId, $basketCode);
1233  }
1234  unset($basketCodeList);
1235  unset($basketData, $storageClassName);
1236  unset($order);
1237 
1238  return $result;
1239  }

◆ loadDefaultOrderConfig()

loadDefaultOrderConfig ( )
protected

Load default order config for order.

Возвращает
void

Переопределяется в Discount.

См. определение в файле discountbase.php строка 1050

1051  {
1052  $this->saleOptions = $this->getModuleSettings();
1053  }
getModuleSettings()
Returns the current module settings required for calculating discounts.

◆ loadDiscountByUserGroups()

loadDiscountByUserGroups ( array  $filter = array())
protected

Load from database discount id for user groups.

См. определение в файле discountbase.php строка 5367

5368  {
5369  $this->discountIds = array();
5370  $userGroups = $this->context->getUserGroups();
5371  if (empty($userGroups))
5372  return;
5373  $filter['@GROUP_ID'] = $userGroups;
5374  $filter['=ACTIVE'] = 'Y';
5375 
5376  //RuntimeCache works only with basic filter.
5377  if(!array_diff_assoc($filter, array(
5378  '@GROUP_ID' => $userGroups,
5379  '=ACTIVE' => 'Y',
5380  )))
5381  {
5382  $this->discountIds = Discount\RuntimeCache\DiscountCache::getInstance()->getDiscountIds($userGroups);
5383  }
5384  else
5385  {
5386  $discountCache = array();
5387  $groupDiscountIterator = Internals\DiscountGroupTable::getList(array(
5388  'select' => array('DISCOUNT_ID'),
5389  'filter' => $filter,
5390  'order' => array('DISCOUNT_ID' => 'ASC')
5391  ));
5392  while ($groupDiscount = $groupDiscountIterator->fetch())
5393  {
5394  $groupDiscount['DISCOUNT_ID'] = (int)$groupDiscount['DISCOUNT_ID'];
5395  if ($groupDiscount['DISCOUNT_ID'] > 0)
5396  $discountCache[$groupDiscount['DISCOUNT_ID']] = $groupDiscount['DISCOUNT_ID'];
5397  }
5398  unset($groupDiscount, $groupDiscountIterator);
5399  $this->discountIds = $discountCache;
5400  unset($discountCache);
5401  }
5402  unset($userGroups);
5403  }
static getInstance()
Returns Singleton of DiscountCache.

◆ loadDiscountList()

loadDiscountList ( )
protected

Load sale discount from database.

См. определение в файле discountbase.php строка 5442

5443  {
5444  if (empty($this->discountIds))
5445  return;
5446 
5448  array('MODULE_ID' => 'sale', 'DISCOUNT_ID' => $this->discountIds),
5449  array(),
5450  true
5451  );
5452 
5453  $this->saleDiscountCacheKey = md5('D'.implode('_', $this->discountIds));
5454  if (!empty($couponList))
5455  $this->saleDiscountCacheKey .= '-C'.implode('_', array_keys($couponList));
5456 
5457  $this->saleDiscountCacheKey .= '-MF'.implode('_', $this->executeModuleFilter);
5458 
5459  if (!isset($this->saleDiscountCache[$this->saleDiscountCacheKey]))
5460  {
5461  $currentList = Discount\RuntimeCache\DiscountCache::getInstance()->getDiscounts(
5462  $this->discountIds,
5463  $this->executeModuleFilter,
5464  $this->getSiteId(),
5465  $couponList?: array()
5466  );
5467 
5468  if (!empty($currentList))
5469  {
5470  $evalCode = '';
5471  $executeFields = $this->getExecuteFieldList();
5472  foreach (array_keys($currentList) as $index)
5473  {
5474  $discount = $currentList[$index];
5475  if (!$this->loadDiscountModules($discount['MODULES']))
5476  {
5477  unset($currentList[$index]);
5478  continue;
5479  }
5480 
5481  foreach ($executeFields as $field)
5482  {
5483  if (!empty($discount[$field]))
5484  $evalCode .= '$currentList['.$index.'][\''.self::getExecuteFieldName($field).'\'] = '.$discount[$field].";\n";
5485  }
5486  }
5487  unset($field, $code, $discount, $index, $executeFields);
5488 
5489  if ($evalCode !== '')
5490  {
5491  if (PHP_MAJOR_VERSION >= 7)
5492  {
5493  try
5494  {
5495  eval($evalCode);
5496  }
5497  catch (\ParseError $e)
5498  {
5499  $this->showAdminError();
5500  }
5501  }
5502  else
5503  {
5504  eval($evalCode);
5505  }
5506  }
5507  unset($evalCode);
5508  }
5509 
5510  $this->saleDiscountCache[$this->saleDiscountCacheKey] = $currentList;
5511  }
5512  unset($couponList);
5513  }
getExecuteFieldList()
Return field list for eval.
static getForApply($filter, $product=array(), $uniqueDiscount=false)
Get coupons list for apply.

◆ loadDiscountModules()

loadDiscountModules ( array  $modules)
protected

Load discount modules.

См. определение в файле discountbase.php строка 5414

5415  {
5416  $result = true;
5417  if (empty($modules))
5418  return $result;
5419 
5420  foreach ($modules as $moduleId)
5421  {
5422  if (!isset($this->loadedModules[$moduleId]))
5423  $this->loadedModules[$moduleId] = Main\Loader::includeModule($moduleId);
5424  if (!$this->loadedModules[$moduleId])
5425  {
5426  $result = false;
5427  break;
5428  }
5429  }
5430  unset($moduleId);
5431 
5432  return $result;
5433  }
static includeModule($moduleName)
Includes a module by its name.

◆ loadOrderConfig()

loadOrderConfig ( )
protected

Load order config for exists order.

Возвращает
void

См. определение в файле discountbase.php строка 999

1000  {
1001  $this->setValidState(true);
1002  $this->loadDefaultOrderConfig();
1003 
1004  if (!$this->isOrderExists()
1005  || $this->isOrderNew()
1006  || $this->getUseMode() == self::USE_MODE_FULL
1007  )
1008  return;
1009 
1010  /** @var OrderDiscountBase $storageClassName */
1011  $storageClassName = $this->getOrderDiscountClassName();
1012  $entityData = $storageClassName::loadOrderStoredDataFromDb(
1013  $this->getOrder()->getId(),
1014  $storageClassName::STORAGE_TYPE_ORDER_CONFIG
1015  );
1016  if (!$this->validateLoadedOrderConfig($entityData))
1017  {
1018  $this->setValidState(false);
1019  return;
1020  }
1021  $this->applyLoadedOrderConfig($entityData);
1022  if (isset($entityData['OLD_ORDER']))
1023  $this->setValidState(false);
1024  unset($entityData);
1025 
1026  $this->loadRoundConfig();
1027  }
loadDefaultOrderConfig()
Load default order config for order.
loadRoundConfig()
Load round apply config for exist order.
validateLoadedOrderConfig($config)
Validate loaded order config.
applyLoadedOrderConfig(array $data)
Set loaded order settings.

◆ loadOrderData()

loadOrderData ( )
protected

Load order information.

Возвращает
Result

Переопределяется в Discount.

См. определение в файле discountbase.php строка 841

842  {
843  $result = new Result;
844  $orderId = 0;
845  if ($this->isOrderExists())
846  $orderId = $this->getOrder()->getId();
847 
848  if (!$this->isLoaded())
849  $this->fillEmptyOrderData();
850 
851  $basketResult = $this->loadBasket();
852  if (!$basketResult->isSuccess())
853  {
854  $result->addErrors($basketResult->getErrors());
855  return $result;
856  }
857  unset($basketResult);
858 
859  if ($this->isOrderExists() && $orderId > 0)
860  {
861  $basketResult = $this->getBasketTables();
862  if (!$basketResult->isSuccess())
863  {
864  $result->addErrors($basketResult->getErrors());
865  return $result;
866  }
867  unset($basketResult);
868  }
869 
870  $this->loadOrderConfig();
871 
873  if (!$discountResult->isSuccess())
874  $result->addErrors($discountResult->getErrors());
875  unset($discountResult);
876 
877  $dataResult = $this->loadBasketStoredData();
878  if (!$dataResult->isSuccess())
879  $result->addErrors($dataResult->getErrors());
880  unset($dataResult);
881 
882  return $result;
883  }
loadOrderConfig()
Load order config for exists order.
loadOrderDiscounts()
Load discounts for exists order.
loadBasketStoredData()
Load basket stored data for order.
getBasketTables()
Create correspondence between basket ids and basket codes.
loadBasket()
Get basket data from owner entity.
fillEmptyOrderData()
Fill empty order data.

◆ loadOrderDiscounts()

loadOrderDiscounts ( )
protected

Load discounts for exists order.

Возвращает
Result

См. определение в файле discountbase.php строка 1094

1095  {
1096  $result = new Result;
1097  $this->discountsCache = array();
1098  $this->couponsCache = array();
1099 
1100  if (!$this->isOrderExists())
1101  return $result;
1102 
1103  $order = $this->getOrder();
1104  if ($this->isOrderNew() || $this->getUseMode() == self::USE_MODE_FULL)
1105  return $result;
1106 
1107  /** @var DiscountCouponsManager $couponClassName */
1108  $couponClassName = $this->getDiscountCouponClassName();
1109 
1110  /** @var OrderDiscount $storageClassName */
1111  $storageClassName = $this->getOrderDiscountClassName();
1112  $applyResult = $storageClassName::loadResultFromDb(
1113  $order->getId(),
1114  $this->reverseBasketTable,
1115  $this->orderData['BASKET_ITEMS']
1116  );
1117 
1118  if (!$applyResult->isSuccess())
1119  $result->addErrors($applyResult->getErrors());
1120 
1121  $applyResultData = $applyResult->getData();
1122 
1123  if (!empty($applyResultData['DISCOUNT_LIST']))
1124  {
1125  foreach ($applyResultData['DISCOUNT_LIST'] as $orderDiscountId => $discountData)
1126  {
1127  $discountData['ACTIONS_DESCR_DATA'] = false;
1128  if (!empty($discountData['ACTIONS_DESCR']) && is_array($discountData['ACTIONS_DESCR']))
1129  {
1130  $discountData['ACTIONS_DESCR_DATA'] = $discountData['ACTIONS_DESCR'];
1131  $discountData['ACTIONS_DESCR'] = $this->formatDescription($discountData['ACTIONS_DESCR']);
1132  }
1133  else
1134  {
1135  $discountData['ACTIONS_DESCR'] = false;
1136  }
1137  if (empty($discountData['ACTIONS_DESCR']))
1138  {
1139  $discountData['ACTIONS_DESCR'] = false;
1140  $discountData['ACTIONS_DESCR_DATA'] = false;
1141  }
1142  $this->discountsCache[$orderDiscountId] = $discountData;
1143  }
1144  unset($orderDiscountId, $discountData);
1145  }
1146  if (!empty($applyResultData['COUPON_LIST']))
1147  $this->couponsCache = $applyResultData['COUPON_LIST'];
1148 
1149  $this->discountResultCounter = 0;
1150  $this->discountResult['APPLY_BLOCKS'] = $applyResultData['APPLY_BLOCKS'];
1151  if (!empty($this->discountResult['APPLY_BLOCKS']))
1152  {
1153  foreach ($this->discountResult['APPLY_BLOCKS'] as $counter => $applyBlock)
1154  {
1155  if (!empty($applyBlock['BASKET']))
1156  {
1157  foreach ($applyBlock['BASKET'] as $discountList)
1158  {
1159  foreach ($discountList as $discount)
1160  {
1161  if ($discount['COUPON_ID'] == '')
1162  continue;
1163  $couponClassName::setApplyByProduct($discount, array($discount['COUPON_ID']));
1164  }
1165  }
1166  unset($discountList);
1167  }
1168 
1169  if (!empty($applyBlock['ORDER']))
1170  {
1171  foreach ($applyBlock['ORDER'] as $discount)
1172  {
1173  if ($discount['COUPON_ID'] != '')
1174  $couponClassName::setApply($discount['COUPON_ID'], $discount['RESULT']);
1175  }
1176  unset($discount);
1177  }
1178 
1179  $this->discountResultCounter = $counter + 1;
1180  }
1181  unset($counter, $applyBlock);
1182  }
1183 
1184  if (!empty($applyResultData['STORED_ACTION_DATA']) && is_array($applyResultData['STORED_ACTION_DATA']))
1185  $this->discountStoredActionData = $applyResultData['STORED_ACTION_DATA'];
1186 
1187  unset($applyResultData, $applyResult);
1188 
1189  return $result;
1190  }

◆ loadRoundConfig()

loadRoundConfig ( )
protected

Load round apply config for exist order.

См. определение в файле discountbase.php строка 3174

3175  {
3176  $defaultApplyMode = self::ROUND_MODE_FINAL_PRICE;
3177  $this->roundApplyMode = $defaultApplyMode;
3178  $this->roundApplyConfig = array();
3179 
3180  if ($this->isOrderExists() && !$this->isOrderNew() && $this->getUseMode() != self::USE_MODE_FULL)
3181  {
3182  $orderId = $this->getOrder()->getId();
3183  /** @var OrderDiscount $storageClassName */
3184  $storageClassName = $this->getOrderDiscountClassName();
3185  $entityData = $storageClassName::loadOrderStoredDataFromDb(
3186  $orderId,
3187  $storageClassName::STORAGE_TYPE_ROUND_CONFIG
3188  );
3189  unset($orderId);
3190 
3191  if (
3192  is_array($entityData)
3193  && isset($entityData['MODE'])
3194  )
3195  {
3196  $this->roundApplyMode = (int)$entityData['MODE'];
3197  if ($this->isRoundMode(self::ROUND_MODE_SALE_DISCOUNT))
3198  $this->roundApplyConfig = (isset($entityData['CONFIG']) ? $entityData['CONFIG'] : array());
3199  }
3200  }
3201 
3202  if (
3203  $this->roundApplyMode != self::ROUND_MODE_BASKET_DISCOUNT
3204  && $this->roundApplyMode != self::ROUND_MODE_SALE_DISCOUNT
3205  && $this->roundApplyMode != self::ROUND_MODE_FINAL_PRICE
3206  )
3207  $this->roundApplyMode = null;
3208  if (!is_array($this->roundApplyConfig))
3209  $this->roundApplyConfig = array();
3210  unset($defaultApplyMode);
3211  }

◆ mergeDiscountActionResult()

mergeDiscountActionResult (   $index,
  $stepResult 
)
protected

Merge discount actions result with old data.

Аргументы
int$indexDiscount index.
array$stepResultNew result.
Возвращает
void

См. определение в файле discountbase.php строка 4320

4321  {
4322  if (!isset($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$index]))
4323  return;
4324  if (empty($stepResult) || !is_array($stepResult))
4325  return;
4326  $basketKeys = array_keys($this->orderData['BASKET_ITEMS']);
4327  foreach ($basketKeys as &$basketCode)
4328  {
4329  if (!$this->isCustomPriceByCode($basketCode))
4330  continue;
4331  if (isset($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$index]['RESULT']['BASKET'][$basketCode]))
4332  unset($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$index]['RESULT']['BASKET'][$basketCode]);
4333  }
4334  unset($basketCode);
4335  if (isset($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$index]['RESULT']['DESCR_DATA']))
4336  unset($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$index]['RESULT']['DESCR_DATA']);
4337  if (isset($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$index]['RESULT']['DESCR']))
4338  unset($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$index]['RESULT']['DESCR']);
4339  self::recursiveMerge($stepResult, $this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$index]['RESULT']);
4340  $this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['ORDER'][$index]['RESULT'] = $stepResult;
4341  }
static recursiveMerge(&$dest, $src)
Added keys from source array to destination array.

◆ migrateInstance()

static migrateInstance (   $oldIndex,
  $newIndex 
)
staticprotected

См. определение в файле discountbase.php строка 5173

5174  {
5175  $className = get_called_class();
5176  if (!isset(self::$instances[$className]))
5177  return;
5178  if (isset(self::$instances[$className][$oldIndex]) && !isset(self::$instances[$className][$newIndex]))
5179  {
5180  self::$instances[$className][$newIndex] = self::$instances[$className][$oldIndex];
5181  unset(self::$instances[$className][$oldIndex]);
5182  }
5183  }

◆ modifyOrderData()

modifyOrderData ( $newData)
protected

Modify order data from handlers.

Аргументы
array&$newDataNew order data from handler.
Возвращает
void

См. определение в файле discountbase.php строка 4486

4487  {
4488  if (!empty($newData) && is_array($newData))
4489  self::recursiveMerge($this->orderData, $newData);
4490  }

◆ normalizeDiscountResult()

normalizeDiscountResult ( )
protected

Round and correct discount calculation results.

Переопределяется в Discount.

См. определение в файле discountbase.php строка 5115

5116  {
5117  if (!empty($this->orderData['BASKET_ITEMS']))
5118  {
5119  foreach (array_keys($this->orderData['BASKET_ITEMS']) as $basketCode)
5120  {
5121  $customPrice = $this->isCustomPriceByCode($basketCode);
5122  $basketItem = $this->orderData['BASKET_ITEMS'][$basketCode];
5123  $basketItem['DISCOUNT_PRICE'] = (!$customPrice
5124  ? PriceMaths::roundPrecision($basketItem['DISCOUNT_PRICE'])
5125  : 0
5126  );
5127  if (!$customPrice)
5128  {
5129  if ($basketItem['DISCOUNT_PRICE'] > 0)
5130  $basketItem['PRICE'] = $basketItem['BASE_PRICE'] - $basketItem['DISCOUNT_PRICE'];
5131  else
5132  $basketItem['PRICE'] = PriceMaths::roundPrecision($basketItem['PRICE']);
5133  }
5134  $this->orderData['BASKET_ITEMS'][$basketCode] = $basketItem;
5135  }
5136  unset($basketItem, $customPrice, $basketCode);
5137  }
5138  }
static roundPrecision($value)
Definition: pricemaths.php:17

◆ normalizeNewResultRows()

normalizeNewResultRows ( array &  $rows)
protected

Fill common system fields for new discount results.

Аргументы
array$rowsPrepared new discount results.
Возвращает
void

См. определение в файле discountbase.php строка 2100

2101  {
2102  if (empty($rows))
2103  return;
2104 
2105  foreach (array_keys($rows) as $index)
2106  {
2107  $rows[$index]['APPLY_BLOCK_COUNTER'] = $this->discountResultCounter;
2108  if (isset($rows[$index]['ORDER_DISCOUNT_ID']))
2109  $rows[$index]['MODULE_ID'] = $this->discountsCache[$rows[$index]['ORDER_DISCOUNT_ID']]['MODULE_ID'];
2110  if (isset($rows[$index]['COUPON_ID']))
2111  $rows[$index]['COUPON_ID'] = ($rows[$index]['COUPON_ID'] != '' ? $this->couponsCache[$rows[$index]['COUPON_ID']]['ID'] : 0);
2112  }
2113  unset($index);
2114  }

◆ recursiveMerge()

static recursiveMerge ( $dest,
  $src 
)
staticprotected

Added keys from source array to destination array.

Аргументы
array&$destDestination array.
array$srcSource array.
Возвращает
void

См. определение в файле discountbase.php строка 5638

5639  {
5640  if (!is_array($dest) || !is_array($src))
5641  return;
5642  if (empty($dest))
5643  {
5644  $dest = $src;
5645  return;
5646  }
5647  foreach ($src as $key => $value)
5648  {
5649  if (!isset($dest[$key]))
5650  {
5651  $dest[$key] = $value;
5652  continue;
5653  }
5654  if (is_array($dest[$key]))
5655  self::recursiveMerge($dest[$key], $value);
5656  }
5657  unset($value, $key);
5658  }

◆ remakingDiscountResult()

remakingDiscountResult ( )
protected

Change result format.

Возвращает
void

Переопределяется в Discount.

См. определение в файле discountbase.php строка 3866

3867  {
3868  $basket = [];
3869  if (!empty($this->discountResult['APPLY_BLOCKS']))
3870  {
3871  foreach ($this->discountResult['APPLY_BLOCKS'] as $counter => $applyBlock)
3872  {
3873  if (!empty($applyBlock['BASKET']))
3874  {
3875  foreach ($applyBlock['BASKET'] as $basketCode => $discountList)
3876  {
3877  if (!isset($basket[$basketCode]))
3878  $basket[$basketCode] = [];
3879  foreach ($discountList as $discount)
3880  {
3881  $basket[$basketCode][] = [
3882  'DISCOUNT_ID' => $discount['DISCOUNT_ID'],
3883  'COUPON_ID' => $discount['COUPON_ID'],
3884  'APPLY' => $discount['RESULT']['APPLY'],
3885  'DESCR' => $discount['RESULT']['DESCR']
3886  ];
3887  }
3888  unset($discount);
3889  }
3890  unset($basketCode, $discountList);
3891  }
3892 
3893  if (!empty($applyBlock['ORDER']))
3894  {
3895  foreach ($applyBlock['ORDER'] as $discount)
3896  {
3897  if (!empty($discount['RESULT']['BASKET']))
3898  {
3899  foreach ($discount['RESULT']['BASKET'] as $basketCode => $applyList)
3900  {
3901  if (!isset($basket[$basketCode]))
3902  $basket[$basketCode] = [];
3903  $basket[$basketCode][] = [
3904  'DISCOUNT_ID' => $discount['DISCOUNT_ID'],
3905  'COUPON_ID' => $discount['COUPON_ID'],
3906  'APPLY' => $applyList['APPLY'],
3907  'DESCR' => $applyList['DESCR']
3908  ];
3909  }
3910  unset($basketCode, $applyList);
3911  }
3912  }
3913  unset($discount);
3914  }
3915  }
3916  unset($counter, $applyBlock);
3917  }
3918 
3919  $this->discountResult['RESULT'] = [
3920  'BASKET' => $basket
3921  ];
3922  unset($basket);
3923  }

◆ removeInstance()

static removeInstance (   $index)
staticprotected

См. определение в файле discountbase.php строка 5185

5186  {
5187  $className = get_called_class();
5188  if (!isset(self::$instances[$className]))
5189  return;
5190  if (isset(self::$instances[$className][$index]))
5191  unset(self::$instances[$className][$index]);
5192  }

◆ resetBasketPrices()

resetBasketPrices ( )
protected

Fill basket prices from base prices.

Возвращает
void

См. определение в файле discountbase.php строка 4562

4563  {
4564  foreach ($this->orderData['BASKET_ITEMS'] as &$basketItem)
4565  {
4566  if ($this->isFreezedBasketItem($basketItem))
4567  continue;
4568  $basketItem = self::resetBasketItemPrice($basketItem);
4569  }
4570  unset($basketItem);
4571  }

◆ resetDiscountAppliedFlag()

resetDiscountAppliedFlag ( )
protected

Reset flag of applying discounts for basket items.

Возвращает
void

См. определение в файле discountbase.php строка 4578

4579  {
4580  foreach ($this->orderData['BASKET_ITEMS'] as &$basketItem)
4581  {
4582  if ($this->isFreezedBasketItem($basketItem))
4583  continue;
4584  $basketItem['ACTION_APPLIED'] = 'N';
4585  }
4586  }

◆ resetOrderState()

resetOrderState ( )
protected

Set order parameters to their original state before the start of calculations.

Возвращает
void

См. определение в файле discountbase.php строка 4541

4542  {
4543  $this->resetPrices();
4544  $this->resetDiscountAppliedFlag();
4545  }
resetPrices()
Fill prices from base prices.
resetDiscountAppliedFlag()
Reset flag of applying discounts for basket items.

◆ resetPrices()

resetPrices ( )
protected

Fill prices from base prices.

Возвращает
void

Переопределяется в Discount.

См. определение в файле discountbase.php строка 4552

4553  {
4554  $this->resetBasketPrices();
4555  }
resetBasketPrices()
Fill basket prices from base prices.

◆ revertApplyBlockForBasketItem()

revertApplyBlockForBasketItem (   $basketItemId)
protected

Reverts apply flag in blocks for basket items which has for example cumulative discount which cancels previous discounts on item.

Аргументы
int$basketItemId
Возвращает
void

См. определение в файле discountbase.php строка 2978

2979  {
2980  if (empty($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]))
2981  {
2982  return;
2983  }
2984 
2985  $applyBlock = &$this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter];
2986  foreach ($applyBlock['ORDER'] as &$orderBlock)
2987  {
2988  foreach ($orderBlock['RESULT']['BASKET'] as $bid => &$basketItem)
2989  {
2990  if ($bid != $basketItemId)
2991  {
2992  continue;
2993  }
2994 
2995  $basketItem['APPLY'] = 'N';
2996  }
2997  }
2998  }

◆ roundApplyBasketPrices()

roundApplyBasketPrices ( )
protected

Round prices.

Возвращает
void

См. определение в файле discountbase.php строка 3302

3303  {
3304  if (empty($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['BASKET_ROUND']))
3305  return;
3306 
3307  $basketCodeList = $this->getBasketCodes(false);
3308  if (!empty($basketCodeList))
3309  {
3310  $roundBlock = &$this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['BASKET_ROUND'];
3311  $basket = array();
3312  $roundData = array();
3313  foreach ($basketCodeList as $basketCode)
3314  {
3315  if (empty($roundBlock[$basketCode]))
3316  continue;
3317  if ($roundBlock[$basketCode]['APPLY'] != 'Y')
3318  continue;
3319  $basket[$basketCode] = $this->orderData['BASKET_ITEMS'][$basketCode];
3320  $roundData[$basketCode] = $roundBlock[$basketCode]['ROUND_RULE'];
3321  }
3322  unset($basketCode);
3323 
3324  if (!empty($basket))
3325  {
3327  unset($orderData['BASKET_ITEMS']);
3328 
3329  /** @var OrderDiscount $storageClassName */
3330  $storageClassName = $this->getOrderDiscountClassName();
3331 
3332  $result = $storageClassName::roundBasket(
3333  $basket,
3334  $roundData,
3335  $orderData
3336  );
3337  foreach ($result as $basketCode => $roundResult)
3338  {
3339  if (empty($roundResult) || !is_array($roundResult))
3340  continue;
3341  if (!$this->isExistBasketItem($basketCode))
3342  continue;
3343  $this->orderData['BASKET_ITEMS'][$basketCode]['PRICE'] = $roundResult['PRICE'];
3344  $this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_PRICE'] = $roundResult['DISCOUNT_PRICE'];
3345  }
3346  unset($basketCode, $roundResult, $result);
3347  unset($orderData);
3348  }
3349  unset($roundData, $basket);
3350 
3351  unset($roundBlock);
3352  }
3353  unset($basketCodeList);
3354  }

◆ roundApplyBasketPricesByIndex()

roundApplyBasketPricesByIndex ( array  $index)
protected

Round prices in sale discount mode for exist order.

См. определение в файле discountbase.php строка 3484

3485  {
3486  if (!isset($index['DISCOUNT_INDEX']))
3487  return;
3488  if (!$this->isRoundMode(self::ROUND_MODE_SALE_DISCOUNT))
3489  return;
3490  if ($this->getUseMode() != self::USE_MODE_APPLY && $this->getUseMode() != self::USE_MODE_MIXED)
3491  return;
3492 
3493  $roundConfig = $this->getRoundIndex('BASKET_ROUND');
3494  if ($roundConfig === null)
3495  return;
3496  if ($roundConfig['DISCOUNT_INDEX'] != $index['DISCOUNT_INDEX'])
3497  return;
3498  $this->roundApplyBasketPrices();
3499  }

◆ roundChangedBasketPrices()

roundChangedBasketPrices ( )
protected

Round only changed prices.

Возвращает
void

См. определение в файле discountbase.php строка 3361

3362  {
3363  $basketCodeList = array();
3364  $applyBlock = $this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter];
3365  switch ($this->getUseMode())
3366  {
3367  case self::USE_MODE_APPLY:
3368  if (!empty($applyBlock['BASKET']))
3369  {
3370  foreach (array_keys($applyBlock['BASKET']) as $basketCode)
3371  {
3372  $basketCodeList[$basketCode] = $basketCode;
3373  }
3374  unset($basketCode);
3375  }
3376  if (!empty($applyBlock['ORDER']))
3377  {
3378  foreach ($applyBlock['ORDER'] as $discount)
3379  {
3380  if (empty($discount['RESULT']['BASKET']))
3381  continue;
3382  foreach (array_keys($discount['RESULT']['BASKET']) as $basketCode)
3383  {
3384  $basketCodeList[$basketCode] = $basketCode;
3385  }
3386  }
3387  unset($basketCode, $discount);
3388  }
3389  break;
3390  case self::USE_MODE_MIXED:
3391  if (!empty($applyBlock['BASKET']))
3392  {
3393  foreach (array_keys($applyBlock['BASKET']) as $basketCode)
3394  {
3395  $basketCodeList[$basketCode] = $basketCode;
3396  }
3397  unset($basketCode);
3398  }
3399  if (!empty($applyBlock['ORDER']))
3400  {
3401  foreach ($applyBlock['ORDER'] as $discount)
3402  {
3403  if (empty($discount['RESULT']['BASKET']))
3404  continue;
3405  foreach (array_keys($discount['RESULT']['BASKET']) as $basketCode)
3406  {
3407  $basketCodeList[$basketCode] = $basketCode;
3408  }
3409  }
3410  unset($basketCode, $discount);
3411  }
3412  foreach ($this->getBasketCodes(true) as $basketCode)
3413  $basketCodeList[$basketCode] = $basketCode;
3414  break;
3415  }
3416 
3417  if (!empty($basketCodeList))
3418  {
3419  $roundBlock = &$this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['BASKET_ROUND'];
3421  unset($orderData['BASKET_ITEMS']);
3422  $basket = array_intersect_key(
3423  $this->orderData['BASKET_ITEMS'],
3424  array_fill_keys($basketCodeList, true)
3425  );
3426 
3427  /** @var OrderDiscount $storageClassName */
3428  $storageClassName = $this->getOrderDiscountClassName();
3429 
3430  $result = $storageClassName::roundBasket(
3431  $basket,
3432  array(),
3433  $orderData
3434  );
3435 
3436  foreach ($result as $basketCode => $roundResult)
3437  {
3438  if (empty($roundResult) || !is_array($roundResult))
3439  continue;
3440  if (!$this->isExistBasketItem($basketCode))
3441  continue;
3442  $this->orderData['BASKET_ITEMS'][$basketCode]['PRICE'] = $roundResult['PRICE'];
3443  $this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_PRICE'] = $roundResult['DISCOUNT_PRICE'];
3444 
3445  $roundBlock[$basketCode] = array(
3446  'APPLY' => 'Y',
3447  'ROUND_RULE' => $roundResult['ROUND_RULE']
3448  );
3449  }
3450  unset($basketCode, $roundResult, $result);
3451  unset($storageClassName);
3452  unset($basket, $orderData);
3453  unset($roundBlock);
3454  }
3455  unset($basketCodeList);
3456  }

◆ roundFullBasketPriceByIndex()

roundFullBasketPriceByIndex ( array  $index)
protected

Round prices in sale discount mode for new order.

См. определение в файле discountbase.php строка 3465

3466  {
3467  if (!$this->isRoundMode(self::ROUND_MODE_SALE_DISCOUNT))
3468  return;
3469  if ($this->getUseMode() != self::USE_MODE_FULL)
3470  return;
3471 
3472  $this->roundFullBasketPrices();
3473  if (!empty($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['BASKET_ROUND']))
3474  $this->setRoundIndex('BASKET_ROUND', $index);
3475  }
setRoundIndex($entity, array $index)
Set discount index for use round.

◆ roundFullBasketPrices()

roundFullBasketPrices ( )
protected

Round prices.

Возвращает
void

См. определение в файле discountbase.php строка 3254

3255  {
3256  $basketCodeList = $this->getBasketCodes(true);
3257  if (!empty($basketCodeList))
3258  {
3259  $roundBlock = &$this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]['BASKET_ROUND'];
3261  unset($orderData['BASKET_ITEMS']);
3262  $basket = array_intersect_key(
3263  $this->orderData['BASKET_ITEMS'],
3264  array_fill_keys($basketCodeList, true)
3265  );
3266 
3267  /** @var OrderDiscount $storageClassName */
3268  $storageClassName = $this->getOrderDiscountClassName();
3269 
3270  $result = $storageClassName::roundBasket(
3271  $basket,
3272  array(),
3273  $orderData
3274  );
3275  foreach ($result as $basketCode => $roundResult)
3276  {
3277  if (empty($roundResult) || !is_array($roundResult))
3278  continue;
3279  if (!$this->isExistBasketItem($basketCode))
3280  continue;
3281  $this->orderData['BASKET_ITEMS'][$basketCode]['PRICE'] = $roundResult['PRICE'];
3282  $this->orderData['BASKET_ITEMS'][$basketCode]['DISCOUNT_PRICE'] = $roundResult['DISCOUNT_PRICE'];
3283 
3284  $roundBlock[$basketCode] = array(
3285  'APPLY' => 'Y',
3286  'ROUND_RULE' => $roundResult['ROUND_RULE']
3287  );
3288  }
3289  unset($basketCode, $roundResult, $result);
3290  unset($storageClassName);
3291  unset($basket, $orderData);
3292  unset($roundBlock);
3293  }
3294  unset($basketCodeList);
3295  }

◆ save()

save ( )

Save discount result.

Возвращает
Result

Переопределяется в Discount.

См. определение в файле discountbase.php строка 627

628  {
629  $process = true;
630  $result = new Result;
631  if (!$this->isOrderExists() || !$this->isBasketNotEmpty())
632  return $result;
633  $orderId = (int)$this->getOrder()->getId();
634 
635  if ($this->getUseMode() === null)
636  return $result;
637 
638  if ($process)
639  {
640  switch ($this->getUseMode())
641  {
642  case self::USE_MODE_FULL:
643  $saveResult = $this->saveFull();
644  break;
646  $saveResult = $this->saveApply();
647  break;
649  $saveResult = $this->saveMixed();
650  break;
651  default:
652  $saveResult = new Result;
653  $saveResult->addError(new Main\Entity\EntityError(
654  Loc::getMessage('BX_SALE_DISCOUNT_ERR_BAD_USE_MODE'),
655  self::ERROR_ID
656  ));
657  }
658  if (!$saveResult->isSuccess())
659  {
660  $result->addErrors($saveResult->getErrors());
661  }
662  else
663  {
664  if ($orderId > 0)
665  {
666  $registry = Registry::getInstance(static::getRegistryType());
667 
668  /** @var OrderHistory $orderHistory */
669  $orderHistory = $registry->getOrderHistoryClassName();
670  $orderHistory::addLog(
671  'DISCOUNT',
672  $orderId,
673  'DISCOUNT_SAVED',
674  null,
675  null,
676  array(),
677  $orderHistory::SALE_ORDER_HISTORY_LOG_LEVEL_1
678  );
679  }
680 
681  }
682  unset($saveResult);
683  }
684 
685  if ($orderId > 0)
686  {
687  $registry = Registry::getInstance(static::getRegistryType());
688 
689  /** @var OrderHistory $orderHistory */
690  $orderHistory = $registry->getOrderHistoryClassName();
691  $orderHistory::collectEntityFields('DISCOUNT', $orderId);
692  }
693 
694  return $result;
695  }
saveFull()
Save discount result for new order.
saveApply()
Save discount result for exist order.
saveMixed()
Save discount result for mixed order.

◆ saveApply()

saveApply ( )
protected

Save discount result for exist order.

Возвращает
Result

См. определение в файле discountbase.php строка 1698

1699  {
1700  $result = new Result;
1701 
1702  $process = true;
1703  $orderId = $this->getOrder()->getId();
1704 
1705  if (!$this->isValidState())
1706  return $result;
1707 
1708  $basketResult = $this->getBasketTables();
1709  if (!$basketResult->isSuccess())
1710  {
1711  $process = false;
1712  $result->addErrors($basketResult->getErrors());
1713  }
1714 
1715  /** @var OrderDiscount $storageClassName */
1716  $storageClassName = $this->getOrderDiscountClassName();
1717  /** @var DiscountCouponsManager $couponClassName */
1718  $couponClassName = $this->getDiscountCouponClassName();
1719 
1720  $rulesList = array();
1721  $roundList = array();
1722  foreach ($this->discountResult['APPLY_BLOCKS'] as $counter => $applyBlock)
1723  {
1724  if ($counter == $this->discountResultCounter)
1725  continue;
1726 
1727  if (!empty($applyBlock['BASKET']))
1728  {
1729  foreach ($applyBlock['BASKET'] as $basketCode => $discountList)
1730  {
1731  foreach ($discountList as $discount)
1732  {
1733  if (!isset($discount['RULE_ID']) || (int)$discount['RULE_ID'] < 0)
1734  {
1735  $process = false;
1736  $result->addError(new Main\Entity\EntityError(
1737  Loc::getMessage('BX_SALE_DISCOUNT_ERR_EMPTY_RULE_ID_EXT_DISCOUNT'),
1738  self::ERROR_ID
1739  ));
1740  continue;
1741  }
1742  $rulesList[] = array(
1743  'RULE_ID' => $discount['RULE_ID'],
1744  'APPLY' => $discount['RESULT']['APPLY'],
1745  'DESCR_ID' => (isset($discount['RULE_DESCR_ID']) ? (int)$discount['RULE_DESCR_ID'] : 0),
1746  'DESCR' => $discount['RESULT']['DESCR_DATA']['BASKET'],
1747  );
1748  }
1749  unset($discount);
1750  }
1751  unset($basketCode, $discountList);
1752  }
1753 
1754  if (!empty($applyBlock['ORDER']))
1755  {
1756  foreach ($applyBlock['ORDER'] as $discount)
1757  {
1758  if (!empty($discount['RESULT']['BASKET']))
1759  {
1760  foreach ($discount['RESULT']['BASKET'] as $basketCode => $applyData)
1761  {
1762  if (!isset($applyData['RULE_ID']) || (int)$applyData['RULE_ID'] < 0)
1763  {
1764  $process = false;
1765  $result->addError(new Main\Entity\EntityError(
1766  Loc::getMessage('BX_SALE_DISCOUNT_ERR_EMPTY_RULE_ID_SALE_DISCOUNT'),
1767  self::ERROR_ID
1768  ));
1769  continue;
1770  }
1771  $ruleData = array(
1772  'RULE_ID' => $applyData['RULE_ID'],
1773  'APPLY' => $applyData['APPLY'],
1774  'DESCR_ID' => (isset($applyData['RULE_DESCR_ID']) ? (int)$applyData['RULE_DESCR_ID'] : 0),
1775  'DESCR' => $applyData['DESCR_DATA'],
1776  );
1777  if (!$discount['ACTION_BLOCK_LIST'])
1778  $ruleData['ACTION_BLOCK_LIST'] = $applyData['ACTION_BLOCK_LIST'];
1779  $rulesList[] = $ruleData;
1780  unset($ruleData);
1781  }
1782  unset($basketCode, $applyData);
1783  }
1784  if (!empty($discount['RESULT']['DELIVERY']))
1785  {
1786  if (!isset($discount['RESULT']['DELIVERY']['RULE_ID']) || (int)$discount['RESULT']['DELIVERY']['RULE_ID'] < 0)
1787  {
1788  $process = false;
1789  $result->addError(new Main\Entity\EntityError(
1790  Loc::getMessage('BX_SALE_DISCOUNT_ERR_EMPTY_RULE_ID_SALE_DISCOUNT'),
1791  self::ERROR_ID
1792  ));
1793  continue;
1794  }
1795  $ruleData = array(
1796  'RULE_ID' => $discount['RESULT']['DELIVERY']['RULE_ID'],
1797  'APPLY' => $discount['RESULT']['DELIVERY']['APPLY'],
1798  'DESCR_ID' => (isset($discount['RESULT']['DELIVERY']['RULE_DESCR_ID']) ? (int)$discount['RESULT']['DELIVERY']['RULE_DESCR_ID'] : 0),
1799  'DESCR' => $discount['RESULT']['DELIVERY']['DESCR_DATA']
1800  );
1801  $rulesList[] = $ruleData;
1802  unset($ruleData);
1803  }
1804  }
1805  unset($discount);
1806  }
1807 
1808  if (!empty($applyBlock['BASKET_ROUND']))
1809  {
1810  foreach ($applyBlock['BASKET_ROUND'] as $row)
1811  {
1812  $roundList[] = array(
1813  'RULE_ID' => $row['RULE_ID'],
1814  'APPLY' => 'Y'
1815  );
1816  }
1817  unset($row);
1818  }
1819  }
1820 
1821  if ($process)
1822  {
1823  $ruleResult = $storageClassName::updateResultBlock($orderId, $rulesList);
1824  if (!$ruleResult->isSuccess())
1825  {
1826 
1827  }
1828  unset($ruleResult);
1829  $roundResult = $storageClassName::updateRoundBlock($orderId, $roundList);
1830  if (!$roundResult->isSuccess())
1831  {
1832 
1833  }
1834  unset($roundResult);
1835  }
1836 
1837  if ($process)
1838  {
1839  if (!empty($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]))
1840  {
1841  $couponClassName::finalApply();
1842  $couponClassName::saveApplied();
1843  $couponsResult = $this->saveCoupons();
1844  if (!$couponsResult->isSuccess())
1845  {
1846  $process = false;
1847  $result->addErrors($couponsResult->getErrors());
1848  }
1849 
1850  if ($process)
1851  {
1852  $lastApplyBlockResult = $this->saveLastApplyBlock();
1853  if (!$lastApplyBlockResult->isSuccess())
1854  {
1855  $process = false;
1856  $result->addErrors($lastApplyBlockResult->getErrors());
1857  }
1858  unset($lastApplyBlockResult);
1859  }
1860  }
1861  }
1862 
1863  if ($process)
1864  {
1865  if (!empty($this->discountStoredActionData))
1866  {
1867  $dataResult = $storageClassName::saveOrderStoredData(
1868  $orderId,
1869  $storageClassName::STORAGE_TYPE_DISCOUNT_ACTION_DATA,
1870  $this->discountStoredActionData,
1871  array('ALLOW_UPDATE' => 'Y')
1872  );
1873  if (!$dataResult->isSuccess())
1874  {
1875  $result->addError(new Main\Entity\EntityError(
1876  Loc::getMessage('BX_SALE_DISCOUNT_ERR_SAVE_APPLY_RULES'),
1877  self::ERROR_ID
1878  ));
1879  }
1880  unset($dataResult);
1881  }
1882  }
1883 
1884  if ($process)
1885  {
1886  if ($couponClassName::usedByManager())
1887  $couponClassName::clear(true);
1888  }
1889 
1890  return $result;
1891  }
saveCoupons()
Save coupons for order.
saveLastApplyBlock()
Save result last apply block discount.

◆ saveBasketStoredData()

saveBasketStoredData ( array  $basketCodeList)
protected

Save basket items stored data.

Аргументы
array$basketCodeListCode list.
Возвращает
Result

См. определение в файле discountbase.php строка 1643

1644  {
1645  $result = new Result();
1646  if (empty($basketCodeList))
1647  return $result;
1648  $useMode = $this->getUseMode();
1649  if ($useMode != self::USE_MODE_FULL && $useMode != self::USE_MODE_MIXED)
1650  return $result;
1651 
1652  $itemsData = [];
1653  foreach ($basketCodeList as $basketCode)
1654  {
1655  if (!isset($this->basketItemsData[$basketCode]))
1656  continue;
1657  $data = $this->prepareBasketItemStoredData($basketCode);
1658  if ($data === null)
1659  continue;
1660  $basketId = $this->forwardBasketTable[$basketCode];
1661  $itemsData[$basketId] = [
1662  'ENTITY_ID' => $basketId,
1663  'ENTITY_VALUE' => $basketId,
1664  'ENTITY_DATA' => $data
1665  ];
1666  }
1667  unset($data, $basketCode);
1668  if (!empty($itemsData))
1669  {
1670  $orderId = $this->getOrder()->getId();
1671  /** @var OrderDiscount $storageClassName */
1672  $storageClassName = $this->getOrderDiscountClassName();
1673  $dataResult = $storageClassName::saveStoredDataBlock(
1674  $orderId,
1675  $storageClassName::STORAGE_TYPE_BASKET_ITEM,
1676  $itemsData,
1677  ['ALLOW_UPDATE' => 'Y', 'DELETE_MISSING' => 'Y']
1678  );
1679  if (!$dataResult->isSuccess())
1680  {
1681  $result->addError(new Main\Entity\EntityError(
1682  Loc::getMessage('BX_SALE_DISCOUNT_ERR_SAVE_APPLY_RULES'),
1683  self::ERROR_ID
1684  ));
1685  }
1686  unset($dataResult, $storageClassName);
1687  }
1688  unset($itemsData);
1689 
1690  return $result;
1691  }

◆ saveCoupons()

saveCoupons ( )
protected

Save coupons for order.

Возвращает
Result

См. определение в файле discountbase.php строка 1924

1925  {
1926  $result = new Result;
1927  if (!$this->isOrderExists())
1928  return $result;
1929  if (!empty($this->couponsCache))
1930  {
1931  /** @var OrderDiscount $storageClassName */
1932  $storageClassName = $this->getOrderDiscountClassName();
1933 
1934  $orderId = $this->getOrder()->getId();
1935  foreach ($this->couponsCache as $orderCouponId => $couponData)
1936  {
1937  if ($couponData['ID'] > 0)
1938  continue;
1939  $fields = $couponData;
1940  $fields['ORDER_ID'] = $orderId;
1941  $couponResult = $storageClassName::saveCoupon($fields);
1942  if (!$couponResult->isSuccess())
1943  {
1944  $result->addErrors($couponResult->getErrors());
1945  unset($couponResult);
1946  continue;
1947  }
1948  $this->couponsCache[$orderCouponId]['ID'] = $couponResult->getId();
1949  unset($couponResult);
1950  }
1951  unset($orderId);
1952  unset($storageClassName);
1953  }
1954  return $result;
1955  }

◆ saveFull()

saveFull ( )
protected

Save discount result for new order.

Возвращает
Result

См. определение в файле discountbase.php строка 1507

1508  {
1509  $result = new Result;
1510 
1511  $process = true;
1512  $orderId = $this->getOrder()->getId();
1513 
1514  /** @var OrderDiscount $storageClassName */
1515  $storageClassName = $this->getOrderDiscountClassName();
1516  /** @var DiscountCouponsManager $couponClassName */
1517  $couponClassName = $this->getDiscountCouponClassName();
1518 
1519  if (!Compatible\DiscountCompatibility::isUsed() || !Compatible\DiscountCompatibility::isInited())
1520  {
1521  $basketResult = $this->getBasketTables();
1522  if (!$basketResult->isSuccess())
1523  {
1524  $process = false;
1525  $result->addErrors($basketResult->getErrors());
1526  }
1527  }
1528 
1529  if ($process)
1530  {
1531  $couponClassName::finalApply();
1532  $couponClassName::saveApplied();
1533  $couponsResult = $this->saveCoupons();
1534  if (!$couponsResult->isSuccess())
1535  {
1536  $process = false;
1537  $result->addErrors($couponsResult->getErrors());
1538  }
1539  }
1540 
1541  if ($process)
1542  {
1543  $storageClassName::deleteByOrder($orderId);
1544 
1545  $lastApplyBlockResult = $this->saveLastApplyBlock();
1546  if (!$lastApplyBlockResult->isSuccess())
1547  {
1548  $process = false;
1549  $result->addErrors($lastApplyBlockResult->getErrors());
1550  }
1551  unset($lastApplyBlockResult);
1552  }
1553 
1554  if ($process)
1555  {
1556  $config = $this->getOrderConfig();
1557  $dataResult = $storageClassName::saveOrderStoredData(
1558  $orderId,
1559  $storageClassName::STORAGE_TYPE_ORDER_CONFIG,
1560  $config
1561  );
1562  if (!$dataResult->isSuccess())
1563  {
1564  $result->addError(new Main\Entity\EntityError(
1565  Loc::getMessage('BX_SALE_DISCOUNT_ERR_SAVE_APPLY_RULES'),
1566  self::ERROR_ID
1567  ));
1568  }
1569  unset($dataResult, $config);
1570 
1571  $config = array(
1572  'MODE' => $this->roundApplyMode,
1573  'CONFIG' => $this->roundApplyConfig
1574  );
1575  $dataResult = $storageClassName::saveOrderStoredData(
1576  $orderId,
1577  $storageClassName::STORAGE_TYPE_ROUND_CONFIG,
1578  $config,
1579  array('ALLOW_UPDATE' => 'Y')
1580  );
1581  if (!$dataResult->isSuccess())
1582  {
1583  $result->addError(new Main\Entity\EntityError(
1584  Loc::getMessage('BX_SALE_DISCOUNT_ERR_SAVE_APPLY_RULES'),
1585  self::ERROR_ID
1586  ));
1587  }
1588  unset($dataResult, $config);
1589 
1590  if (!empty($this->discountStoredActionData))
1591  {
1592  $dataResult = $storageClassName::saveOrderStoredData(
1593  $orderId,
1594  $storageClassName::STORAGE_TYPE_DISCOUNT_ACTION_DATA,
1595  $this->discountStoredActionData,
1596  array('ALLOW_UPDATE' => 'Y')
1597  );
1598  if (!$dataResult->isSuccess())
1599  {
1600  $result->addError(new Main\Entity\EntityError(
1601  Loc::getMessage('BX_SALE_DISCOUNT_ERR_SAVE_APPLY_RULES'),
1602  self::ERROR_ID
1603  ));
1604  }
1605  unset($dataResult);
1606  }
1607 
1608  $dataResult = $this->saveBasketStoredData($this->getBasketCodes(true));
1609  if (!$dataResult->isSuccess())
1610  {
1611  $result->addErrors($dataResult->getErrors());
1612  }
1613  unset($dataResult);
1614  }
1615 
1616  if ($process)
1617  {
1618  if ($couponClassName::usedByManager())
1619