Bitrix-D7  20.0.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  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ calculateApplyBasketAdditionalCoupons()

calculateApplyBasketAdditionalCoupons ( array  $applyCoupons)
protected

Calculate additional basket coupons.

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

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

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

◆ 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  }

◆ 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  }

◆ calculateApplySaleAdditionalCoupons()

calculateApplySaleAdditionalCoupons ( array  $applyCoupons)
protected

Calculate additional sale coupons.

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

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

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

◆ 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  }

◆ 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 строка 5680

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

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ clearAdditionalCoupons()

clearAdditionalCoupons ( array  $coupons)
protected

Clear coupons from already used discounts.

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

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

◆ clearCurrentApplyBlock()

clearCurrentApplyBlock ( )
protected

Internal.

Fill current apply block empty data.

Возвращает
void

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

4395  {
4396  $this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter] = $this->getEmptyApplyBlock();
4397  }

◆ 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  }

◆ executeDiscountList()

executeDiscountList ( )
protected

Execute sale discount list.

Возвращает
Result

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

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

◆ extendOrderData()

extendOrderData ( )
protected

Extend order data for discounts.

Возвращает
void

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

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

◆ fillBasketLastDiscount()

fillBasketLastDiscount ( )
protected

Fill last discount flag for basket items.

Only for basket or new order or refreshed order.

Возвращает
void

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

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

◆ fillCurrentStep()

fillCurrentStep (   $data)
protected

Internal.

Fill current step data.

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

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

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

◆ fillDiscountResult()

fillDiscountResult ( )
protected

Fill result order data.

Возвращает
array

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

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

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

◆ fillEmptyCurrentStep()

fillEmptyCurrentStep ( )
protected

Internal.

Clear current step data.

Возвращает
void

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

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

◆ 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 = array();
4358  $this->basketItemsData = array();
4359  }

◆ 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  }

◆ formatDescription()

static formatDescription (   $descr)
staticprotected

Return formatted discount description.

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

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

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

◆ getAdditionalCoupons()

getAdditionalCoupons ( array  $filter = array())
protected

Return additional coupons for exist order.

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

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

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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 строка 5352

5353  {
5354  return 'UNPACK';
5355  }

◆ getCurrency()

getCurrency ( )
protected

Return order currency for calculate.

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

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

◆ getDiscountCouponClassName()

getDiscountCouponClassName ( )
protected

Returns current discount coupons manager class name.

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

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

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

◆ 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 строка 5664

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

◆ 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 строка 5340

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

◆ getExecuteFieldName()

static getExecuteFieldName (   $fieldName)
staticfinalprotected

Return field name for save eval result.

Only for core.

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

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

◆ getInstance()

static getInstance (   $index)
staticprotected

Returns discount instance.

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

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

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

◆ getInstanceIndexByBasket()

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

Return instance index for basket.

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

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

◆ getInstanceIndexByOrder()

static getInstanceIndexByOrder ( OrderBase  $order)
staticprotected

Return instance index for order.

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

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

◆ 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 строка 5241

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

◆ 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 строка 5534

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

◆ getOrderPropertyCodes()

static getOrderPropertyCodes ( )
staticprotected

Return order property codes for translate to order fields.

Возвращает
array

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

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

◆ getRegistryType()

static getRegistryType ( )
static

Return parent entity type.

The method must be overridden in the derived class.

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

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

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

◆ 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 строка 5562

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

◆ getShowPrices()

getShowPrices ( )

Returns show prices for public components.

Возвращает
array

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

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

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

◆ getSiteCurrency()

getSiteCurrency ( )
protected

Return site currency.

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

5306  {
5308  if (is_array($result))
5309  return $result['CURRENCY'];
5310  $result = (string)Main\Config\Option::get('sale', 'default_currency');
5311  if ($result !== '')
5312  return $result;
5314  if ($result !== '')
5315  return $result;
5316  return null;
5317  }

◆ getSiteId()

getSiteId ( )
protected

Return site id for calculate.

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

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

◆ getStatusApplyBasketDiscount()

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

Return apply status for basket discount.

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

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

◆ 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  }

◆ 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  }

◆ instanceExists()

static instanceExists (   $index)
staticprotected

Returns true, if instance exist.

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

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

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

◆ 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 строка 4737

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

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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 строка 5251

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

◆ 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  }

◆ 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  }

◆ loadDiscountByUserGroups()

loadDiscountByUserGroups ( array  $filter = array())
protected

Load from database discount id for user groups.

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

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

◆ loadDiscountList()

loadDiscountList ( )
protected

Load sale discount from database.

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

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

◆ loadDiscountModules()

loadDiscountModules ( array  $modules)
protected

Load discount modules.

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

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

◆ 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  }

◆ 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  }

◆ 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  }

◆ migrateInstance()

static migrateInstance (   $oldIndex,
  $newIndex 
)
staticprotected

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

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

◆ modifyOrderData()

modifyOrderData ( $newData)
protected

Modify order data from handlers.

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

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

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

◆ normalizeDiscountResult()

normalizeDiscountResult ( )
protected

Round and correct discount calculation results.

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

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

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

◆ 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 строка 5637

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

◆ 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 строка 5184

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

◆ resetBasketPrices()

resetBasketPrices ( )
protected

Fill basket prices from base prices.

Возвращает
void

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

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

◆ resetDiscountAppliedFlag()

resetDiscountAppliedFlag ( )
protected

Reset flag of applying discounts for basket items.

Возвращает
void

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

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

◆ resetOrderState()

resetOrderState ( )
protected

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

Возвращает
void

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

4541  {
4542  $this->resetPrices();
4543  $this->resetDiscountAppliedFlag();
4544  }

◆ resetPrices()

resetPrices ( )
protected

Fill prices from base prices.

Возвращает
void

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

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

4552  {
4553  $this->resetBasketPrices();
4554  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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  $couponClassName::clear(true);
1620  }
1621 
1622  return $result;
1623  }

◆ saveLastApplyBlock()

saveLastApplyBlock ( )
protected

Save result last apply block discount.

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

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

1964  {
1965  $result = new Result;
1966 
1967  $orderId = $this->getOrder()->getId();
1968 
1969  $applyBlock = &$this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter];
1970  /** @var OrderDiscount $storageClassName */
1971  $storageClassName = $this->getOrderDiscountClassName();
1972 
1973  $rulesList = array();
1974  if (!empty($applyBlock['BASKET']))
1975  {
1976  foreach ($applyBlock['BASKET'] as $basketCode => $discountList)
1977  {
1978  $commonFields = $this->getEntitySaveIdentifier([
1979  'ENTITY_TYPE' => self::ENTITY_BASKET_ITEM,
1980  'ENTITY_CODE' => $basketCode
1981  ]);
1982  if ($commonFields === null)
1983  continue;
1984  foreach ($discountList as $discount)
1985  {
1986  $rulesList[] = $commonFields + [
1987  'ORDER_DISCOUNT_ID' => $discount['DISCOUNT_ID'],
1988  'COUPON_ID' => $discount['COUPON_ID'],
1989  'APPLY' => $discount['RESULT']['APPLY'],
1990  'DESCR' => $discount['RESULT']['DESCR_DATA']
1991  ];
1992  }
1993  unset($discount);
1994  }
1995  unset($discount, $commonFields, $discountList, $basketCode);
1996  }
1997  if (!empty($applyBlock['ORDER']))
1998  {
1999  foreach ($applyBlock['ORDER'] as $discount)
2000  {
2001  if (!empty($discount['RESULT']['BASKET']))
2002  {
2003  foreach ($discount['RESULT']['BASKET'] as $basketCode => $applyData)
2004  {
2005  $commonFields = $this->getEntitySaveIdentifier([
2006  'ENTITY_TYPE' => self::ENTITY_BASKET_ITEM,
2007  'ENTITY_CODE' => $basketCode
2008  ]);
2009  if ($commonFields === null)
2010  continue;
2011  $rulesList[] = $commonFields + [
2012  'ORDER_DISCOUNT_ID' => $discount['DISCOUNT_ID'],
2013  'COUPON_ID' => $discount['COUPON_ID'],
2014  'APPLY' => $applyData['APPLY'],
2015  'ACTION_BLOCK_LIST' => $applyData['ACTION_BLOCK_LIST'],
2016  'DESCR' => $applyData['DESCR_DATA']
2017  ];
2018  }
2019  unset($commonFields, $basketCode, $applyData);
2020  }
2021  if (!empty($discount['RESULT']['DELIVERY']))
2022  {
2023  $commonFields = $this->getEntitySaveIdentifier([
2024  'ENTITY_TYPE' => self::ENTITY_DELIVERY,
2025  'ENTITY_CODE' => $discount['RESULT']['DELIVERY']['DELIVERY_ID']
2026  ]);
2027  if ($commonFields === null)
2028  continue;
2029  $rulesList[] = $commonFields + [
2030  'ORDER_DISCOUNT_ID' => $discount['DISCOUNT_ID'],
2031  'COUPON_ID' => $discount['COUPON_ID'],
2032  'APPLY' => $discount['RESULT']['DELIVERY']['APPLY'],
2033  'DESCR' => $discount['RESULT']['DELIVERY']['DESCR_DATA']
2034  ];
2035  unset($commonFields);
2036  }
2037  }
2038  unset($discount);
2039  }
2040 
2041  if (!empty($rulesList))
2042  {
2043  $this->normalizeNewResultRows($rulesList);
2044  $blockResult = $storageClassName::addResultBlock($orderId, $rulesList);
2045  if (!$blockResult->isSuccess())
2046  {
2047  $result->addError(new Main\Entity\EntityError(
2048  Loc::getMessage('BX_SALE_DISCOUNT_ERR_SAVE_APPLY_RULES'),
2049  self::ERROR_ID
2050  ));
2051  }
2052  unset($blockResult);
2053  }
2054  unset($rulesList);
2055 
2056  if (!empty($applyBlock['BASKET_ROUND']))
2057  {
2058  $roundList = array();
2059  foreach ($applyBlock['BASKET_ROUND'] as $basketCode => $roundData)
2060  {
2061  $commonFields = $this->getEntitySaveIdentifier([
2062  'ENTITY_TYPE' => self::ENTITY_BASKET_ITEM,
2063  'ENTITY_CODE' => $basketCode
2064  ]);
2065  if ($commonFields === null)
2066  continue;
2067  $roundList[] = $commonFields + [
2068  'APPLY' => $roundData['APPLY'],
2069  'ROUND_RULE' => $roundData['ROUND_RULE']
2070  ];
2071  }
2072  unset($commonFields, $roundData, $basketCode);
2073  if (!empty($roundList))
2074  {
2075  $this->normalizeNewResultRows($roundList);
2076  $blockResult = $storageClassName::addRoundBlock($orderId, $roundList);
2077  if (!$blockResult->isSuccess())
2078  {
2079  $result->addError(new Main\Entity\EntityError(
2080  Loc::getMessage('BX_SALE_DISCOUNT_ERR_SAVE_APPLY_RULES'),
2081  self::ERROR_ID
2082  ));
2083  }
2084  unset($blockResult);
2085  }
2086  unset($roundList);
2087  }
2088 
2089  unset($applyBlock);
2090 
2091  return $result;
2092  }

◆ saveMixed()

saveMixed ( )
protected

Save discount result for mixed order.

Возвращает
Result

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

1899  {
1900  $result = $this->saveApply();
1901 
1902  if ($result->isSuccess())
1903  {
1904  $basketCodeList = array_merge(
1905  $this->getBasketCodes(false),
1906  $this->getBasketCodes(true)
1907  );
1908  $dataResult = $this->saveBasketStoredData($basketCodeList);
1909  if (!$dataResult->isSuccess())
1910  {
1911  $result->addErrors($dataResult->getErrors());
1912  }
1913  unset($dataResult, $basketCodeList);
1914  }
1915 
1916  return $result;
1917  }

◆ setApplyResult()

setApplyResult (   $applyResult)

Change applied discount list.

Аргументы
array$applyResultChange apply result.
Возвращает
void

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

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

521  {
522  if (is_array($applyResult))
523  $this->applyResult = $applyResult;
524 
525  if (!empty($this->applyResult['DISCOUNT_LIST']))
526  {
527  if (!empty($this->applyResult['BASKET']) && is_array($this->applyResult['BASKET']))
528  {
529  foreach ($this->applyResult['BASKET'] as $discountList)
530  {
531  if (empty($discountList) || !is_array($discountList))
532  continue;
533  foreach ($discountList as $orderDiscountId => $apply)
534  {
535  if ($apply == 'Y')
536  $this->applyResult['DISCOUNT_LIST'][$orderDiscountId] = 'Y';
537  }
538  unset($apply, $orderDiscountId);
539  }
540  unset($discountList);
541  }
542  }
543  }

◆ setDiscountStoredActionData()

setDiscountStoredActionData (   $orderDiscountId,
array  $data 
)
protected

Fill additional discount data.

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

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

3688  {
3689  $orderDiscountId = (int)$orderDiscountId;
3690  if (!isset($this->discountsCache[$orderDiscountId]))
3691  return;
3692  if (empty($data))
3693  return;
3694  if (!isset($this->discountStoredActionData[$this->discountResultCounter]))
3695  $this->discountStoredActionData[$this->discountResultCounter] = array();
3696  $this->discountStoredActionData[$this->discountResultCounter][$orderDiscountId] = $data;
3697  }

◆ setExecuteModuleFilter()

setExecuteModuleFilter ( array  $moduleList)

Sets list of execute module which will be used to filter discount.

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

380  {
381  $this->executeModuleFilter = $moduleList;
382  }

◆ setNewOrder()

setNewOrder ( )
protected

Set new order flag.

Возвращает
void

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

237  {
238  if ($this->newOrder !== null)
239  return;
240  $this->newOrder = true;
241  if ($this->isOrderExists())
242  $this->newOrder = ((int)$this->getOrder()->getId() <= 0);
243  }

◆ setOrder()

static setOrder ( BasketBase  $basket)
static

Get discount by order basket.

Аргументы
BasketBase$basketBasket.
Возвращает
DiscountBase

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

317  {
318  $order = $basket->getOrder();
319  if (!($order instanceof OrderBase))
320  {
321  throw new Main\InvalidOperationException();
322  }
323  $instanceIndex = static::getInstanceIndexByBasket($basket);
324  if (!static::instanceExists($instanceIndex))
325  return static::buildFromOrder($order);
326 
327  $newInstanceIndex = static::getInstanceIndexByOrder($order);
328  if (!static::instanceExists($newInstanceIndex))
329  {
330  /** @var Discount $discount */
331  $discount = static::getInstance($instanceIndex);
332  $discount->basket = null;
333  $discount->order = $order;
334  $discount->context = new Context\User($order->getUserId());
335  $discount->initInstanceFromOrder();
336  unset($discount);
337  static::migrateInstance($instanceIndex, $newInstanceIndex);
338  }
339  else
340  {
341  static::removeInstance($instanceIndex);
342  }
343  return static::getInstance($newInstanceIndex);
344  }

◆ setOrderRefresh()

setOrderRefresh (   $state)

Set full refresh status from edit order form.

Аргументы
bool$stateRefresh or not order.
Возвращает
void

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

205  {
206  if ($state !== true && $state !== false)
207  return;
208  $this->orderRefresh = $state;
209  }

◆ setRoundIndex()

setRoundIndex (   $entity,
array  $index 
)
protected

Set discount index for use round.

Only for sale discount mode.

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

3222  {
3223  if (!$this->isRoundMode(self::ROUND_MODE_SALE_DISCOUNT))
3224  return;
3225  if (!isset($index['DISCOUNT_INDEX']) || !isset($index['DISCOUNT_ID']))
3226  return;
3227  if (!isset($this->roundApplyConfig[$this->discountResultCounter]))
3228  $this->roundApplyConfig[$this->discountResultCounter] = array();
3229  $this->roundApplyConfig[$this->discountResultCounter][$entity] = $index;
3230  }

◆ setUseMode()

setUseMode (   $useMode)

Set calculate mode.

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

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

355  {
356  $useMode = (int)$useMode;
357  if ($useMode <= 0)
358  return;
359  $this->useMode = $useMode;
360  }

◆ setValidState()

setValidState (   $value)
protected

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

703  {
704  if (!is_bool($value))
705  return;
706  $this->valid = $value;
707  }

◆ stopCalculate()

stopCalculate ( )
protected

Return is allow discount calculate.

Возвращает
bool

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

748  {
749  if (!$this->isBasketNotEmpty())
750  return true;
751  if ($this->isOrderExists() && $this->getOrder()->isExternal())
752  return true;
753  return false;
754  }

◆ tryToRevertApplyStatusInBlocks()

tryToRevertApplyStatusInBlocks ( array  $stepResult)
protected

Tries to revert apply status of discounts.

It depends on current $stepResult. If it has REVERT_APPLY like true, that we have to cancel discounts on basket items which were affected.

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

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

2940  {
2941  if (empty($stepResult['BASKET']))
2942  {
2943  return;
2944  }
2945 
2946  foreach ($stepResult['BASKET'] as $basketItemId => $item)
2947  {
2948  if ($item['APPLY'] !== 'Y')
2949  {
2950  continue;
2951  }
2952 
2953  if (empty($item['DESCR_DATA']))
2954  {
2955  continue;
2956  }
2957 
2958  foreach ($item['DESCR_DATA'] as $rowDescription)
2959  {
2960  //TODO: remove this hack
2961  if (
2962  !empty($rowDescription['REVERT_APPLY']) &&
2963  $rowDescription['VALUE_ACTION'] === Discount\Formatter::VALUE_ACTION_CUMULATIVE
2964  )
2965  {
2966  $this->revertApplyBlockForBasketItem($basketItemId);
2967  }
2968  }
2969  }
2970  }

◆ useOnlySaleDiscounts()

useOnlySaleDiscounts ( )
protected

Return true, if only sale discounts is allowed.

For new order or refreshed order use sale option, otherwise use order option.

Возвращает
bool

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

762  {
763  if (!$this->isOrderExists() || $this->isOrderNew() || $this->isOrderRefresh())
764  return (string)Main\Config\Option::get('sale', 'use_sale_discount_only') == 'Y';
765  else
766  return (isset($this->saleOptions['SALE_DISCOUNT_ONLY']) && $this->saleOptions['SALE_DISCOUNT_ONLY'] == 'Y');
767  }

◆ validateLoadedOrderConfig()

validateLoadedOrderConfig (   $config)
protected

Validate loaded order config.

Аргументы
mixed$configOrder configuration.
Возвращает
bool

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

1062  {
1063  if (empty($config) || !is_array($config))
1064  return false;
1065  if (empty($config['OPTIONS']) || !is_array($config['OPTIONS']))
1066  return false;
1067  return true;
1068  }

◆ verify()

verify ( )

Verifies discounts before order save.

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

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

585  {
586  $result = new Result();
587 
588  $useMode = $this->getUseMode();
589  if ($useMode == self::USE_MODE_APPLY || $useMode == self::USE_MODE_MIXED)
590  {
591  if (!$this->isValidState())
592  return $result;
593  }
594 
595  if (empty($this->discountResult['APPLY_BLOCKS'][$this->discountResultCounter]))
596  return $result;
597 
598  /** @var DiscountCouponsManager $couponClassName */
599  $couponClassName = $this->getDiscountCouponClassName();
600 
601  $checkCoupons = $couponClassName::verifyApplied();
602  if (!$checkCoupons->isSuccess())
603  {
604  $result->addError(new Main\Error(
605  Loc::getMessage('BX_SALE_DISCOUNT_ERR_BAD_COUPONS_USED')
606  ));
607  $errors = $checkCoupons->getErrors();
608  $row = reset($errors);
609  foreach ($row->getCustomData() as $coupon => $description)
610  {
611  $result->addError(new Main\Error(
612  $coupon.' : '.$description
613  ));
614  }
615  unset($coupon, $description, $row, $errors);
616  }
617  unset($checkCoupons, $couponClassName);
618 
619  return $result;
620  }

Поля

◆ $applyResult

$applyResult = array()
protected

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

◆ $basket

$basket = null
protected

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

◆ $basketDiscountList

$basketDiscountList = array()
protected

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

◆ $basketItemsData

$basketItemsData = array()
protected

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

◆ $context

$context
protected

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

◆ $couponsCache

$couponsCache = array()
protected

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

◆ $currentStep

$currentStep = array()
protected

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

◆ $discountIds

$discountIds = null
protected

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

◆ $discountResult

$discountResult = array()
protected

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

◆ $discountResultCounter

$discountResultCounter = 0
protected

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

◆ $discountsCache

$discountsCache = array()
protected

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

◆ $discountStoredActionData

$discountStoredActionData = array()
protected

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

◆ $entityList

$entityList = array()
protected

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

◆ $entityResultCache

$entityResultCache = array()
protected

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

χ