20 const ERROR_ID =
'BX_SALE_DISCOUNT_COMPATIBILITY';
50 public static function OnSaleBasketItemRefreshData(Main\
Event $event)
52 if (static::isInited() && static::usedByClient())
54 $parameters = $event->getParameters();
56 $basketItem = $parameters[
'ENTITY'];
58 $values = $parameters[
'PREPARED_VALUES'];
68 static::setBasketItemData($basketItem->getBasketCode(), $values);
70 unset($values, $basketItem);
90 $adminSection = (defined(
'ADMIN_SECTION') && ADMIN_SECTION ===
true);
103 elseif (empty(
$config[
'CURRENCY']))
104 $config[
'CURRENCY'] = Sale\Internals\SiteCurrencyTable::getCurrency(
$config[
'SITE_ID']);
105 if (empty(
$config[
'CURRENCY']))
107 if (empty(self::$errors))
110 $config[
'SALE_DISCOUNT_ONLY'] = (string)Main\
Config\Option::get(
'sale',
'use_sale_discount_only');
112 self::$discountUseMode = Sale\Discount::USE_MODE_FULL;
116 if (empty(
$config[
'ORDER_ID']))
120 if (empty(
$config[
'CURRENCY']))
122 if (empty(self::$errors))
125 self::$order =
$config[
'ORDER_ID'];
145 if (empty(
$config[
'CURRENCY']))
146 $config[
'CURRENCY'] = Sale\Internals\SiteCurrencyTable::getSiteCurrency(
$config[
'SITE_ID']);
147 $config[
'SALE_DISCOUNT_ONLY'] = (string)Main\
Config\Option::get(
'sale',
'use_sale_discount_only');
149 self::$discountUseMode = Sale\Discount::USE_MODE_FULL;
155 if (empty(
$config[
'CURRENCY']))
157 $config[
'SALE_DISCOUNT_ONLY'] = (string)Main\
Config\Option::get(
'sale',
'use_sale_discount_only');
159 self::$discountUseMode = Sale\Discount::USE_MODE_FULL;
190 return (self::$useMode == self::MODE_CLIENT);
200 return (self::$useMode == self::MODE_MANAGER || self::$useMode == self::MODE_ORDER);
223 if ($save !==
true && $save !==
false)
225 self::$saved = $save;
248 if ($repeat !==
true && $repeat !==
false)
250 self::$repeatSave = $repeat;
260 return empty(self::$errors);
280 self::$errors = array();
303 self::$shipmentOrder =
$order;
304 self::$shipmentId = $shipment;
314 public static function init($mode = self::MODE_CLIENT,
$config = array())
320 if (!self::isSuccess())
322 self::$basketBasePrice = array();
323 self::$basketDiscountList = array();
324 self::$basketItemsData = array();
325 self::$useCompatible =
true;
326 Sale\OrderDiscountManager::setManagerConfig(self::$config);
327 self::$saved =
false;
328 self::$repeatSave =
false;
374 if(self::$useCompatible)
376 self::$useCompatible =
false;
388 if(self::$init && !self::$useCompatible)
390 self::$useCompatible =
true;
406 if (!self::isSuccess() || self::$useMode == self::MODE_SYSTEM || self::$useMode == self::MODE_DISABLED)
409 self::$basketBasePrice[$code] = (
410 $currency == self::$config[
'CURRENCY']
412 : \CCurrencyRates::convertCurrency($price, $currency, self::$config[
'CURRENCY'])
427 if (!self::isSuccess() || self::$useMode == self::MODE_SYSTEM || self::$useMode == self::MODE_DISABLED)
429 self::$basketBasePrice = array();
430 if (empty($basket) || !is_array($basket))
432 foreach ($basket as $code => $basketItem)
435 self::$basketBasePrice[$code] = (
436 $basketItem[
'CURRENCY'] == self::$config[
'CURRENCY']
437 ? $basketItem[
'PRICE']
438 : \CCurrencyRates::convertCurrency($basketItem[
'PRICE'], $basketItem[
'CURRENCY'], self::$config[
'CURRENCY'])
441 unset($code, $basketItem);
454 return (isset(self::$basketBasePrice[$code]) ? self::$basketBasePrice[$code] :
null);
468 if (!self::isSuccess() || self::$useMode == self::MODE_SYSTEM || self::$useMode == self::MODE_DISABLED)
470 if (self::$config[
'SALE_DISCOUNT_ONLY'] ==
'Y')
472 if (!is_array($discountList))
474 self::$basketDiscountList[$code] = $discountList;
487 if (self::$config[
'SALE_DISCOUNT_ONLY'] ==
'Y')
489 return (isset(self::$basketDiscountList[$code]) ? self::$basketDiscountList[$code] :
null);
499 if ($code ==
'' || empty($providerData) || !is_array($providerData))
501 if (isset($providerData[
'CUSTOM_PRICE']) && $providerData[
'CUSTOM_PRICE'] ==
'Y')
503 static::clearBasketItemData($code);
506 if (isset($providerData[
'BASE_PRICE']) && isset($providerData[
'CURRENCY']))
507 static::setBasketItemBasePrice($code, $providerData[
'BASE_PRICE'], $providerData[
'CURRENCY']);
508 if (isset($providerData[
'DISCOUNT_LIST']))
510 if (!empty($providerData[
'DISCOUNT_LIST']) || isset(self::$basketDiscountList[$code]))
511 static::setBasketItemDiscounts($code, $providerData[
'DISCOUNT_LIST']);
514 $fields[
'PRICE'] = static::getBasketItemBasePrice($code);
515 if (empty($fields[
'PRICE']))
518 self::$basketItemsData[$code] = $providerData;
520 $fields[
'DISCOUNT_PRICE'] = 0;
521 $fields[
'CURRENCY'] = self::$config[
'CURRENCY'];
523 if (self::$config[
'SALE_DISCOUNT_ONLY'] ==
'Y')
525 static::calculateBasketItemDiscount($code, $fields);
536 if (isset(self::$basketBasePrice[$code]))
537 unset(self::$basketBasePrice[$code]);
538 if (isset(self::$basketDiscountList[$code]))
539 unset(self::$basketDiscountList[$code]);
540 if (isset(self::$discountResult[
'BASKET'][$code]))
541 unset(self::$discountResult[
'BASKET'][$code]);
542 if (isset(self::$basketItemsData[$code]))
543 unset(self::$basketItemsData[$code]);
553 self::$discountResult = array(
555 'BASKET_ROUND' => array(),
558 self::$compatibleSaleDiscountResult = array();
571 if (!self::isSuccess() || self::$useMode == self::MODE_SYSTEM || self::$useMode == self::MODE_DISABLED)
573 if (empty($basket) || !is_array($basket))
577 $loadBasketProperties = array();
578 foreach ($basket as $basketCode => $basketItem)
580 $code = ($publicMode ? $basketItem[
'ID'] : $basketCode);
581 if (!isset($basketItem[
'DISCOUNT_PRICE']))
582 $basketItem[
'DISCOUNT_PRICE'] = 0;
583 if (!isset($basketItem[
'BASE_PRICE']))
585 $basketItem[
'BASE_PRICE'] = (isset(self::$basketBasePrice[$code])
586 ? self::$basketBasePrice[$code]
587 : $basketItem[
'PRICE'] + $basketItem[
'DISCOUNT_PRICE']
590 $checkProperties =
true;
591 if (self::isCustomPrice($basketItem))
593 if (array_key_exists($code, self::$basketDiscountList))
594 unset(self::$basketDiscountList[$code]);
595 $checkProperties =
false;
597 if (\CSaleBasketHelper::isSetItem($basketItem))
599 $basketItem[
'PRICE'] = $basketItem[
'BASE_PRICE'];
600 $basketItem[
'DISCOUNT_PRICE'] = 0;
601 $checkProperties =
false;
603 if (isset(self::$basketItemsData[$code]))
605 if (isset(self::$basketItemsData[$code][
'PRICE_TYPE_ID']))
606 $basketItem[
'PRICE_TYPE_ID'] = self::$basketItemsData[$code][
'PRICE_TYPE_ID'];
609 if ($checkProperties)
611 if (!isset($basketItem[
'PROPERTIES']))
613 if (isset($basketItem[
'PROPS']))
614 $basketItem[
'PROPERTIES'] = $basketItem[
'PROPS'];
615 elseif (isset($basketItem[
'ID']))
617 $loadBasketProperties[$basketItem[
'ID']] = $basketCode;
618 $basketItem[
'PROPERTIES'] = array();
622 $basketItem[
'ACTION_APPLIED'] =
'N';
623 $basket[$basketCode] = $basketItem;
626 if (!empty($loadBasketProperties))
628 $iterator = Sale\BasketPropertiesCollection::getList(array(
629 'select' => array(
'*'),
630 'filter' => array(
'BASKET_ID' =>
'ASC',
'SORT' =>
'ASC',
'ID' =>
'ASC')
632 while ($row = $iterator->fetch())
635 if (!isset($loadBasketProperties[$id]))
637 $basketCode = $loadBasketProperties[$id];
638 $basket[$basketCode][
'PROPERTIES'][] = array(
639 'CODE' => ((
string)$row[
'CODE'] !=
'' ? $row[
'CODE'] : $row[
'NAME']),
641 'VALUE' => $row[
'VALUE'],
642 'SORT' => $row[
'SORT'],
643 'NAME' => $row[
'NAME']
646 unset($row, $iterator);
648 unset($loadBasketProperties);
650 unset($basketCode, $basketItem);
663 if (!self::isSuccess() || self::$useMode == self::MODE_SYSTEM || self::$useMode == self::MODE_DISABLED)
665 if (empty($basket) || !is_array($basket))
667 Sale\DiscountCouponsManager::clearApply();
668 if (self::$config[
'SALE_DISCOUNT_ONLY'] ==
'Y' || empty(self::$basketDiscountList))
672 foreach ($basket as $basketCode => $basketItem)
674 $code = ($publicMode ? $basketItem[
'ID'] : $basketCode);
675 if (!static::calculateBasketItemDiscount($code, $basketItem))
677 if (!empty(self::$discountResult[
'BASKET'][$code]))
679 foreach (self::$discountResult[
'BASKET'][$code] as $row)
681 if ($row[
'RESULT'][
'APPLY'] ==
'Y')
683 $basket[$basketCode][
'ACTION_APPLIED'] =
'Y';
690 unset($basketCode, $basketItem);
705 if (!self::isSuccess() || self::$useMode == self::MODE_SYSTEM || self::$useMode == self::MODE_DISABLED)
707 if (empty($basket) || !is_array($basket))
713 case Sale\Discount::APPLY_MODE_DISABLE:
714 case Sale\Discount::APPLY_MODE_FULL_DISABLE:
715 foreach ($basket as $basketCode => $basketItem)
717 $code = ($publicMode ? $basketItem[
'ID'] : $basketCode);
718 if (isset(self::$basketDiscountList[$code]) && !empty(self::$basketDiscountList[$code]))
719 $basket[$basketCode][
'LAST_DISCOUNT'] =
'Y';
722 unset($basketCode, $basketItem);
724 case Sale\Discount::APPLY_MODE_LAST:
725 case Sale\Discount::APPLY_MODE_FULL_LAST:
726 foreach ($basket as $basketCode => $basketItem)
728 $code = ($publicMode ? $basketItem[
'ID'] : $basketCode);
729 if (!isset(self::$basketDiscountList[$code]) || empty(self::$basketDiscountList[$code]))
731 $lastDiscount = end(self::$basketDiscountList[$code]);
732 if (!empty($lastDiscount[
'LAST_DISCOUNT']) && $lastDiscount[
'LAST_DISCOUNT'] ==
'Y')
733 $basket[$basketCode][
'LAST_DISCOUNT'] =
'Y';
735 unset($basketCode, $basketItem);
737 case Sale\Discount::APPLY_MODE_ADD:
750 if (array_key_exists(
'DISCOUNT_DESCR',
$order))
751 unset(
$order[
'DISCOUNT_DESCR']);
752 if (array_key_exists(
'DISCOUNT_RESULT',
$order))
753 unset(
$order[
'DISCOUNT_RESULT']);
754 self::$previousOrderData =
$order;
765 self::$compatibleSaleDiscountResult = $discountList;
789 if (!self::isSuccess())
792 $order[
'DISCOUNT_RESULT'] = Sale\Discount\Actions::getActionResult();
793 $order[
'DISCOUNT_DESCR'] = Sale\Discount\Actions::getActionDescription();
794 if (!empty(
$order[
'DISCOUNT_RESULT']) && is_array(
$order[
'DISCOUNT_RESULT']))
801 if (!empty($stepResult))
803 if (empty(
$order[
'DISCOUNT_DESCR']) || !is_array(
$order[
'DISCOUNT_DESCR']))
804 $order[
'DISCOUNT_DESCR'] = Discount\Result\CompatibleFormat::getDiscountDescription($stepResult);
807 Sale\Discount\Actions::fillCompatibleFields(
$order);
808 $applied = !empty($stepResult);
810 $orderDiscountId = 0;
817 $discount[
'ACTIONS_DESCR'] =
$order[
'DISCOUNT_DESCR'];
824 $discount[
'ORDER_DISCOUNT_ID'] = $orderDiscountId;
826 if ($discountData[
'USE_COUPONS'] ==
'Y')
828 if (empty($discount[
'COUPON']))
832 if (!$couponResult->isSuccess())
834 $orderCouponId = $couponResult->getId();
835 Sale\DiscountCouponsManager::setApply($orderCouponId, $stepResult);
836 unset($couponResult);
840 unset(
$order[
'DISCOUNT_DESCR'],
$order[
'DISCOUNT_RESULT']);
842 self::$currentOrderData =
$order;
843 if ($applied && $orderCouponId !=
'')
845 $couponApply = Sale\DiscountCouponsManager::setApply(self::$couponsCache[$orderCouponId][
'COUPON'], $stepResult);
851 if (!empty($stepResult[
'BASKET']))
854 foreach (
$order[
'BASKET_ITEMS'] as $basketCode => $basketItem)
856 $code = ($publicMode ? $basketItem[
'ID'] : $basketCode);
857 if (empty($stepResult[
'BASKET'][$code]))
859 if ($stepResult[
'BASKET'][$code][
'APPLY'] ==
'Y')
860 $order[
'BASKET_ITEMS'][$basketCode][
'ACTION_APPLIED'] =
'Y';
862 unset($code, $basketCode, $basketItem);
866 self::$discountResult[
'ORDER'][] = array(
867 'DISCOUNT_ID' => $orderDiscountId,
868 'COUPON_ID' => $orderCouponId,
869 'RESULT' => $stepResult
885 $extMode = ($extMode ===
true);
893 unset($result[
'BASKET'], $result[
'ORDER']);
907 self::$basketCodes[$index] = $code;
917 if (!self::$init || self::$useMode == self::MODE_SYSTEM)
919 if (self::$useMode == self::MODE_ORDER)
921 if (self::$useMode == self::MODE_DISABLED)
924 'CALCULATE' => array(
925 'USE_MODE' => self::$discountUseMode,
926 'NEW_ORDER' => self::$order ===
null,
928 'BASE_PRICE' => array(),
929 'DISCOUNT_LIST' => array(),
930 'COUPONS_LIST' => array(),
931 'DISCOUNT_RESULT' => array(),
932 'FORWARD_BASKET_TABLE' => array(),
933 'REVERSE_BASKET_TABLE' => array()
936 if (!empty(self::$basketBasePrice))
938 foreach (self::$basketBasePrice as $index => $price)
940 if (!isset(self::$basketCodes[$index]))
942 $result[
'BASE_PRICE'][self::$basketCodes[$index]] = $price;
944 unset($index, $price);
947 if (!empty(self::$discountsCache))
950 if (!empty(self::$couponsCache))
954 !empty(self::$discountResult[
'BASKET'])
955 || !empty(self::$discountResult[
'ORDER'])
956 || !empty(self::$discountResult[
'BASKET_ROUND'])
959 $result[
'DISCOUNT_RESULT'][
'APPLY_BLOCKS'] = array(
962 'BASKET_ROUND' => array(),
968 if (!empty(self::$discountResult[
'BASKET']))
970 foreach (self::$discountResult[
'BASKET'] as $index => $discountList)
972 if (!isset(self::$basketCodes[$index]))
974 $result[
'DISCOUNT_RESULT'][
'APPLY_BLOCKS'][0][
'BASKET'][self::$basketCodes[$index]] = $discountList;
976 unset($index, $discountList);
979 if (!empty(self::$discountResult[
'BASKET_ROUND']))
981 foreach (self::$discountResult[
'BASKET_ROUND'] as $index => $roundData)
983 if (!isset(self::$basketCodes[$index]))
985 $result[
'DISCOUNT_RESULT'][
'APPLY_BLOCKS'][0][
'BASKET_ROUND'][self::$basketCodes[$index]] = $roundData;
987 unset($index, $roundData);
990 if (!empty(self::$discountResult[
'ORDER']))
992 foreach (self::$discountResult[
'ORDER'] as $discountIndex => $discount)
994 if (!empty($discount[
'RESULT'][
'BASKET']))
996 $newBasket = array();
997 foreach ($discount[
'RESULT'][
'BASKET'] as $index => $basketItem)
999 if (!isset(self::$basketCodes[$index]))
1001 $basketItem[
'BASKET_ID'] = self::$basketCodes[$index];
1002 $newBasket[self::$basketCodes[$index]] = $basketItem;
1004 unset($index, $basketItem);
1005 $discount[
'RESULT'][
'BASKET'] = $newBasket;
1007 $result[
'DISCOUNT_RESULT'][
'APPLY_BLOCKS'][0][
'ORDER'][$discountIndex] = $discount;
1009 unset($discountIndex, $discount);
1012 if (!empty(self::$basketCodes))
1014 foreach (self::$basketCodes as $code => $id)
1016 $result[
'FORWARD_BASKET_TABLE'][$code] = $id;
1017 $result[
'REVERSE_BASKET_TABLE'][$id] = $code;
1032 public static function roundPrices(array &$basket, array $orderData = array())
1039 $clearedBasket = array();
1040 foreach ($basket as $basketCode => $basketItem)
1042 if (\CSaleBasketHelper::isSetItem($basketItem))
1044 $clearedBasket[$basketCode] = $basketItem;
1046 unset($basketCode, $basketItem);
1048 if (!empty($clearedBasket))
1050 $result = Sale\OrderDiscountManager::roundBasket(
1055 foreach ($result as $basketCode => $roundResult)
1057 if (empty($roundResult) || !is_array($roundResult))
1060 $code = ($publicMode ? $basket[$basketCode][
'ID'] : $basketCode);
1062 $basket[$basketCode][
'PRICE'] = $roundResult[
'PRICE'];
1063 $basket[$basketCode][
'DISCOUNT_PRICE'] = $roundResult[
'DISCOUNT_PRICE'];
1065 if ($basket[$basketCode][
'PRICE'] > $basket[$basketCode][
'BASE_PRICE'])
1067 $basket[$basketCode][
'BASE_PRICE'] = $basket[$basketCode][
'PRICE'];
1068 $basket[$basketCode][
'DISCOUNT_PRICE'] = 0;
1071 if (!isset(self::$discountResult[
'BASKET_ROUND']))
1072 self::$discountResult[
'BASKET_ROUND'] = array();
1073 self::$discountResult[
'BASKET_ROUND'][$code] = array(
1075 'ROUND_RULE' => $roundResult[
'ROUND_RULE']
1078 unset($basketCode, $roundResult, $result);
1080 unset($clearedBasket);
1093 (isset($basketItem[
'CUSTOM_PRICE']) && $basketItem[
'CUSTOM_PRICE'] ==
'Y')
1094 || (array_key_exists(
'PRODUCT_PROVIDER_CLASS', $basketItem) && empty($basketItem[
'PRODUCT_PROVIDER_CLASS']))
1107 if (\CSaleBasketHelper::isSetItem($fields))
1109 if (empty(self::$basketDiscountList[$code]))
1113 'MODULE_ID' => $fields[
'MODULE'],
1114 'PRODUCT_ID' => $fields[
'PRODUCT_ID'],
1115 'BASKET_ID' => $code
1117 foreach (self::$basketDiscountList[$code] as $index => $discount)
1125 $orderCouponId =
'';
1126 self::$basketDiscountList[$code][$index][
'ORDER_DISCOUNT_ID'] = $orderDiscountId;
1127 if ($discountData[
'USE_COUPONS'] ==
'Y')
1129 if (empty($discount[
'COUPON']))
1133 if (!$couponResult->isSuccess())
1136 $orderCouponId = $couponResult->getId();
1137 Sale\DiscountCouponsManager::setApplyByProduct($itemData, array($orderCouponId));
1138 unset($couponResult);
1141 if (!isset(self::$discountResult[
'BASKET'][$code]))
1142 self::$discountResult[
'BASKET'][$code] = array();
1143 self::$discountResult[
'BASKET'][$code][$index] = array(
1144 'DISCOUNT_ID' => $orderDiscountId,
1145 'COUPON_ID' => $orderCouponId,
1149 'DESCR_DATA' =>
false
1153 $orderApplication = (
1154 !empty(self::$discountsCache[$orderDiscountId][
'APPLICATION'])
1155 ? self::$discountsCache[$orderDiscountId][
'APPLICATION']
1158 if (!empty($orderApplication))
1160 $fields[
'DISCOUNT_RESULT'] = (
1161 !empty(self::$discountsCache[$orderDiscountId][
'ACTIONS_DESCR_DATA'])
1162 ? self::$discountsCache[$orderDiscountId][
'ACTIONS_DESCR_DATA']
1166 $applyProduct =
null;
1167 eval(
'$applyProduct='.$orderApplication.
';');
1168 if (is_callable($applyProduct))
1169 $applyProduct($fields);
1170 unset($applyProduct);
1172 if (!empty($fields[
'DISCOUNT_RESULT']))
1174 self::$discountResult[
'BASKET'][$code][$index][
'RESULT'][
'DESCR_DATA'] = $fields[
'DISCOUNT_RESULT'][
'BASKET'];
1175 self::$discountResult[
'BASKET'][$code][$index][
'RESULT'][
'DESCR'] =
self::formatDescription($fields[
'DISCOUNT_RESULT']);
1177 unset($fields[
'DISCOUNT_RESULT']);
1179 unset($orderApplication);
1181 unset($discount, $index);
1196 $discountResult = Sale\OrderDiscountManager::saveDiscount($discount,
false);
1205 $resultData = array(
1206 'ORDER_DISCOUNT_ID' => $orderDiscountId,
1207 'USE_COUPONS' => $discountData[
'USE_COUPONS'],
1208 'MODULE_ID' => $discountData[
'MODULE_ID'],
1210 if (!isset(self::$discountsCache[$orderDiscountId]))
1212 $discountData[
'ACTIONS_DESCR_DATA'] =
false;
1213 if (!empty($discountData[
'ACTIONS_DESCR']) && is_array($discountData[
'ACTIONS_DESCR']))
1215 $discountData[
'ACTIONS_DESCR_DATA'] = $discountData[
'ACTIONS_DESCR'];
1220 $discountData[
'ACTIONS_DESCR'] =
false;
1222 if (empty($discountData[
'ACTIONS_DESCR']))
1224 $discountData[
'ACTIONS_DESCR'] =
false;
1225 $discountData[
'ACTIONS_DESCR_DATA'] =
false;
1227 self::$discountsCache[$orderDiscountId] = $discountData;
1230 $result->setId($orderDiscountId);
1231 $result->setData($resultData);
1232 unset($discountData, $resultData, $orderDiscountId);
1248 if (!is_array($coupon))
1250 $couponData = Sale\DiscountCouponsManager::getEnteredCoupon($coupon,
true);
1251 if (empty($couponData))
1260 'COUPON' => $couponData[
'COUPON'],
1261 'TYPE' => $couponData[
'TYPE'],
1262 'COUPON_ID' => $couponData[
'ID'],
1263 'DATA' => $couponData
1267 $coupon[
'ORDER_DISCOUNT_ID'] = $discount;
1270 $orderCouponId = $coupon[
'COUPON'];
1271 if (!isset(self::$couponsCache[$orderCouponId]))
1272 self::$couponsCache[$orderCouponId] = $coupon;
1273 $result->setId($orderCouponId);
1274 $result->setData($coupon);
1275 unset($coupon, $orderCouponId);
1288 if (empty($descr) || !is_array($descr))
1290 if (isset($descr[
'DELIVERY']))
1292 $result[
'DELIVERY'] = array();
1293 foreach ($descr[
'DELIVERY'] as $index => $value)
1295 $result[
'DELIVERY'][$index] = Sale\OrderDiscountManager::formatDescription($value);
1296 if ($result[
'DELIVERY'][$index] ==
false)
1297 unset($result[
'DELIVERY'][$index]);
1299 unset($value, $index);
1300 if (!empty($result[
'DELIVERY']))
1301 $result[
'DELIVERY'] = implode(
', ', $result[
'DELIVERY']);
1303 if (isset($descr[
'BASKET']))
1305 $result[
'BASKET'] = array();
1306 foreach ($descr[
'BASKET'] as $index => $value)
1308 $result[
'BASKET'][$index] = Sale\OrderDiscountManager::formatDescription($value);
1309 if ($result[
'BASKET'][$index] ==
false)
1310 unset($result[
'BASKET'][$index]);
1312 unset($value, $index);
1313 if (!empty($result[
'BASKET']))
1314 $result[
'BASKET'] = implode(
', ', $result[
'BASKET']);
1329 $stepResult = &
$order[
'DISCOUNT_RESULT'];
1330 if (!empty($stepResult[
'DELIVERY']) && is_array($stepResult[
'DELIVERY']))
1332 $result[
'DELIVERY'] = array(
1334 'DELIVERY_ID' => (isset(
$order[
'DELIVERY_ID']) ?
$order[
'DELIVERY_ID'] :
false),
1335 'SHIPMENT_CODE' => (isset(
$order[
'SHIPMENT_CODE']) ?
$order[
'SHIPMENT_CODE'] :
false),
1337 'DESCR_DATA' => $stepResult[
'DELIVERY'],
1338 'ACTION_BLOCK_LIST' => array_keys($stepResult[
'DELIVERY'])
1340 if (is_array($result[
'DELIVERY'][
'DESCR']))
1341 $result[
'DELIVERY'][
'DESCR'] = implode(
', ', $result[
'DELIVERY'][
'DESCR']);
1343 if (!empty($stepResult[
'BASKET']) && is_array($stepResult[
'BASKET']))
1345 if (!isset($result[
'BASKET']))
1346 $result[
'BASKET'] = array();
1347 foreach ($stepResult[
'BASKET'] as $basketCode => $basketResult)
1349 $code = ($publicMode ?
$order[
'BASKET_ITEMS'][$basketCode][
'ID'] : $basketCode);
1350 $result[
'BASKET'][$code] = array(
1353 'DESCR_DATA' => $basketResult,
1354 'MODULE' =>
$order[
'BASKET_ITEMS'][$basketCode][
'MODULE'],
1355 'PRODUCT_ID' =>
$order[
'BASKET_ITEMS'][$basketCode][
'PRODUCT_ID'],
1356 'BASKET_ID' => $code,
1357 'ACTION_BLOCK_LIST' => array_keys($basketResult)
1359 if (is_array($result[
'BASKET'][$code][
'DESCR']))
1360 $result[
'BASKET'][$code][
'DESCR'] = implode(
', ', $result[
'BASKET'][$code][
'DESCR']);
1362 unset($code, $basketCode, $basketResult);
1379 if (isset(self::$previousOrderData[
'PRICE_DELIVERY']) && isset($currentOrder[
'PRICE_DELIVERY']))
1381 if (self::$previousOrderData[
'PRICE_DELIVERY'] != $currentOrder[
'PRICE_DELIVERY'])
1383 $descr = Discount\Result\CompatibleFormat::createResultDescription(
1384 $currentOrder[
'PRICE_DELIVERY'],
1385 self::$previousOrderData[
'PRICE_DELIVERY'],
1386 self::$previousOrderData[
'CURRENCY']
1388 $result[
'DELIVERY'] = array(
1390 'DELIVERY_ID' => (isset($currentOrder[
'DELIVERY_ID']) ? $currentOrder[
'DELIVERY_ID'] :
false),
1391 'SHIPMENT_CODE' => (isset($currentOrder[
'SHIPMENT_CODE']) ? $currentOrder[
'SHIPMENT_CODE'] :
false),
1393 'DESCR_DATA' => $descr
1398 if (!empty(self::$previousOrderData[
'BASKET_ITEMS']) && !empty($currentOrder[
'BASKET_ITEMS']))
1400 foreach (self::$previousOrderData[
'BASKET_ITEMS'] as $basketCode => $item)
1402 if (!isset($currentOrder[
'BASKET_ITEMS'][$basketCode]))
1404 $code = ($publicMode ? $currentOrder[
'BASKET_ITEMS'][$basketCode][
'ID'] : $basketCode);
1405 if ($item[
'PRICE'] != $currentOrder[
'BASKET_ITEMS'][$basketCode][
'PRICE'])
1407 if (!isset($result[
'BASKET']))
1408 $result[
'BASKET'] = array();
1409 $descr = Discount\Result\CompatibleFormat::createResultDescription(
1410 $currentOrder[
'BASKET_ITEMS'][$basketCode][
'PRICE'],
1412 self::$previousOrderData[
'CURRENCY']
1414 $result[
'BASKET'][$code] = array(
1417 'DESCR_DATA' => $descr,
1418 'MODULE' => $currentOrder[
'BASKET_ITEMS'][$basketCode][
'MODULE'],
1419 'PRODUCT_ID' => $currentOrder[
'BASKET_ITEMS'][$basketCode][
'PRODUCT_ID'],
1420 'BASKET_ID' => $code
1439 if ($discount[
'USE_COUPONS'] ==
'Y' && !empty($discount[
'COUPON']))
1443 (!empty($stepResult[
'BASKET']) && count($stepResult[
'BASKET']) > 1)
1450 foreach (self::$previousOrderData[
'BASKET_ITEMS'] as $key => $item)
1452 $resultKey = ($publicMode ? $item[
'ID'] : $key);
1453 if (isset($stepResult[
'BASKET'][$resultKey]))
1455 if ($maxPrice < $item[
'PRICE'])
1457 $maxPrice = $item[
'PRICE'];
1459 $basketId = $resultKey;
1464 $basketKeys = array_keys(
$order[
'BASKET_ITEMS']);
1465 foreach ($basketKeys as &$key)
1467 if ($key == $maxKey)
1469 $order[
'BASKET_ITEMS'][$key] = self::$previousOrderData[
'BASKET_ITEMS'][$key];
1472 $basketKeys = array_keys($stepResult[
'BASKET']);
1473 foreach ($basketKeys as &$key)
1475 if ($key == $basketId)
1477 unset($stepResult[
'BASKET'][$key]);
1481 unset($basketId, $maxKey, $maxPrice, $publicMode);
1493 $discountApply = array();
1494 $couponApply = array();
1496 self::$discountResult[
'DISCOUNT_LIST'] = array();
1497 if (!empty(self::$discountsCache))
1499 foreach (self::$discountsCache as $id => $discount)
1501 self::$discountResult[
'DISCOUNT_LIST'][$id] = array(
1503 'NAME' => $discount[
'NAME'],
1504 'MODULE_ID' => $discount[
'MODULE_ID'],
1505 'DISCOUNT_ID' => $discount[
'ID'],
1506 'USE_COUPONS' => $discount[
'USE_COUPONS'],
1507 'ACTIONS_DESCR' => $discount[
'ACTIONS_DESCR'],
1508 'ACTIONS_DESCR_DATA' => $discount[
'ACTIONS_DESCR_DATA'],
1510 'EDIT_PAGE_URL' => $discount[
'EDIT_PAGE_URL']
1512 $discountApply[$id] = &self::$discountResult[
'DISCOUNT_LIST'][$id];
1514 unset($id, $discount);
1517 self::$discountResult[
'COUPON_LIST'] = array();
1518 if (!empty(self::$couponsCache))
1520 foreach (self::$couponsCache as $id => $coupon)
1522 self::$discountResult[
'COUPON_LIST'][$id] = $coupon;
1523 self::$discountResult[
'COUPON_LIST'][$id][
'APPLY'] =
'N';
1524 $couponApply[$id] = &self::$discountResult[
'COUPON_LIST'][$id];
1526 unset($id, $coupon);
1529 if (!empty(self::$discountResult[
'BASKET']))
1531 foreach (self::$discountResult[
'BASKET'] as $basketCode => $discountList)
1533 foreach ($discountList as $discount)
1535 if ($discount[
'RESULT'][
'APPLY'] ==
'Y')
1537 if (isset($discountApply[$discount[
'DISCOUNT_ID']]))
1538 $discountApply[$discount[
'DISCOUNT_ID']][
'APPLY'] =
'Y';
1539 if (isset($couponApply[$discount[
'COUPON_ID']]))
1540 $couponApply[$discount[
'COUPON_ID']][
'APPLY'] =
'Y';
1545 unset($basketCode, $discountList);
1548 if (!empty(self::$discountResult[
'ORDER']))
1550 foreach (self::$discountResult[
'ORDER'] as $discount)
1552 if (!empty($discount[
'RESULT'][
'BASKET']))
1554 foreach ($discount[
'RESULT'][
'BASKET'] as $basketCode => $applyList)
1556 if ($applyList[
'APPLY'] ==
'Y')
1558 if (isset($discountApply[$discount[
'DISCOUNT_ID']]))
1559 $discountApply[$discount[
'DISCOUNT_ID']][
'APPLY'] =
'Y';
1560 if (isset($couponApply[$discount[
'COUPON_ID']]))
1561 $couponApply[$discount[
'COUPON_ID']][
'APPLY'] =
'Y';
1564 unset($basketCode, $applyList);
1566 if (!empty($discount[
'RESULT'][
'DELIVERY']) && $discount[
'RESULT'][
'DELIVERY'][
'APPLY'] ==
'Y')
1568 if (isset($discountApply[$discount[
'DISCOUNT_ID']]))
1569 $discountApply[$discount[
'DISCOUNT_ID']][
'APPLY'] =
'Y';
1570 if (isset($couponApply[$discount[
'COUPON_ID']]))
1571 $couponApply[$discount[
'COUPON_ID']][
'APPLY'] =
'Y';
1576 unset($discountApply, $couponApply);
1587 $delivery = array();
1589 if (!empty(self::$discountResult[
'BASKET']))
1591 foreach (self::$discountResult[
'BASKET'] as $basketCode => $discountList)
1593 if (!isset($basket[$basketCode]))
1594 $basket[$basketCode] = array();
1595 foreach ($discountList as $discount)
1597 $basket[$basketCode][] = array(
1598 'DISCOUNT_ID' => $discount[
'DISCOUNT_ID'],
1599 'COUPON_ID' => $discount[
'COUPON_ID'],
1600 'APPLY' => $discount[
'RESULT'][
'APPLY'],
1601 'DESCR' => $discount[
'RESULT'][
'DESCR']
1606 unset($basketCode, $discountList);
1609 if (!empty(self::$discountResult[
'ORDER']))
1611 foreach (self::$discountResult[
'ORDER'] as $discount)
1613 if (!empty($discount[
'RESULT'][
'BASKET']))
1615 foreach ($discount[
'RESULT'][
'BASKET'] as $basketCode => $applyList)
1617 if (!isset($basket[$basketCode]))
1618 $basket[$basketCode] = array();
1619 $basket[$basketCode][] = array(
1620 'DISCOUNT_ID' => $discount[
'DISCOUNT_ID'],
1621 'COUPON_ID' => $discount[
'COUPON_ID'],
1622 'APPLY' => $applyList[
'APPLY'],
1623 'DESCR' => $applyList[
'DESCR']
1626 unset($basketCode, $applyList);
1628 if (!empty($discount[
'RESULT'][
'DELIVERY']))
1630 $delivery[] = array(
1631 'DISCOUNT_ID' => $discount[
'DISCOUNT_ID'],
1632 'COUPON_ID' => $discount[
'COUPON_ID'],
1633 'DELIVERY_ID' => $discount[
'RESULT'][
'DELIVERY'][
'DELIVERY_ID'],
1634 'APPLY' => $discount[
'RESULT'][
'DELIVERY'][
'APPLY'],
1635 'DESCR' => $discount[
'RESULT'][
'DELIVERY'][
'DESCR']
1642 unset($couponApply, $discountApply);
1643 self::$discountResult[
'RESULT'] = array(
1644 'BASKET' => $basket,
1645 'DELIVERY' => $delivery
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static convertDiscount($discount)
static getStepResultOld($currentOrder)
static setBasketItemData($code, $providerData)
static clearDiscountResult()
static isCustomPrice($basketItem)
static getBasketItemBasePrice($code)
static initUseMode($mode=self::MODE_CLIENT, $config=array())
static getOldDiscountResult()
static setOldDiscountResult($discountList)
static getApplyDiscounts()
static init($mode=self::MODE_CLIENT, $config=array())
static formatDescription($descr)
static calculateBasketDiscounts(&$basket)
static remakingDiscountResult()
static roundPrices(array &$basket, array $orderData=array())
static fillBasketData(&$basket)
static calculateSaleDiscount(&$order, $discount)
static setRepeatSave($repeat)
static $compatibleSaleDiscountResult
static setBasketItemBasePrice($code, $price, $currency)
static getBasketItemDiscounts($code)
static getApplyResult($extMode=false)
static calculateBasketItemDiscount($code, $fields)
static getStepResult($order)
static $previousOrderData
static clearBasketItemData($code)
static convertCoupon($coupon, $discount)
static setBasketBasePrice($basket)
static reInit($mode=self::MODE_CLIENT, $config=array())
static revertUsageCompatible()
static setApplyMode(&$basket)
static setBasketCode($index, $code)
static setShipment($order, $shipment)
static stopUsageCompatible()
static $basketDiscountList
static setOrderData($order)
static setBasketItemDiscounts($code, $discountList)
static correctStepResult(&$order, &$stepResult, $discount)
static getSiteCurrency($siteId)
static formatArrayDescription($data)