1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
discount.php
См. документацию.
1<?
7
8Loc::loadMessages(__FILE__);
9
11{
15
17 const OLD_DSC_TYPE_FIX = 'V';
18
20 const PREPARE_ACTIONS = 2;
21
22 static protected $cacheDiscountHandlers = array();
23 static protected $usedModules = array();
24
40 public static function DoProcessOrder(&$arOrder, $arOptions, &$arErrors)
41 {
42 if (empty($arOrder['BASKET_ITEMS']) || !is_array($arOrder['BASKET_ITEMS']))
43 return;
44
45 $isOrderConverted = \Bitrix\Main\Config\Option::get("main", "~sale_converted_15", 'Y');
46 $onlySaleDiscounts = (string)Main\Config\Option::get('sale', 'use_sale_discount_only') == 'Y';
47 $oldDelivery = '';
48
49 $checkIds = true;
50 $arIDS = array();
51 if ($isOrderConverted != 'N')
52 {
53 if (isset($arOrder['DELIVERY_ID']) && $arOrder['DELIVERY_ID'] != '')
54 {
55 $oldDelivery = $arOrder['DELIVERY_ID'];
56 $arOrder['DELIVERY_ID'] = \CSaleDelivery::getIdByCode($arOrder['DELIVERY_ID']);
57 }
58 $adminSection = (defined('ADMIN_SECTION') && ADMIN_SECTION === true);
59 if ($adminSection)
60 {
62 $modeParams = array();
63 if (isset($arOrder['CURRENCY']))
64 $modeParams['CURRENCY'] = $arOrder['CURRENCY'];
65 if (isset($arOrder['SITE_ID']))
66 {
67 $modeParams['SITE_ID'] = $arOrder['SITE_ID'];
68 if (!isset($modeParams['CURRENCY']))
69 $modeParams['CURRENCY'] = Sale\Internals\SiteCurrencyTable::getSiteCurrency($modeParams['SITE_ID']);
70 }
71 }
72 else
73 {
75 $modeParams = array(
76 'SITE_ID' => SITE_ID,
78 );
79
80 $basketIdList = array();
81 foreach ($arOrder['BASKET_ITEMS'] as $basketId => $basketItem)
82 {
83 if (isset($basketItem['ID']))
84 {
85 if (!isset($basketItem['PRODUCT_PRICE_ID']) || !isset($basketItem['PRICE_TYPE_ID']))
86 {
87 $basketIdList[$basketItem['ID']] = $basketId;
88 }
89 }
90 }
91 unset($basketId, $basketItem);
92 if (!empty($basketIdList))
93 {
94 $iterator = Sale\Internals\BasketTable::getList(array(
95 'select' => array('ID', 'PRODUCT_PRICE_ID', 'PRICE_TYPE_ID'),
96 'filter' => array('@ID' => array_keys($basketIdList))
97 ));
98 while ($row = $iterator->fetch())
99 {
100 if (!isset($basketIdList[$row['ID']]))
101 continue;
102 $index = $basketIdList[$row['ID']];
103 $arOrder['BASKET_ITEMS'][$index]['PRODUCT_PRICE_ID'] = $row['PRODUCT_PRICE_ID'];
104 $arOrder['BASKET_ITEMS'][$index]['PRICE_TYPE_ID'] = $row['PRICE_TYPE_ID'];
105 unset($index);
106 }
107 unset($row, $iterator);
108 }
109 }
110 unset($adminSection);
111 if (!empty($modeParams))
112 {
115 array(
116 'USE_BASE_PRICE' => \Bitrix\Main\Config\Option::get('sale', 'get_discount_percent_from_base_price'),
117 'SITE_ID' => $modeParams['SITE_ID'],
118 'CURRENCY' => $modeParams['CURRENCY']
119 )
120 );
121 }
123 {
124 if (!empty($modeParams))
126 }
127 unset($modeParams, $mode);
130 if (!$onlySaleDiscounts)
133
134 $applyMode = Sale\Discount::getApplyMode();
135 if ($applyMode == Sale\Discount::APPLY_MODE_FULL_LAST || $applyMode == Sale\Discount::APPLY_MODE_FULL_DISABLE)
136 {
137 foreach ($arOrder['BASKET_ITEMS'] as &$basketItem)
138 {
139 if (isset($basketItem['LAST_DISCOUNT']) && $basketItem['LAST_DISCOUNT'] == 'Y')
140 {
141 $checkIds = false;
142 break;
143 }
144 }
145 unset($basketItem);
146 }
147 }
148
149 $arOrder['DISCOUNT_LIST'] = array();
150 $arOrder['FULL_DISCOUNT_LIST'] = array();
151 if ($checkIds)
152 {
153 $groupDiscountIterator = Sale\Internals\DiscountGroupTable::getList(array(
154 'select' => array('DISCOUNT_ID'),
155 'filter' => array('@GROUP_ID' => CUser::GetUserGroup($arOrder['USER_ID']), '=ACTIVE' => 'Y'),
156 'order' => array('DISCOUNT_ID' => 'ASC')
157 ));
158 while ($groupDiscount = $groupDiscountIterator->fetch())
159 {
160 $groupDiscount['DISCOUNT_ID'] = (int)$groupDiscount['DISCOUNT_ID'];
161 if ($groupDiscount['DISCOUNT_ID'] > 0)
162 $arIDS[$groupDiscount['DISCOUNT_ID']] = true;
163 }
164 }
165 if (!empty($arIDS))
166 {
167 $arIDS = array_keys($arIDS);
168 $couponList = Sale\DiscountCouponsManager::getForApply(array('MODULE_ID' => 'sale', 'DISCOUNT_ID' => $arIDS), array(), true);
169
170 //TODO: fix this condition
171 $useProps = true;
172 $iblockPropList = array();
174 $arIDS,
175 array(
176 '=MODULE_ID' => 'catalog',
177 '@ENTITY' => array(
178 'ELEMENT_PROPERTY', 'PRICE'
179 )
180 )
181 );
182 if (empty($entityList))
183 {
184 $useProps = false;
185 }
186 else
187 {
188 if (empty($entityList['catalog']['ELEMENT_PROPERTY']))
189 {
190 $useProps = false;
191 }
192 else
193 {
194 foreach ($entityList['catalog']['ELEMENT_PROPERTY'] as $entity)
195 {
196 $entityField = explode(':', $entity['FIELD_TABLE']);
197 if (isset($entityField[1]))
198 {
199 $propId = (int)$entityField[1];
200 if ($propId > 0)
201 $iblockPropList[$propId] = $propId;
202 unset($propId);
203 }
204 unset($entityField);
205 }
206 unset($entity);
207 if (empty($iblockPropList))
208 $useProps = false;
209 }
210 }
211
212 $arExtend = array(
213 'catalog' => array(
214 'fields' => true,
215 'price' => !empty($entityList['catalog']['PRICE']),
216 'props' => $useProps,
217 ),
218 );
219 if ($useProps)
220 $arExtend['iblock']['props'] = $iblockPropList;
221 unset($iblockPropList, $useProps);
222 foreach (GetModuleEvents('sale', 'OnExtendBasketItems', true) as $arEvent)
223 ExecuteModuleEventEx($arEvent, array(&$arOrder['BASKET_ITEMS'], $arExtend));
224
225 foreach ($arOrder['BASKET_ITEMS'] as &$arOneItem)
226 {
227 if (
228 array_key_exists('PRODUCT_PROVIDER_CLASS', $arOneItem) && empty($arOneItem['PRODUCT_PROVIDER_CLASS'])
229 && array_key_exists('CALLBACK_FUNC', $arOneItem) && empty($arOneItem['CALLBACK_FUNC'])
230 && (!isset($arOneItem['CUSTOM_PRICE']) || $arOneItem['CUSTOM_PRICE'] != 'Y')
231 )
232 {
233 if (isset($arOneItem['DISCOUNT_PRICE']))
234 {
235 $arOneItem['PRICE'] += $arOneItem['DISCOUNT_PRICE'];
236 $arOneItem['DISCOUNT_PRICE'] = 0;
237 $arOneItem['BASE_PRICE'] = $arOneItem['PRICE'];
238 }
239 }
240 }
241 if (isset($arOneItem))
242 unset($arOneItem);
243
244 if (empty(self::$cacheDiscountHandlers))
245 {
246 self::$cacheDiscountHandlers = CSaleDiscount::getDiscountHandlers($arIDS);
247 }
248 else
249 {
250 $needDiscountHandlers = array();
251 foreach ($arIDS as $discountID)
252 {
253 if (!isset(self::$cacheDiscountHandlers[$discountID]))
254 $needDiscountHandlers[] = $discountID;
255 }
256 unset($discountID);
257 if (!empty($needDiscountHandlers))
258 {
259 $discountHandlersList = CSaleDiscount::getDiscountHandlers($needDiscountHandlers);
260 if (!empty($discountHandlersList))
261 {
262 foreach ($discountHandlersList as $discountID => $discountHandlers)
263 {
264 self::$cacheDiscountHandlers[$discountID] = $discountHandlers;
265 }
266 unset($discountHandlers, $discountID);
267 }
268 unset($discountHandlersList);
269 }
270 unset($needDiscountHandlers);
271 }
272
273 $currentDatetime = new Main\Type\DateTime();
274 $discountSelect = array(
275 'ID', 'PRIORITY', 'SORT', 'LAST_DISCOUNT', 'LAST_LEVEL_DISCOUNT', 'UNPACK', 'APPLICATION', 'USE_COUPONS', 'EXECUTE_MODULE',
276 'NAME', 'CONDITIONS_LIST', 'ACTIONS_LIST'
277 );
278 $discountOrder = array('PRIORITY' => 'DESC', 'SORT' => 'ASC', 'ID' => 'ASC');
279 $discountFilter = array(
280 '@ID' => $arIDS,
281 '=LID' => $arOrder['SITE_ID'],
282 array(
283 'LOGIC' => 'OR',
284 'ACTIVE_FROM' => '',
285 '<=ACTIVE_FROM' => $currentDatetime
286 ),
287 array(
288 'LOGIC' => 'OR',
289 'ACTIVE_TO' => '',
290 '>=ACTIVE_TO' => $currentDatetime
291 )
292 );
293
294 $couponsDiscount = array();
295 if (!empty($couponList))
296 {
297 $iterator = Sale\Internals\DiscountCouponTable::getList(array(
298 'select' => array('DISCOUNT_ID', 'COUPON'),
299 'filter' => array('@DISCOUNT_ID' => $arIDS,'@COUPON' => array_keys($couponList)),
300 'order' => array('DISCOUNT_ID' => 'ASC')
301 ));
302 while ($row = $iterator->fetch())
303 {
304 $id = (int)$row['DISCOUNT_ID'];
305 if (isset($couponsDiscount[$id]))
306 continue;
307 $couponsDiscount[$id] = $row['COUPON'];
308 }
309 unset($id, $row, $iterator);
310 }
311
312 if (empty($couponsDiscount))
313 {
314 $discountFilter['=USE_COUPONS'] = 'N';
315 }
316 else
317 {
318 $discountFilter[] = array(
319 'LOGIC' => 'OR',
320 '=USE_COUPONS' => 'N',
321 array(
322 '=USE_COUPONS' => 'Y',
323 '@ID' => array_keys($couponsDiscount)
324 )
325 );
326 }
327
328 $newDiscounts = null;
329 $resultDiscountFullList = array();
330 $discountIterator = Sale\Internals\DiscountTable::getList(array(
331 'select' => $discountSelect,
332 'filter' => $discountFilter,
333 'order' => $discountOrder
334 ));
335
336 $resultDiscountList = array();
337 $resultDiscountKeys = array();
338 $resultDiscountIndex = 0;
339 $skipPriorityLevel = null;
340 while ($discount = $discountIterator->fetch())
341 {
342 $discount['ID'] = (int)$discount['ID'];
343 if ($discount['USE_COUPONS'] == 'Y')
344 $discount['DISCOUNT_COUPON'] = $couponsDiscount[$discount['ID']];
345
346 if($skipPriorityLevel == $discount['PRIORITY'])
347 {
348 continue;
349 }
350 $skipPriorityLevel = null;
351
352 static::prefillDiscountFields($discount, $couponList);
353 $applyFlag = static::workWithDiscountHandlers($discount);
354
355 if ($isOrderConverted != 'N')
357 if ($applyFlag && self::__Unpack($arOrder, $discount['UNPACK']))
358 {
359 $oldOrder = $arOrder;
360 if ($isOrderConverted != 'N')
362
363 self::__ApplyActions($arOrder, $discount['APPLICATION']);
364
365 if ($isOrderConverted != 'N')
366 {
367 $resultDiscountFullList[] = $discount;
369 {
370 $resultDiscountList[$resultDiscountIndex] = array(
371 'MODULE_ID' => $discount['MODULE_ID'],
372 'ID' => $discount['ID'],
373 'NAME' => $discount['NAME'],
374 'PRIORITY' => $discount['PRIORITY'],
375 'SORT' => $discount['SORT'],
376 'LAST_DISCOUNT' => $discount['LAST_DISCOUNT'],
377 'CONDITIONS' => serialize($discount['CONDITIONS_LIST']),
378 'UNPACK' => $discount['UNPACK'],
379 'ACTIONS' => serialize($discount['ACTIONS_LIST']),
380 'APPLICATION' => $discount['APPLICATION'],
381 'RESULT' => self::getDiscountResult($oldOrder, $arOrder, false),
382 'HANDLERS' => self::$cacheDiscountHandlers[$discount['ID']],
383 'USE_COUPONS' => $discount['USE_COUPONS'],
384 'COUPON' => ($discount['USE_COUPONS'] == 'Y' ? $couponList[$discount['DISCOUNT_COUPON']] : false)
385 );
386 $resultDiscountKeys[$discount['ID']] = $resultDiscountIndex;
387 $resultDiscountIndex++;
388 if ($discount['LAST_DISCOUNT'] == 'Y')
389 break;
390
391 if ($discount['LAST_LEVEL_DISCOUNT'] == 'Y')
392 {
393 $skipPriorityLevel = $discount['PRIORITY'];
394 }
395 }
397 }
398 else
399 {
400 $discountResult = self::getDiscountResult($oldOrder, $arOrder, false);
401 if (!empty($discountResult['DELIVERY']) || !empty($discountResult['BASKET']))
402 {
403 if ($discount['USE_COUPONS'] == 'Y' && !empty($discount['DISCOUNT_COUPON']))
404 {
405 if ($couponList[$discount['DISCOUNT_COUPON']]['TYPE'] == Sale\Internals\DiscountCouponTable::TYPE_BASKET_ROW)
406 self::changeDiscountResult($oldOrder, $arOrder, $discountResult);
407 $couponApply = Sale\DiscountCouponsManager::setApply($discount['DISCOUNT_COUPON'], $discountResult);
408 unset($couponApply);
409 }
410 $resultDiscountList[$resultDiscountIndex] = array(
411 'MODULE_ID' => $discount['MODULE_ID'],
412 'ID' => $discount['ID'],
413 'NAME' => $discount['NAME'],
414 'PRIORITY' => $discount['PRIORITY'],
415 'SORT' => $discount['SORT'],
416 'LAST_DISCOUNT' => $discount['LAST_DISCOUNT'],
417 'CONDITIONS' => serialize($discount['CONDITIONS_LIST']),
418 'UNPACK' => $discount['UNPACK'],
419 'ACTIONS' => serialize($discount['ACTIONS_LIST']),
420 'APPLICATION' => $discount['APPLICATION'],
421 'RESULT' => $discountResult,
422 'HANDLERS' => self::$cacheDiscountHandlers[$discount['ID']],
423 'USE_COUPONS' => $discount['USE_COUPONS'],
424 'COUPON' => ($discount['USE_COUPONS'] == 'Y' ? $couponList[$discount['DISCOUNT_COUPON']] : false)
425 );
426 $resultDiscountKeys[$discount['ID']] = $resultDiscountIndex;
427 $resultDiscountIndex++;
428 if ($discount['LAST_DISCOUNT'] == 'Y')
429 break;
430 }
431 unset($discountResult);
432 }
433 }
434 }
435 unset($discount, $discountIterator);
436
437 $arOrder['DISCOUNT_LIST'] = $resultDiscountList;
438 $arOrder['FULL_DISCOUNT_LIST'] = $resultDiscountFullList;
439 if ($isOrderConverted != 'N')
441 }
442 $orderData = $arOrder;
443 unset($orderData['BASKET_ITEMS'], $orderData['DISCOUNT_LIST'], $orderData['FULL_DISCOUNT_LIST']);
444 Sale\Compatible\DiscountCompatibility::roundPrices($arOrder['BASKET_ITEMS'], $orderData);
445 unset($orderData);
446
447 $arOrder["ORDER_PRICE"] = 0;
448 $arOrder["ORDER_WEIGHT"] = 0;
449 $arOrder["USE_VAT"] = false;
450 $arOrder["VAT_RATE"] = 0;
451 $arOrder["VAT_SUM"] = 0;
452 $arOrder["DISCOUNT_PRICE"] = 0.0;
453 $arOrder["DISCOUNT_VALUE"] = $arOrder["DISCOUNT_PRICE"];
454 $arOrder["PRICE_DELIVERY"] = roundEx($arOrder["PRICE_DELIVERY"], SALE_VALUE_PRECISION);
455 $arOrder["DELIVERY_PRICE"] = $arOrder["PRICE_DELIVERY"];
456
457 $clearFields = array(
458 'CATALOG', 'PRICE_TYPE_ID'
459 );
460
463
464 foreach (array_keys($arOrder['BASKET_ITEMS']) as $index)
465 {
466 $arShoppingCartItem = $arOrder['BASKET_ITEMS'][$index];
467 if (!CSaleBasketHelper::isSetItem($arShoppingCartItem))
468 {
469 $customPrice = isset($arShoppingCartItem['CUSTOM_PRICE']) && $arShoppingCartItem['CUSTOM_PRICE'] == 'Y';
470 if (!$customPrice)
471 {
472 $arShoppingCartItem['DISCOUNT_PRICE'] = Sale\PriceMaths::roundPrecision($arShoppingCartItem['DISCOUNT_PRICE']);
473 if ($arShoppingCartItem['DISCOUNT_PRICE'] > 0)
474 $arShoppingCartItem['PRICE'] = $arShoppingCartItem['BASE_PRICE'] - $arShoppingCartItem['DISCOUNT_PRICE'];
475 else
476 $arShoppingCartItem['PRICE'] = Sale\PriceMaths::roundPrecision($arShoppingCartItem['PRICE']);
477 }
478
479 if (isset($arShoppingCartItem['VAT_RATE']))
480 {
481 $vatRate = (float)$arShoppingCartItem['VAT_RATE'];
482 if ($vatRate > 0)
483 $arShoppingCartItem['VAT_VALUE'] = (($arShoppingCartItem['PRICE'] / ($vatRate + 1)) * $vatRate);
484 unset($vatRate);
485 }
486
487 $arOrder["ORDER_PRICE"] += $arShoppingCartItem["PRICE"] * $arShoppingCartItem["QUANTITY"];
488 $arOrder["ORDER_WEIGHT"] += $arShoppingCartItem["WEIGHT"] * $arShoppingCartItem["QUANTITY"];
489
490 $arShoppingCartItem["PRICE_FORMATED"] = CCurrencyLang::CurrencyFormat($arShoppingCartItem["PRICE"], $arShoppingCartItem["CURRENCY"], true);
491 $arShoppingCartItem["DISCOUNT_PRICE_PERCENT"] = 0;
492
493 if ($arShoppingCartItem["BASE_PRICE"] > 0)
494 $arShoppingCartItem["DISCOUNT_PRICE_PERCENT"] = ($arShoppingCartItem["DISCOUNT_PRICE"] * 100) / $arShoppingCartItem["BASE_PRICE"];
495 $arShoppingCartItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arShoppingCartItem["DISCOUNT_PRICE_PERCENT"], 0)."%";
496
497 if ($arShoppingCartItem["VAT_RATE"] > 0)
498 {
499 $arOrder["USE_VAT"] = true;
500 if ($arShoppingCartItem["VAT_RATE"] > $arOrder["VAT_RATE"])
501 $arOrder["VAT_RATE"] = $arShoppingCartItem["VAT_RATE"];
502
503 $arOrder["VAT_SUM"] += $arShoppingCartItem["VAT_VALUE"] * $arShoppingCartItem["QUANTITY"];
504 }
505
506 $itemDiscountsApply = false;
507 $simplePercent = true;
508 $simplePercentValue = null;
509 $code = ($publicMode ? $arShoppingCartItem['ID'] : $index);
510 if (!empty($discountResult['BASKET'][$code]))
511 {
512 foreach ($discountResult['BASKET'][$code] as $row)
513 {
514 if ($row['RESULT']['APPLY'] != 'Y')
515 continue;
516
517 $itemDiscountsApply = true;
518 $descr = $row['RESULT']['DESCR_DATA'][0];
519 $validDiscount = (
520 isset($descr['TYPE']) && $descr['TYPE'] == Sale\Discount\Formatter::TYPE_VALUE
521 && (
522 $descr['VALUE_ACTION'] == Sale\Discount\Formatter::VALUE_ACTION_DISCOUNT
523 || $descr['VALUE_ACTION'] == Sale\Discount\Formatter::VALUE_ACTION_CUMULATIVE
524 )
525 && $descr['VALUE_TYPE'] == Sale\Discount\Formatter::VALUE_TYPE_PERCENT
526 );
527
528 if (!$validDiscount)
529 $simplePercent = false;
530
531 if (
532 $simplePercent
533 && $validDiscount
534 )
535 {
536 if ($simplePercentValue === null)
537 $simplePercentValue = $descr['VALUE'];
538 else
539 $simplePercent = false;
540 }
541 unset($validDiscount, $descr);
542 }
543 unset($row);
544 }
545 if (!empty($discountResult['ORDER']) && $simplePercent)
546 {
547 foreach ($discountResult['ORDER'] as $discount)
548 {
549 if (
550 empty($discount['RESULT']['BASKET'][$code])
551 || $discount['RESULT']['BASKET'][$code]['APPLY'] != 'Y'
552 )
553 continue;
554
555 $itemDiscountsApply = true;
556 if (
557 $simplePercentValue !== null
558 || count($discount['RESULT']['BASKET'][$code]['DESCR_DATA']) != 1
559 )
560 {
561 $simplePercent = false;
562 break;
563 }
564 $descr = $discount['RESULT']['BASKET'][$code]['DESCR_DATA'][0];
565 if (
566 isset($descr['TYPE']) && $descr['TYPE'] == Sale\Discount\Formatter::TYPE_VALUE
567 && $descr['VALUE_ACTION'] == Sale\Discount\Formatter::VALUE_ACTION_DISCOUNT
568 && $descr['VALUE_TYPE'] == Sale\Discount\Formatter::VALUE_TYPE_PERCENT
569 )
570 {
571 $simplePercentValue = $descr['VALUE'];
572 }
573 unset($descr);
574 }
575 unset($discount);
576 }
577 $simplePercent = false;
578 if ($simplePercent && $simplePercentValue !== null)
579 $arShoppingCartItem['SIMPLE_DISCOUNT_PRICE_PERCENT'] = $simplePercentValue;
580 $arShoppingCartItem['DISCOUNTS_APPLY'] = $itemDiscountsApply;
581 unset($code, $simplePercentValue, $simplePercent, $itemDiscountsApply);
582 }
583
584 foreach ($clearFields as $fieldName)
585 {
586 if (isset($arShoppingCartItem[$fieldName]))
587 unset($arShoppingCartItem[$fieldName]);
588 }
589 unset($fieldName);
590 $arOrder['BASKET_ITEMS'][$index] = $arShoppingCartItem;
591 unset($arShoppingCartItem);
592 }
593 unset($index);
594 unset($discountResult, $publicMode);
595 unset($clearFields);
596
597 if ($isOrderConverted != 'N' && $oldDelivery != '')
598 $arOrder['DELIVERY_ID'] = $oldDelivery;
599
600 $arOrder["ORDER_PRICE"] = roundEx($arOrder["ORDER_PRICE"], SALE_VALUE_PRECISION);
601 }
602
603 private static function prefillDiscountFields(array &$discount, array $couponList)
604 {
605 $discount['MODULE'] = 'sale';
606 $discount['MODULE_ID'] = 'sale';
607 if($discount['USE_COUPONS'] == 'Y')
608 {
609 $discount['COUPON'] = $couponList[$discount['DISCOUNT_COUPON']];
610 }
611 }
612
613 private static function workWithDiscountHandlers(array &$discount)
614 {
615 $applyFlag = true;
616 if (isset(self::$cacheDiscountHandlers[$discount['ID']]))
617 {
618 $moduleList = self::$cacheDiscountHandlers[$discount['ID']]['MODULES'];
619 if (!empty($moduleList))
620 {
621 foreach ($moduleList as &$moduleID)
622 {
623 if (!isset(self::$usedModules[$moduleID]))
624 {
625 self::$usedModules[$moduleID] = Loader::includeModule($moduleID);
626 }
627 if (!self::$usedModules[$moduleID])
628 {
629 $applyFlag = false;
630 break;
631 }
632 }
633 unset($moduleID);
634 if ($applyFlag)
635 $discount['MODULES'] = $moduleList;
636 }
637 unset($moduleList);
638 }
639
640 return $applyFlag;
641 }
642
643 public static function PrepareCurrency4Where($val, $key, $operation, $negative, $field, $arField, $arFilter)
644 {
645 $val = (float)$val;
646
647 $baseSiteCurrency = '';
648 if (isset($arFilter["LID"]) && $arFilter["LID"] <> '')
649 $baseSiteCurrency = CSaleLang::GetLangCurrency($arFilter["LID"]);
650 elseif (isset($arFilter["CURRENCY"]) && $arFilter["CURRENCY"] <> '')
651 $baseSiteCurrency = $arFilter["CURRENCY"];
652
653 if ($baseSiteCurrency == '')
654 return false;
655
656 $strSqlSearch = '';
657
658 foreach (array_keys(Currency\CurrencyManager::getCurrencyList()) as $currency)
659 {
661 if ($strSqlSearch != '')
662 $strSqlSearch .= " OR ";
663
664 $strSqlSearch .= "(D.CURRENCY = '".$currency."' AND ";
665 if ($negative == "Y")
666 $strSqlSearch .= "NOT";
667 $strSqlSearch .= "(".$field." ".$operation." ".$val1." OR ".$field." IS NULL OR ".$field." = 0)";
668 $strSqlSearch .= ")";
669 }
670 unset($currency);
671 return ($strSqlSearch == '' ? false : '('.$strSqlSearch.')');
672 }
673
674 public static function GetByID($ID)
675 {
676 $ID = (int)$ID;
677 if ($ID > 0)
678 {
679 $rsDiscounts = CSaleDiscount::GetList(
680 array(),
681 array('ID' => $ID),
682 false,
683 false,
684 array(
685 "ID",
686 "XML_ID",
687 "LID",
688 "SITE_ID",
689 "NAME",
690 "PRICE_FROM",
691 "PRICE_TO",
692 "CURRENCY",
693 "DISCOUNT_VALUE",
694 "DISCOUNT_TYPE",
695 "ACTIVE",
696 "SORT",
697 "ACTIVE_FROM",
698 "ACTIVE_TO",
699 "TIMESTAMP_X",
700 "MODIFIED_BY",
701 "DATE_CREATE",
702 "CREATED_BY",
703 "PRIORITY",
704 "LAST_DISCOUNT",
705 "VERSION",
706 "CONDITIONS",
707 "UNPACK",
708 "APPLICATION",
709 "ACTIONS",
710 )
711 );
712 if ($arDiscount = $rsDiscounts->Fetch())
713 {
714 return $arDiscount;
715 }
716 }
717 return false;
718 }
719
720 public static function CheckFields($ACTION, &$arFields)
721 {
722 global $DB, $APPLICATION, $USER;
723
724 if (empty($arFields) || !is_array($arFields))
725 {
726 return false;
727 }
728 $ACTION = mb_strtoupper($ACTION);
729 if ('UPDATE' != $ACTION && 'ADD' != $ACTION)
730 return false;
731
732 $discountID = 0;
733 if ($ACTION == 'UPDATE')
734 {
735 if (isset($arFields['ID']))
736 $discountID = (int)$arFields['ID'];
737 if ($discountID <= 0)
738 return false;
739 }
740
741 $clearFields = array(
742 'ID',
743 '~ID',
744 'UNPACK',
745 '~UNPACK',
746 '~CONDITIONS',
747 'APPLICATION',
748 '~APPLICATION',
749 '~ACTIONS',
750 'USE_COUPONS',
751 '~USE_COUPONS',
752 'HANDLERS',
753 '~HANDLERS',
754 '~VERSION',
755 'TIMESTAMP_X',
756 'DATE_CREATE',
757 '~DATE_CREATE',
758 '~MODIFIED_BY',
759 '~CREATED_BY',
760 'EXECUTE_MODULE',
761 '~EXECUTE_MODULE',
762 'PREDICTIONS_APP',
763 '~PREDICTIONS_APP',
764 '~SHORT_DESCRIPTION'
765
766 );
767 if ($ACTION =='UPDATE')
768 $clearFields[] = 'CREATED_BY';
769
770 foreach ($clearFields as $fieldName)
771 {
772 if (array_key_exists($fieldName, $arFields))
773 unset($arFields[$fieldName]);
774 }
775 unset($fieldName, $clearFields);
776
777 if ($ACTION === "ADD")
778 {
779 $arFields["ACTIVE"] ??= 'N';
780 $arFields["DISCOUNT_TYPE"] ??= self::OLD_DSC_TYPE_FIX;
781 $arFields["DISCOUNT_VALUE"] ??= '';
782 $arFields["SORT"] ??= 100;
783 $arFields["LID"] ??= '';
784 $arFields["CURRENCY"] ??= '';
785 $arFields["ACTIVE_FROM"] ??= '';
786 $arFields["ACTIVE_TO"] ??= '';
787 $arFields["PRIORITY"] ??= 1;
788 $arFields["LAST_DISCOUNT"] ??= 'Y';
789 $arFields["USE_COUPONS"] ??= 'N';
790 }
791
792 if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"]!="Y")
793 {
794 $arFields["ACTIVE"] = "N";
795 }
796 if (is_set($arFields, "DISCOUNT_TYPE") && $arFields["DISCOUNT_TYPE"] != self::OLD_DSC_TYPE_PERCENT)
797 {
798 $arFields["DISCOUNT_TYPE"] = self::OLD_DSC_TYPE_FIX;
799 }
800
801 if (is_set($arFields, "SORT") && intval($arFields["SORT"])<=0)
802 {
803 $arFields["SORT"] = 100;
804 }
805
806 if (is_set($arFields, "LID") && $arFields["LID"] == '')
807 {
808 return false;
809 }
810
811 if (is_set($arFields, "LID"))
812 {
813 $dbSite = CSite::GetByID($arFields["LID"]);
814 if (!$dbSite->Fetch())
815 {
816 $APPLICATION->ThrowException(
818 'SKGD_NO_SITE',
819 array('#ID#' => $arFields['LID'])
820 ),
821 'ERROR_NO_SITE'
822 );
823 return false;
824 }
825 $arFields['CURRENCY'] = CSaleLang::GetLangCurrency($arFields["LID"]);
826 }
827
828 if (is_set($arFields, "CURRENCY") && $arFields["CURRENCY"] == '')
829 {
830 return false;
831 }
832
833 if (is_set($arFields, "CURRENCY"))
834 {
835 if (!($arCurrency = CCurrency::GetByID($arFields["CURRENCY"])))
836 {
837 $APPLICATION->ThrowException(
839 'SKGD_NO_CURRENCY',
840 array('#ID#' => $arFields['CURRENCY'])
841 ),
842 'ERROR_NO_CURRENCY'
843 );
844 return false;
845 }
846 }
847
848 if (is_set($arFields, "DISCOUNT_VALUE"))
849 {
850 if (!is_set($arFields["DISCOUNT_VALUE"]))
851 $arFields["DISCOUNT_VALUE"] = '';
852 $arFields["DISCOUNT_VALUE"] = str_replace(",", ".", $arFields["DISCOUNT_VALUE"]);
853 $arFields["DISCOUNT_VALUE"] = doubleval($arFields["DISCOUNT_VALUE"]);
854 }
855
856 if (is_set($arFields, "PRICE_FROM"))
857 {
858 $arFields["PRICE_FROM"] = str_replace(",", ".", $arFields["PRICE_FROM"]);
859 $arFields["PRICE_FROM"] = doubleval($arFields["PRICE_FROM"]);
860 }
861
862 if (is_set($arFields, "PRICE_TO"))
863 {
864 $arFields["PRICE_TO"] = str_replace(",", ".", $arFields["PRICE_TO"]);
865 $arFields["PRICE_TO"] = doubleval($arFields["PRICE_TO"]);
866 }
867
868 if (is_set($arFields, "ACTIVE_FROM") && (!$DB->IsDate($arFields["ACTIVE_FROM"], false, LANGUAGE_ID, "FULL")))
869 {
870 $arFields["ACTIVE_FROM"] = null;
871 }
872 if (is_set($arFields, "ACTIVE_TO") && (!$DB->IsDate($arFields["ACTIVE_TO"], false, LANGUAGE_ID, "FULL")))
873 {
874 $arFields["ACTIVE_TO"] = null;
875 }
876
877 if (is_set($arFields, 'PRIORITY') && intval($arFields['PRIORITY']) <= 0)
878 {
879 $arFields['PRIORITY'] = 1;
880 }
881 if (is_set($arFields, 'LAST_DISCOUNT') && $arFields["LAST_DISCOUNT"] != "N")
882 {
883 $arFields["LAST_DISCOUNT"] = 'Y';
884 }
885
886 $arFields['VERSION'] = self::VERSION_15;
887
888 $useConditions = array_key_exists('CONDITIONS', $arFields) || $ACTION === 'ADD';
889 $useActions = array_key_exists('ACTIONS', $arFields) || $ACTION === 'ADD';
890 $usePredictions = array_key_exists('PREDICTIONS', $arFields) || $ACTION === 'ADD';
891 $updateData = $useConditions || $useActions || $usePredictions;
892 $discountSite = (isset($arFields['LID']) ? trim($arFields['LID']) : '');
893 $usedHandlers = array();
894 $usedEntities = array();
895 $executeModule = '';
896 $conditionData = array(
897 'HANDLERS' => array(),
898 'ENTITY' => array(),
899 'EXECUTE_MODULE' => array()
900 );
901 $predictionData = array(
902 'HANDLERS' => array(),
903 'ENTITY' => array(),
904 'EXECUTE_MODULE' => array()
905 );
906 $actionData = array(
907 'HANDLERS' => array(),
908 'ENTITY' => array(),
909 'EXECUTE_MODULE' => array()
910 );
911
912 if ($updateData)
913 {
915 if ($discountSite == '')
916 $selectFields['LID'] = true;
917 if (!$useConditions)
918 {
919 $selectFields['LID'] = true;
920 $selectFields['CONDITIONS_LIST'] = true;
921 }
922 if (!$useActions)
923 {
924 $selectFields['LID'] = true;
925 $selectFields['ACTIONS_LIST'] = true;
926 }
927 if (!$usePredictions)
928 {
929 $selectFields['LID'] = true;
930 $selectFields['PREDICTIONS_LIST'] = true;
931 }
932 if (!empty($selectFields))
933 {
934 $selectFields['ID'] = true;
935 $discountInfo = Sale\Internals\DiscountTable::getList(array(
936 'select' => array_keys($selectFields),
937 'filter' => array('=ID' => $discountID)
938 ))->fetch();
939 if (empty($discountInfo))
940 return false;
941
942 if ($discountSite == '')
943 $discountSite = $discountInfo['LID'];
944 }
945 unset($selectFields);
946 if ($useConditions)
947 {
948 if (!isset($arFields['CONDITIONS']) || empty($arFields['CONDITIONS']))
949 {
950 $APPLICATION->ThrowException(Loc::getMessage('BT_MOD_SALE_DISC_ERR_EMPTY_CONDITIONS'), 'CONDITIONS');
951 return false;
952 }
953 else
954 {
955 $arFields['UNPACK'] = '';
956 if (!self::prepareDiscountConditions(
957 $arFields['CONDITIONS'],
958 $arFields['UNPACK'],
959 $conditionData,
960 self::PREPARE_CONDITIONS,
961 $discountSite)
962 )
963 return false;
964 }
965 }
966 else
967 {
968 $discountInfo['UNPACK'] = '';
969 if (!self::prepareDiscountConditions(
970 $discountInfo['CONDITIONS_LIST'],
971 $discountInfo['UNPACK'],
972 $conditionData,
973 self::PREPARE_CONDITIONS,
974 $discountSite)
975 )
976 return false;
977 }
978
979 if ($useActions)
980 {
981 if (!isset($arFields['ACTIONS']) || empty($arFields['ACTIONS']))
982 {
983 $APPLICATION->ThrowException(Loc::getMessage('BT_MOD_SALE_DISC_ERR_EMPTY_ACTIONS_EXT'), 'ACTIONS');
984 return false;
985 }
986 else
987 {
988 $arFields['APPLICATION'] = '';
989 if (!self::prepareDiscountConditions(
990 $arFields['ACTIONS'],
991 $arFields['APPLICATION'],
992 $actionData,
993 self::PREPARE_ACTIONS,
994 $discountSite)
995 )
996 return false;
997 }
998 }
999 else
1000 {
1001 $discountInfo['APPLICATION'] = '';
1002 if (!self::prepareDiscountConditions(
1003 $discountInfo['ACTIONS_LIST'],
1004 $discountInfo['APPLICATION'],
1005 $actionData,
1006 self::PREPARE_ACTIONS,
1007 $discountSite)
1008 )
1009 return false;
1010 }
1011
1012 if ($usePredictions)
1013 {
1014 $arFields['PREDICTIONS_APP'] = '';
1015 if (isset($arFields['PREDICTIONS']))
1016 {
1017 if (!self::prepareDiscountConditions(
1018 $arFields['PREDICTIONS'],
1019 $arFields['PREDICTIONS_APP'],
1020 $predictionData,
1021 self::PREPARE_CONDITIONS,
1022 $discountSite)
1023 )
1024 return false;
1025 }
1026 }
1027 else
1028 {
1029 if (
1030 isset($discountInfo['PREDICTIONS_LIST'])
1031 && $discountInfo['PREDICTIONS_LIST'] !== ''
1032 && $discountInfo['PREDICTIONS_LIST'] !== false
1033 )
1034 {
1035 $discountInfo['PREDICTIONS_APP'] = '';
1036 if (!self::prepareDiscountConditions(
1037 $discountInfo['PREDICTIONS_LIST'],
1038 $discountInfo['PREDICTIONS_APP'],
1039 $predictionData,
1040 self::PREPARE_CONDITIONS,
1041 $discountSite)
1042 )
1043 return false;
1044 }
1045 }
1046
1047 if (!empty($conditionData['HANDLERS']) || !empty($actionData['HANDLERS']) || !empty($predictionData['HANDLERS']))
1048 {
1049 $conditionData['HANDLERS']['MODULES'] = $conditionData['HANDLERS']['MODULES'] ?? [];
1050 $actionData['HANDLERS']['MODULES'] = $actionData['HANDLERS']['MODULES'] ?? [];
1051 $predictionData['HANDLERS']['MODULES'] = $predictionData['HANDLERS']['MODULES'] ?? [];
1052
1053 $conditionData['HANDLERS']['EXT_FILES'] = $conditionData['HANDLERS']['EXT_FILES'] ?? [];
1054 $actionData['HANDLERS']['EXT_FILES'] = $actionData['HANDLERS']['EXT_FILES'] ?? [];
1055 $predictionData['HANDLERS']['EXT_FILES'] = $predictionData['HANDLERS']['EXT_FILES'] ?? [];
1056
1057 $usedHandlers = array(
1058 'MODULES' => array_unique(array_merge(
1059 $conditionData['HANDLERS']['MODULES'],
1060 $actionData['HANDLERS']['MODULES'],
1061 $predictionData['HANDLERS']['MODULES']
1062 )),
1063 'EXT_FILES' => array_unique(array_merge(
1064 $conditionData['HANDLERS']['EXT_FILES'],
1065 $actionData['HANDLERS']['EXT_FILES'],
1066 $predictionData['HANDLERS']['EXT_FILES']
1067 )),
1068 );
1069 }
1070
1071 if (!empty($conditionData['EXECUTE_MODULE']) || !empty($actionData['EXECUTE_MODULE']) || !empty($predictionData['EXECUTE_MODULE']))
1072 {
1073 $conditionData['EXECUTE_MODULE'] = $conditionData['EXECUTE_MODULE'] ?? [];
1074 $actionData['EXECUTE_MODULE'] = $actionData['EXECUTE_MODULE'] ?? [];
1075 $predictionData['EXECUTE_MODULE'] = $predictionData['EXECUTE_MODULE'] ?? [];
1076
1077 $executeModuleList = array_merge(
1078 $conditionData['EXECUTE_MODULE'],
1079 $actionData['EXECUTE_MODULE'],
1080 $predictionData['EXECUTE_MODULE']
1081 );
1082
1083 $executeModuleList = array_unique($executeModuleList);
1084 if (count($executeModuleList) > 1)
1085 $executeModule = 'sale';
1086 else
1087 $executeModule = current($executeModuleList);
1088 unset($executeModuleList);
1089 }
1090
1091 if (!empty($conditionData['ENTITY']) || !empty($actionData['ENTITY']) || !empty($predictionData['ENTITY']))
1092 {
1093 $conditionData['ENTITY'] = $conditionData['ENTITY'] ?? [];
1094 $actionData['ENTITY'] = $actionData['ENTITY'] ?? [];
1095 $predictionData['ENTITY'] = $predictionData['ENTITY'] ?? [];
1096
1097 $usedEntities = array_merge(
1098 $conditionData['ENTITY'],
1099 $actionData['ENTITY'],
1100 $predictionData['ENTITY']
1101 );
1102 }
1103 }
1104 if (($ACTION == 'ADD' || $updateData) && $executeModule == '')
1105 $executeModule = 'all';
1106 if ($executeModule != '')
1107 $arFields['EXECUTE_MODULE'] = $executeModule;
1108
1109 if ($updateData)
1110 {
1111 $arFields['HANDLERS'] = $usedHandlers;
1112 $arFields['ENTITIES'] = $usedEntities;
1113 }
1114
1115 if (is_set($arFields, 'USE_COUPONS') && ('Y' != $arFields['USE_COUPONS']))
1116 {
1117 $arFields['USE_COUPONS'] = 'N';
1118 }
1119
1120 if (array_key_exists('USER_GROUPS', $arFields) || $ACTION=="ADD")
1121 {
1123 if (empty($arFields['USER_GROUPS']) || !is_array($arFields['USER_GROUPS']))
1124 {
1125 $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_SALE_DISC_ERR_USER_GROUPS_ABSENT_SHORT"), "USER_GROUPS");
1126 return false;
1127 }
1128 }
1129
1130 if(empty($arFields['SHORT_DESCRIPTION']) && !empty($arFields['ACTIONS']))
1131 {
1133 if($actionConfiguration)
1134 {
1135 $arFields['SHORT_DESCRIPTION'] = serialize($actionConfiguration);
1136 }
1137 else
1138 {
1139 $arFields['SHORT_DESCRIPTION'] = null;
1140 }
1141 }
1142
1143 $intUserID = 0;
1144 $boolUserExist = isset($USER) && $USER instanceof CUser;
1145 if ($boolUserExist)
1146 $intUserID = (int)$USER->GetID();
1147 $strDateFunction = $DB->GetNowFunction();
1148 $arFields['~TIMESTAMP_X'] = $strDateFunction;
1149 if ($boolUserExist)
1150 {
1151 if (!array_key_exists('MODIFIED_BY', $arFields) || (int)$arFields["MODIFIED_BY"] <= 0)
1152 $arFields["MODIFIED_BY"] = $intUserID;
1153 }
1154 if ($ACTION == 'ADD')
1155 {
1156 $arFields['~DATE_CREATE'] = $strDateFunction;
1157 if ($boolUserExist)
1158 {
1159 if (!array_key_exists('CREATED_BY', $arFields) || (int)$arFields["CREATED_BY"] <= 0)
1160 $arFields["CREATED_BY"] = $intUserID;
1161 }
1162 }
1163
1164 return true;
1165 }
1166
1167 public static function Add($arFields)
1168 {
1169 global $APPLICATION;
1170
1171 $boolNewVersion = true;
1172 if (!array_key_exists('CONDITIONS', $arFields) && !array_key_exists('ACTIONS', $arFields))
1173 {
1174 $boolConvert = self::__ConvertOldFormat('ADD', $arFields);
1175 if (!$boolConvert)
1176 return false;
1177 $boolNewVersion = false;
1178 }
1179
1180 if (!self::CheckFields("ADD", $arFields))
1181 return false;
1182
1183 if ($boolNewVersion)
1184 {
1185 $boolConvert = self::__SetOldFields('ADD', $arFields);
1186 if (!$boolConvert)
1187 return false;
1188 }
1189
1190 $tableFields = self::clearFields($arFields);
1191 if (empty($tableFields))
1192 return false;
1193
1194 $result = Sale\Internals\DiscountTable::add($tableFields);
1195 if (!$result->isSuccess())
1196 {
1197 foreach ($result->getErrorMessages() as $error)
1198 $APPLICATION->ThrowException($error);
1199 }
1200 $ID = (int)$result->getId();
1201
1202 if ($ID > 0)
1203 {
1205 if (isset($arFields['HANDLERS']))
1206 self::updateDiscountHandlers($ID, $arFields['HANDLERS'], false);
1207 if (isset($arFields['ENTITIES']))
1209 }
1210
1211 return $ID;
1212 }
1213
1214 public static function Update($ID, $arFields)
1215 {
1216 global $APPLICATION;
1217
1218 $ID = (int)$ID;
1219 if ($ID <= 0)
1220 return false;
1221
1222 $boolNewVersion = true;
1223 $arFields['ID'] = $ID;
1224 if (!array_key_exists('CONDITIONS', $arFields) && !array_key_exists('ACTIONS', $arFields))
1225 {
1226 $boolConvert = self::__ConvertOldFormat('UPDATE', $arFields);
1227 if (!$boolConvert)
1228 return false;
1229 $boolNewVersion = false;
1230 }
1231
1232 if (!self::CheckFields("UPDATE", $arFields))
1233 return false;
1234
1235 if ($boolNewVersion)
1236 {
1237 $boolConvert = self::__SetOldFields('UPDATE', $arFields);
1238 if (!$boolConvert)
1239 return false;
1240 }
1241
1242 $tableFields = self::clearFields($arFields);
1243 if (!empty($tableFields))
1244 {
1245 $result = Sale\Internals\DiscountTable::update($ID, $tableFields);
1246 if (!$result->isSuccess())
1247 {
1248 foreach ($result->getErrorMessages() as $error)
1249 $APPLICATION->ThrowException($error);
1250 return false;
1251 }
1252 }
1253
1254 if (isset($arFields['USER_GROUPS']))
1255 {
1257 $ID,
1258 $arFields['USER_GROUPS'],
1259 (isset($arFields['ACTIVE']) ? $arFields['ACTIVE'] : ''),
1260 true
1261 );
1262 }
1263
1264 if (isset($arFields['HANDLERS']))
1265 self::updateDiscountHandlers($ID, $arFields['HANDLERS'], true);
1266 if (isset($arFields['ENTITIES']))
1268
1269 return $ID;
1270 }
1271
1272 /*
1273 * @deprecated deprecated since sale 14.11.0
1274 * @see \Bitrix\Sale\Internals\DiscountTable::delete
1275 */
1276 public static function Delete($ID)
1277 {
1278 $ID = (int)$ID;
1279 if ($ID <= 0)
1280 return false;
1281
1282 $result = Sale\Internals\DiscountTable::delete($ID);
1283 return $result->isSuccess();
1284 }
1285
1286 protected static function getDiscountResult(&$oldOrder, &$currentOrder, $extMode = false)
1287 {
1288 $extMode = ($extMode === true);
1289 $result = array();
1290 if (isset($oldOrder['PRICE_DELIVERY']) && isset($currentOrder['PRICE_DELIVERY']))
1291 {
1292 if ($oldOrder['PRICE_DELIVERY'] != $currentOrder['PRICE_DELIVERY'])
1293 {
1294 $absValue = $oldOrder['PRICE_DELIVERY'] - $currentOrder['PRICE_DELIVERY'];
1295 $fullValue = ($extMode && isset($currentOrder['PRICE_DELIVERY_ORIG']) ? $currentOrder['PRICE_DELIVERY_ORIG'] : $oldOrder['PRICE_DELIVERY']);
1296 $percValue = ($fullValue != 0 ? $absValue*100/$fullValue : 0);
1297 $result['DELIVERY'] = array(
1298 'TYPE' => 'D',
1299 'DISCOUNT_TYPE' => ($currentOrder['PRICE_DELIVERY'] < $oldOrder['PRICE_DELIVERY'] ? 'D' : 'M'),
1300 'VALUE' => $absValue,
1301 'VALUE_PERCENT' => $percValue,
1302 'DELIVERY_ID' => (isset($currentOrder['DELIVERY_ID']) ? $currentOrder['DELIVERY_ID'] : false)
1303 );
1304 unset($percValue, $fullValue, $absValue);
1305 }
1306 }
1307 if (!empty($oldOrder['BASKET_ITEMS']) && !empty($currentOrder['BASKET_ITEMS']))
1308 {
1309 foreach ($oldOrder['BASKET_ITEMS'] as $key => $item)
1310 {
1311 if (!isset($currentOrder['BASKET_ITEMS'][$key]))
1312 continue;
1313 if ($item['PRICE'] != $currentOrder['BASKET_ITEMS'][$key]['PRICE'])
1314 {
1315 $newItem = &$currentOrder['BASKET_ITEMS'][$key];
1316 $absValue = $item['PRICE'] - $newItem['PRICE'];
1317 $fullValue = ($extMode && isset($newItem['PRICE_ORIG']) ? $newItem['PRICE_ORIG'] : $item['PRICE']);
1318 $percValue = ($fullValue != 0 ? $absValue*100/$fullValue : 0);
1319 if (!isset($result['BASKET']))
1320 $result['BASKET'] = array();
1321 $result['BASKET'][] = array(
1322 'TYPE' => 'B',
1323 'DISCOUNT_TYPE' => ($newItem['PRICE'] < $item['PRICE'] ? 'D' : 'M'),
1324 'VALUE' => $absValue,
1325 'VALUE_PERCENT' => $percValue,
1326 'BASKET_NUM' => $key,
1327 'BASKET_ID' => (isset($newItem['ID']) ? $newItem['ID'] : '0'),
1328 'BASKET_PRODUCT_XML_ID' => (isset($newItem['PRODUCT_XML_ID']) && $newItem['PRODUCT_XML_ID'] != '' ? $newItem['PRODUCT_XML_ID'] : false),
1329 'PRODUCT_ID' => $newItem['PRODUCT_ID'],
1330 'MODULE' => $newItem['MODULE']
1331 );
1332 unset($percValue, $fullValue, $absValue, $newItem);
1333 }
1334 }
1335 }
1336 return $result;
1337 }
1338
1339 protected static function changeDiscountResult(&$oldOrder, &$order, &$discountResult)
1340 {
1341 if (empty($discountResult['BASKET']) || count($discountResult['BASKET']) <= 1)
1342 return;
1343 $maxPrice = 0;
1344 $maxKey = -1;
1345 $basketKeys = array();
1346 foreach ($discountResult['BASKET'] as $key => $row)
1347 {
1348 $basketKeys[$key] = $row['BASKET_NUM'];
1349 if ($maxPrice < $oldOrder['BASKET_ITEMS'][$row['BASKET_NUM']]['PRICE'])
1350 {
1351 $maxPrice = $oldOrder['BASKET_ITEMS'][$row['BASKET_NUM']]['PRICE'];
1352 $maxKey = $key;
1353 }
1354 }
1355 unset($row, $key);
1356 unset($basketKeys[$maxKey]);
1357 foreach ($basketKeys as $key => $basketRow)
1358 {
1359 unset($discountResult['BASKET'][$key]);
1360 $order['BASKET_ITEMS'][$basketRow] = $oldOrder['BASKET_ITEMS'][$basketRow];
1361 }
1362 $discountResult['BASKET'] = array_values($discountResult['BASKET']);
1363 }
1364
1365 protected static function __Unpack($arOrder, $strUnpack)
1366 {
1367 $checkOrder = null;
1368 if (empty($strUnpack))
1369 return false;
1370 eval('$checkOrder='.$strUnpack.';');
1371 if (!is_callable($checkOrder))
1372 return false;
1373 $boolRes = $checkOrder($arOrder);
1374 unset($checkOrder);
1375 return $boolRes;
1376 }
1377
1378 protected static function __ApplyActions(&$arOrder, $strActions)
1379 {
1380 $applyOrder = null;
1381 if (!empty($strActions))
1382 {
1383 eval('$applyOrder='.$strActions.';');
1384 if (is_callable($applyOrder))
1385 $applyOrder($arOrder);
1386 }
1387 }
1388
1389 protected static function __ConvertOldFormat($strAction, &$arFields)
1390 {
1391 global $APPLICATION;
1392
1393 $arMsg = array();
1394 $boolResult = true;
1395
1396 $arNeedFields = array(
1397 'LID',
1398 'CURRENCY',
1399 'DISCOUNT_TYPE',
1400 'DISCOUNT_VALUE',
1401 'PRICE_FROM',
1402 'PRICE_TO',
1403 );
1404 $arUpdateFields = array(
1405 'DISCOUNT_VALUE',
1406 'PRICE_FROM',
1407 'PRICE_TO',
1408 );
1409
1410 $strAction = mb_strtoupper($strAction);
1411 if (!array_key_exists('CONDITIONS', $arFields) && !array_key_exists('ACTIONS', $arFields))
1412 {
1413 $strSiteCurrency = '';
1414 $boolUpdate = false;
1415
1416 if ('UPDATE' == $strAction)
1417 {
1418 $boolNeedQuery = false;
1419 foreach ($arUpdateFields as &$strFieldID)
1420 {
1421 if (array_key_exists($strFieldID, $arFields))
1422 {
1423 $boolUpdate = true;
1424 break;
1425 }
1426 }
1427 if (isset($strFieldID))
1428 unset($strFieldID);
1429 if ($boolUpdate)
1430 {
1431 foreach ($arNeedFields as &$strFieldID)
1432 {
1433 if (!array_key_exists($strFieldID, $arFields))
1434 {
1435 $boolNeedQuery = true;
1436 break;
1437 }
1438 }
1439 if (isset($strFieldID))
1440 unset($strFieldID);
1441
1442 if ($boolNeedQuery)
1443 {
1444 $rsDiscounts = CSaleDiscount::GetList(array(), array('ID' => $arFields['ID']), false, false, $arNeedFields);
1445 if ($arDiscount = $rsDiscounts->Fetch())
1446 {
1447 foreach ($arNeedFields as &$strFieldID)
1448 {
1449 if (!array_key_exists($strFieldID, $arFields))
1450 {
1451 $arFields[$strFieldID] = $arDiscount[$strFieldID];
1452 }
1453 }
1454 if (isset($strFieldID))
1455 unset($strFieldID);
1456 }
1457 else
1458 {
1459 $boolUpdate = false;
1460 $boolResult = false;
1461 $arMsg[] = array('id' => 'ID', 'text' => Loc::getMessage('BT_MOD_SALE_ERR_DSC_ABSENT'));
1462 }
1463 }
1464 }
1465 }
1466
1467 if ('ADD' == $strAction || $boolUpdate)
1468 {
1469 if (!array_key_exists('LID', $arFields))
1470 {
1471 $boolResult = false;
1472 $arMsg[] = array('id' => 'LID','text' => Loc::getMessage('BT_MOD_SALE_ERR_DSC_SITE_ID_ABSENT'));
1473 }
1474 else
1475 {
1476 $arFields['LID'] = strval($arFields['LID']);
1477 if ('' == $arFields['LID'])
1478 {
1479 $boolResult = false;
1480 $arMsg[] = array('id' => 'LID','text' => Loc::getMessage('BT_MOD_SALE_ERR_DSC_SITE_ID_ABSENT'));
1481 }
1482 else
1483 {
1484 $rsSites = CSite::GetByID($arFields["LID"]);
1485 if (!$arSite = $rsSites->Fetch())
1486 {
1487 $boolResult = false;
1488 $arMsg[] = array('id' => 'LID', 'text' => Loc::getMessage('SKGD_NO_SITE', array('#ID#' => $arFields['LID'])));
1489 }
1490 else
1491 {
1492 $strSiteCurrency = CSaleLang::GetLangCurrency($arFields['LID']);
1493 }
1494 }
1495 }
1496
1497 if (!array_key_exists('CURRENCY', $arFields))
1498 {
1499 $boolResult = false;
1500 $arMsg[] = array('id' => 'CURRENCY', 'text' => Loc::getMessage('BT_MOD_SALE_ERR_DSC_CURRENCY_ABSENT'));
1501 }
1502 else
1503 {
1504 $arFields['CURRENCY'] = strval($arFields['CURRENCY']);
1505 if ('' == $arFields['CURRENCY'])
1506 {
1507 $boolResult = false;
1508 $arMsg[] = array('id' => 'CURRENCY', 'text' => Loc::getMessage('BT_MOD_SALE_ERR_DSC_CURRENCY_ABSENT'));
1509 }
1510 else
1511 {
1512 if (!($arCurrency = CCurrency::GetByID($arFields["CURRENCY"])))
1513 {
1514 $boolResult = false;
1515 $arMsg[] = array('id' => 'CURRENCY', 'text' => Loc::getMessage('SKGD_NO_CURRENCY', array('#ID#' => $arFields['CURRENCY'])));
1516 }
1517 }
1518 }
1519
1520 if (!array_key_exists("DISCOUNT_TYPE", $arFields))
1521 {
1522 $boolResult = false;
1523 $arMsg[] = array('id' => 'DISCOUNT_TYPE', 'text' => Loc::getMessage('BT_MOD_SALE_ERR_DSC_TYPE_ABSENT'));
1524 }
1525 else
1526 {
1527 $arFields["DISCOUNT_TYPE"] = strval($arFields["DISCOUNT_TYPE"]);
1528 if (CSaleDiscount::OLD_DSC_TYPE_PERCENT != $arFields["DISCOUNT_TYPE"] && CSaleDiscount::OLD_DSC_TYPE_FIX != $arFields["DISCOUNT_TYPE"])
1529 {
1530 $boolResult = false;
1531 $arMsg[] = array('id' => 'DISCOUNT_TYPE', 'text' => Loc::getMessage('BT_MOD_SALE_ERR_DSC_TYPE_BAD'));
1532 }
1533 }
1534
1535 if (!array_key_exists('DISCOUNT_VALUE', $arFields))
1536 {
1537 $boolResult = false;
1538 $arMsg[] = array('id' => 'DISCOUNT_VALUE', 'text' => Loc::getMessage('BT_MOD_SALE_ERR_DSC_VALUE_ABSENT'));
1539 }
1540 else
1541 {
1542 $arFields['DISCOUNT_VALUE'] = (float)str_replace(',', '.', $arFields['DISCOUNT_VALUE']);
1543 if (0 >= $arFields['DISCOUNT_VALUE'])
1544 {
1545 $boolResult = false;
1546 $arMsg[] = array('id' => 'DISCOUNT_VALUE', 'text' => Loc::getMessage('BT_MOD_SALE_ERR_DSC_VALUE_BAD'));
1547 }
1548 }
1549
1550 if ($boolResult)
1551 {
1552 $arConditions = array(
1553 'CLASS_ID' => 'CondGroup',
1554 'DATA' => array(
1555 'All' => 'AND',
1556 'True' => 'True',
1557 ),
1558 'CHILDREN' => array(),
1559 );
1560 $arActions = array(
1561 'CLASS_ID' => 'CondGroup',
1562 'DATA' => array(
1563 'All' => 'AND',
1564 'True' => 'True',
1565 ),
1566 'CHILDREN' => array(),
1567 );
1568
1569 $boolCurrency = ($arFields['CURRENCY'] == $strSiteCurrency);
1570
1571 if (array_key_exists('PRICE_FROM', $arFields))
1572 {
1573 $arFields["PRICE_FROM"] = str_replace(",", ".", strval($arFields["PRICE_FROM"]));
1574 $arFields["PRICE_FROM"] = doubleval($arFields["PRICE_FROM"]);
1575 if (0 < $arFields["PRICE_FROM"])
1576 {
1577 $dblValue = roundEx(($boolCurrency ? $arFields['PRICE_FROM'] : CCurrencyRates::ConvertCurrency($arFields['PRICE_FROM'], $arFields['CURRENCY'], $strSiteCurrency)), SALE_VALUE_PRECISION);
1578 $arConditions['CHILDREN'][] = array(
1579 'CLASS_ID' => 'CondBsktAmtGroup',
1580 'DATA' => array(
1581 'logic' => 'EqGr',
1582 'Value' => (string)$dblValue,
1583 'All' => 'AND',
1584 ),
1585 'CHILDREN' => array(
1586 ),
1587 );
1588 $arFields["PRICE_FROM"] = $dblValue;
1589 }
1590 }
1591 if (array_key_exists('PRICE_TO', $arFields))
1592 {
1593 $arFields["PRICE_TO"] = str_replace(",", ".", strval($arFields["PRICE_TO"]));
1594 $arFields["PRICE_TO"] = doubleval($arFields["PRICE_TO"]);
1595 if (0 < $arFields["PRICE_TO"])
1596 {
1597 $dblValue = roundEx(($boolCurrency ? $arFields['PRICE_TO'] : CCurrencyRates::ConvertCurrency($arFields['PRICE_TO'], $arFields['CURRENCY'], $strSiteCurrency)), SALE_VALUE_PRECISION);
1598 $arConditions['CHILDREN'][] = array(
1599 'CLASS_ID' => 'CondBsktAmtGroup',
1600 'DATA' => array(
1601 'logic' => 'EqLs',
1602 'Value' => (string)$dblValue,
1603 'All' => 'AND',
1604 ),
1605 'CHILDREN' => array(
1606 ),
1607 );
1608 $arFields["PRICE_TO"] = $dblValue;
1609 }
1610 }
1611 if (self::OLD_DSC_TYPE_PERCENT == $arFields['DISCOUNT_TYPE'])
1612 {
1613 $arActions['CHILDREN'][] = array(
1614 'CLASS_ID' => 'ActSaleBsktGrp',
1615 'DATA' => array(
1616 'Type' => 'Discount',
1617 'Value' => (string)roundEx($arFields['DISCOUNT_VALUE'], SALE_VALUE_PRECISION),
1618 'Unit' => 'Perc',
1619 'All' => 'AND',
1620 'True' => 'True'
1621 ),
1622 'CHILDREN' => array(
1623 ),
1624 );
1625 }
1626 else
1627 {
1628 $dblValue = roundEx(($boolCurrency ? $arFields['DISCOUNT_VALUE'] : CCurrencyRates::ConvertCurrency($arFields['DISCOUNT_VALUE'], $arFields['CURRENCY'], $strSiteCurrency)), SALE_VALUE_PRECISION);
1629 $arActions['CHILDREN'][] = array(
1630 'CLASS_ID' => 'ActSaleBsktGrp',
1631 'DATA' => array(
1632 'Type' => 'Discount',
1633 'Value' => (string)$dblValue,
1634 'Unit' => 'CurAll',
1635 'All' => 'AND',
1636 'True' => 'True'
1637 ),
1638 'CHILDREN' => array(
1639 ),
1640 );
1641 $arFields['DISCOUNT_VALUE'] = $dblValue;
1642 }
1643
1644 $arFields['CONDITIONS'] = $arConditions;
1645 $arFields['ACTIONS'] = $arActions;
1646 $arFields['CURRENCY'] = $strSiteCurrency;
1647 }
1648 else
1649 {
1650 $obError = new CAdminException($arMsg);
1651 $APPLICATION->ThrowException($obError);
1652 }
1653 }
1654 }
1655 return $boolResult;
1656 }
1657
1658 protected static function __SetOldFields($strAction, &$arFields)
1659 {
1660 global $APPLICATION;
1661
1662 $arMsg = array();
1663 $boolResult = true;
1664
1665 $strAction = mb_strtoupper($strAction);
1666 if (array_key_exists('CONDITIONS', $arFields) && !empty($arFields['CONDITIONS']))
1667 {
1668 $arConditions = false;
1669 if (!is_array($arFields['CONDITIONS']))
1670 {
1671 if (CheckSerializedData($arFields['CONDITIONS']))
1672 {
1673 $arConditions = unserialize($arFields['CONDITIONS'], ['allowed_classes' => false]);
1674 }
1675 }
1676 else
1677 {
1678 $arConditions = $arFields['CONDITIONS'];
1679 }
1680
1681 if (is_array($arConditions) && !empty($arConditions))
1682 {
1683 $obCond = new CSaleCondTree();
1684 $boolCond = $obCond->Init(BT_COND_MODE_SEARCH, BT_COND_BUILD_SALE, array());
1685 if ($boolCond)
1686 {
1687 $arResult = $obCond->GetConditionValues($arConditions);
1688
1689 }
1690 }
1691 }
1692 if (array_key_exists('ACTIONS', $arFields) && !empty($arFields['ACTIONS']))
1693 {
1694 $arActions = false;
1695 if (!is_array($arFields['ACTIONS']))
1696 {
1697 if (CheckSerializedData($arFields['ACTIONS']))
1698 {
1699 $arActions = unserialize($arFields['ACTIONS'], ['allowed_classes' => false]);
1700 }
1701 }
1702 else
1703 {
1704 $arActions = $arFields['ACTIONS'];
1705 }
1706
1707 if (is_array($arActions) && !empty($arActions))
1708 {
1709 $obAct = new CSaleActionTree();
1710 $boolAct = $obAct->Init(BT_COND_MODE_SEARCH, BT_COND_BUILD_SALE_ACTIONS, array());
1711 if ($boolAct)
1712 {
1713 $arResult = $obAct->GetConditionValues($arActions);
1714 }
1715 }
1716 }
1717
1718 if (!$boolResult)
1719 {
1720 $obError = new CAdminException($arMsg);
1721 $APPLICATION->ThrowException($obError);
1722 }
1723
1724 return $boolResult;
1725 }
1726
1727 protected static function prepareDiscountConditions(&$conditions, &$result, &$handlers, $type, $site)
1728 {
1729 global $APPLICATION;
1730
1731 $obCond = null;
1732 $result = '';
1733 $handlers = array();
1734 $type = (int)$type;
1735 if ($type != self::PREPARE_CONDITIONS && $type != self::PREPARE_ACTIONS || empty($conditions))
1736 {
1737 return false;
1738 }
1739 if (!is_array($conditions))
1740 {
1741 if (!CheckSerializedData($conditions))
1742 {
1743 if ($type == self::PREPARE_CONDITIONS)
1744 {
1745 $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_SALE_DISC_ERR_BAD_CONDITIONS"), "CONDITIONS");
1746 }
1747 else
1748 {
1749 $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_SALE_DISC_ERR_BAD_ACTIONS_EXT"), "ACTIONS");
1750 }
1751 return false;
1752 }
1753 $conditions = unserialize($conditions, ['allowed_classes' => false]);
1754 if (!is_array($conditions) || empty($conditions))
1755 {
1756 if ($type == self::PREPARE_CONDITIONS)
1757 {
1758 $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_SALE_DISC_ERR_BAD_CONDITIONS"), "CONDITIONS");
1759 }
1760 else
1761 {
1762 $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_SALE_DISC_ERR_BAD_ACTIONS_EXT"), "ACTIONS");
1763 }
1764 return false;
1765 }
1766 }
1767
1768 if ($type == self::PREPARE_CONDITIONS)
1769 {
1770 $obCond = new CSaleCondTree();
1771 $boolCond = $obCond->Init(BT_COND_MODE_GENERATE, BT_COND_BUILD_SALE, array('INIT_CONTROLS' => array(
1772 'SITE_ID' => $site,
1774 )));
1775 }
1776 else
1777 {
1778 $obCond = new CSaleActionTree();
1779 $boolCond = $obCond->Init(BT_COND_MODE_GENERATE, BT_COND_BUILD_SALE_ACTIONS, array());
1780 }
1781 if (!$boolCond)
1782 {
1783 return false;
1784 }
1785 $result = $obCond->Generate(
1786 $conditions,
1787 array(
1788 'ORDER' => '$arOrder',
1789 'ORDER_FIELDS' => '$arOrder',
1790 'ORDER_PROPS' => '$arOrder[\'ORDER_PROP\']',
1791 'ORDER_BASKET' => '$arOrder[\'BASKET_ITEMS\']',
1792 'BASKET' => '$arBasket',
1793 'BASKET_ROW' => '$row',
1794 )
1795 );
1796 if ($result == '')
1797 {
1798 if ($type == self::PREPARE_CONDITIONS)
1799 {
1800 $APPLICATION->ThrowException(Loc::getMessage('BT_MOD_SALE_DISC_ERR_BAD_CONDITIONS'), 'CONDITIONS');
1801 }
1802 else
1803 {
1804 $APPLICATION->ThrowException(Loc::getMessage('BT_MOD_SALE_DISC_ERR_BAD_ACTIONS_EXT'), 'ACTIONS');
1805 }
1806 return false;
1807 }
1808 else
1809 {
1810 $handlers['HANDLERS'] = $obCond->GetConditionHandlers();
1811 $handlers['ENTITY'] = $obCond->GetUsedEntityList();
1812 $handlers['EXECUTE_MODULE'] = $obCond->GetExecuteModule();
1813 }
1814 $conditions = serialize($conditions);
1815
1816 return true;
1817 }
1818
1819 protected static function updateDiscountHandlers($discountID, $handlers, $update)
1820 {
1821 $discountID = (int)$discountID;
1822 if ($discountID <= 0 || empty($handlers) || !is_array($handlers))
1823 return;
1824 if (isset($handlers['MODULES']))
1825 Sale\Internals\DiscountModuleTable::updateByDiscount($discountID, $handlers['MODULES'], $update);
1826 }
1827
1828 protected static function getDiscountHandlers($discountList)
1829 {
1830 $result = array();
1831 if (!empty($discountList) && is_array($discountList))
1832 {
1833 $moduleList = Sale\Internals\DiscountModuleTable::getByDiscount($discountList);
1834 if (!empty($moduleList))
1835 {
1836 foreach ($moduleList as $discount => $discountModule)
1837 {
1839 'MODULES' => $discountModule,
1840 'EXT_FILES' => array()
1841 );
1842 }
1843 unset($discount, $discountModule, $moduleList);
1844 }
1845 }
1846 return $result;
1847 }
1848
1849 /*
1850 * @deprecated deprecated since sale 14.11.0
1851 * @see \Bitrix\Sale\Internals\DiscountGroupTable::updateByDiscount
1852 */
1853 protected function updateUserGroups($discountID, $userGroups, $active, $updateData)
1854 {
1855 Sale\Internals\DiscountGroupTable::updateByDiscount($discountID, $userGroups, $active, $updateData);
1856 }
1857
1858 private static function clearFields(array $fields)
1859 {
1860 $whiteList = array(
1861 'XML_ID', 'LID', 'NAME',
1862 'PRICE_FROM', 'PRICE_TO', 'CURRENCY', 'DISCOUNT_VALUE', 'DISCOUNT_TYPE',
1863 'ACTIVE', 'SORT',
1864 'MODIFIED_BY', 'CREATED_BY',
1865 'PRIORITY', 'LAST_DISCOUNT', 'LAST_LEVEL_DISCOUNT',
1866 'VERSION',
1867 'CONDITIONS_LIST', 'UNPACK', 'ACTIONS_LIST', 'APPLICATION',
1868 'PREDICTION_TEXT', 'PREDICTIONS_APP', 'PREDICTIONS_LIST',
1869 'USE_COUPONS', 'EXECUTE_MODULE',
1870 'PRESET_ID'
1871 );
1872 $convertList = array(
1873 'CONDITIONS_LIST' => 'CONDITIONS',
1874 'ACTIONS_LIST' => 'ACTIONS',
1875 'PREDICTIONS_LIST' => 'PREDICTIONS',
1876 'SHORT_DESCRIPTION_STRUCTURE' => 'SHORT_DESCRIPTION'
1877 );
1878 $datetimeList = array(
1879 'ACTIVE_FROM', 'ACTIVE_TO',
1880 'TIMESTAMP_X', 'DATE_CREATE'
1881 );
1882
1883 $result = array();
1884 foreach ($convertList as $fieldName => $oldField)
1885 {
1886 if (!array_key_exists($oldField, $fields))
1887 continue;
1888 if (!is_array($fields[$oldField]) && $fields[$oldField] !== null)
1889 {
1890 $fields[$oldField] = (string)$fields[$oldField];
1891 if (CheckSerializedData($fields[$oldField]))
1892 $fields[$oldField] = unserialize($fields[$oldField], ['allowed_classes' => false]);
1893 else
1894 $fields[$oldField] = null;
1895 }
1896 $result[$fieldName] = $fields[$oldField];
1897 }
1898 unset($fieldName, $oldField);
1899
1900 foreach ($whiteList as $fieldName)
1901 {
1902 if (!array_key_exists($fieldName, $fields))
1903 continue;
1904 $result[$fieldName] = $fields[$fieldName];
1905 }
1906 unset($fieldName);
1907
1908 foreach ($datetimeList as $fieldName)
1909 {
1910 if (!array_key_exists($fieldName, $fields))
1911 continue;
1912 if (is_string($fields[$fieldName]))
1913 {
1914 $fields[$fieldName] = trim($fields[$fieldName]);
1915 $fields[$fieldName] = (
1916 $fields[$fieldName] === ''
1917 ? null
1918 : Main\Type\DateTime::createFromUserTime($fields[$fieldName])
1919 );
1920 }
1921 $result[$fieldName] = $fields[$fieldName];
1922 }
1923 unset($fieldName);
1924
1925 return $result;
1926 }
1927}
$type
Определения options.php:106
global $APPLICATION
Определения include.php:80
$arResult
Определения generate_coupon.php:16
const BT_COND_BUILD_SALE_ACTIONS
Определения catalog_cond.php:26
const BT_COND_MODE_GENERATE
Определения catalog_cond.php:20
const BT_COND_MODE_SEARCH
Определения catalog_cond.php:22
const BT_COND_BUILD_SALE
Определения catalog_cond.php:25
static getCurrencyList()
Определения currencymanager.php:109
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
Определения loader.php:13
static getMessage($code, $replace=null, $language=null)
Определения loc.php:30
static normalizeArrayValuesByInt(&$map, $sorted=true)
Определения collection.php:150
static setOldDiscountResult($discountList)
Определения discountcompatibility.php:763
static init($mode=self::MODE_CLIENT, $config=array())
Определения discountcompatibility.php:314
static roundPrices(array &$basket, array $orderData=array())
Определения discountcompatibility.php:1032
static calculateSaleDiscount(&$order, $discount)
Определения discountcompatibility.php:785
static getApplyResult($extMode=false)
Определения discountcompatibility.php:883
static getActionConfiguration(array $discount)
Определения actions.php:1239
static setUseMode($mode, array $config=array())
Определения actions.php:91
static clearAction()
Определения actions.php:431
const MODE_CALCULATE
Определения actions.php:24
const TYPE_VALUE
Определения formatter.php:11
const VALUE_ACTION_DISCOUNT
Определения formatter.php:22
const VALUE_ACTION_CUMULATIVE
Определения formatter.php:24
const VALUE_TYPE_PERCENT
Определения formatter.php:17
static getForApply($filter, $product=[], $uniqueDiscount=false)
Определения discountcouponsmanagerbase.php:986
static getByDiscount($discountList, $filter=array(), $groupModule=true)
Определения discountentities.php:218
static updateByDiscount($discount, $entityList, $clear)
Определения discountentities.php:166
static updateByDiscount($discount, $groupList, $active, $clear)
Определения discountgroup.php:112
static getByDiscount($discountList, $filter=array())
Определения discountmodule.php:142
static updateByDiscount($discount, $moduleList, $clear)
Определения discountmodule.php:110
static getSiteCurrency($siteId)
Определения sitecurrency.php:96
static roundPrecision($value)
Определения pricemaths.php:16
static GetByID($currency)
Определения currency.php:453
static ConvertCurrency($valSum, $curFrom, $curTo, $valDate="")
Определения currency_rate.php:393
static getIdByCode($code)
Определения delivery.php:1641
Определения discount.php:11
const VERSION_NEW
Определения discount.php:13
const OLD_DSC_TYPE_PERCENT
Определения discount.php:16
static prepareDiscountConditions(&$conditions, &$result, &$handlers, $type, $site)
Определения discount.php:1727
static DoProcessOrder(&$arOrder, $arOptions, &$arErrors)
Определения discount.php:40
static Delete($ID)
Определения discount.php:1276
static Add($arFields)
Определения discount.php:1167
static GetByID($ID)
Определения discount.php:674
static changeDiscountResult(&$oldOrder, &$order, &$discountResult)
Определения discount.php:1339
static $cacheDiscountHandlers
Определения discount.php:22
updateUserGroups($discountID, $userGroups, $active, $updateData)
Определения discount.php:1853
static getDiscountHandlers($discountList)
Определения discount.php:1828
static PrepareCurrency4Where($val, $key, $operation, $negative, $field, $arField, $arFilter)
Определения discount.php:643
static __SetOldFields($strAction, &$arFields)
Определения discount.php:1658
static $usedModules
Определения discount.php:23
const PREPARE_ACTIONS
Определения discount.php:20
const VERSION_OLD
Определения discount.php:12
static __ConvertOldFormat($strAction, &$arFields)
Определения discount.php:1389
static CheckFields($ACTION, &$arFields)
Определения discount.php:720
static updateDiscountHandlers($discountID, $handlers, $update)
Определения discount.php:1819
const VERSION_15
Определения discount.php:14
static __ApplyActions(&$arOrder, $strActions)
Определения discount.php:1378
static __Unpack($arOrder, $strUnpack)
Определения discount.php:1365
const PREPARE_CONDITIONS
Определения discount.php:19
const OLD_DSC_TYPE_FIX
Определения discount.php:17
static Update($ID, $arFields)
Определения discount.php:1214
static getDiscountResult(&$oldOrder, &$currentOrder, $extMode=false)
Определения discount.php:1286
Определения sale_act.php:1550
static isSetItem($arItem)
Определения basket_helper.php:26
Определения sale_cond.php:2749
static GetList($arOrder=array(), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения discount.php:15
static GetLangCurrency($siteId)
Определения settings.php:52
Определения user.php:6037
$moduleID
Определения options.php:7
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$rsSites
Определения options.php:477
$result
Определения get_property_values.php:14
if($ajaxMode) $ID
Определения get_user.php:27
$entity
$selectFields
Определения iblock_catalog_list.php:160
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
$ACTION
Определения csv_new_setup.php:27
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$arOptions
Определения structure.php:223
CheckSerializedData($str, $max_depth=200)
Определения tools.php:4949
roundEx($value, $prec=0)
Определения tools.php:4635
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
is_set($a, $k=false)
Определения tools.php:2133
$order
Определения payment.php:8
$publicMode
Определения product_settings.php:144
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
const ADMIN_SECTION
Определения rss.php:2
$discount
Определения waybill.php:788
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$currency
Определения template.php:266
const SALE_VALUE_PRECISION
Определения include.php:46
$val
Определения options.php:1793
const SITE_ID
Определения sonet_set_content_view.php:12
$error
Определения subscription_card_product.php:20
$arFilter
Определения user_search.php:106
$iterator
Определения yandex_run.php:610
$site
Определения yandex_run.php:614
$fields
Определения yandex_run.php:501