1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sale_cond.php
См. документацию.
1<?
8
9if (!Loader::includeModule('catalog'))
10 return;
11
12Loc::loadMessages(__FILE__);
13
15{
16 public static function ClearBasket($row)
17 {
18 return (
19 (!isset($row['IN_SET']) || $row['IN_SET'] != 'Y') &&
20 (
21 (isset($row['TYPE']) && (int)$row['TYPE'] == CSaleBasket::TYPE_SET) ||
22 (!isset($row['SET_PARENT_ID']) || (int)$row['SET_PARENT_ID'] <= 0)
23 )
24 );
25 }
26
27 public static function AmountFilter(&$arOrder, $func)
28 {
29 $dblSumm = 0.0;
30 if (!empty($arOrder['BASKET_ITEMS']) && is_array($arOrder['BASKET_ITEMS']))
31 {
32 reset($arOrder['BASKET_ITEMS']);
33 $arRes = (is_callable($func) ? array_filter($arOrder['BASKET_ITEMS'], $func) : $arOrder['BASKET_ITEMS']);
34 if (!empty($arRes))
35 {
36 $arClear = array_filter($arRes, '\CSaleBasketFilter::ClearBasket');
37 if (!empty($arClear))
38 {
39 foreach ($arClear as $arRow)
40 $dblSumm += (float)$arRow['PRICE']*(float)$arRow['QUANTITY'];
41 unset($arRow);
42 }
43 unset($arClear);
44 }
45 unset($arRes);
46 }
47 return $dblSumm;
48 }
49
50 public static function AmountBaseFilter(&$order, $func)
51 {
52 $summ = 0.0;
53 if (!empty($order['BASKET_ITEMS']) && is_array($order['BASKET_ITEMS']))
54 {
55 reset($order['BASKET_ITEMS']);
56 $basket = (is_callable($func) ? array_filter($order['BASKET_ITEMS'], $func) : $order['BASKET_ITEMS']);
57 if (!empty($basket))
58 {
59 $clearBasket = array_filter($basket, '\CSaleBasketFilter::ClearBasket');
60 if (!empty($clearBasket))
61 {
62 foreach ($clearBasket as $row)
63 $summ += (float)$row['BASE_PRICE']*(float)$row['QUANTITY'];
64 unset($arRow);
65 }
66 unset($clearBasket);
67 }
68 unset($basket);
69 }
70 return $summ;
71 }
72
73 public static function CountFilter(&$arOrder, $func)
74 {
75 $dblQuantity = 0.0;
76 if (!empty($arOrder['BASKET_ITEMS']) && is_array($arOrder['BASKET_ITEMS']))
77 {
78 reset($arOrder['BASKET_ITEMS']);
79 $arRes = (is_callable($func) ? array_filter($arOrder['BASKET_ITEMS'], $func) : $arOrder['BASKET_ITEMS']);
80 if (!empty($arRes))
81 {
82 $arClear = array_filter($arRes, '\CSaleBasketFilter::ClearBasket');
83 if (!empty($arClear))
84 {
85 foreach ($arClear as $arRow)
86 {
87 $dblQuantity += (float)$arRow['QUANTITY'];
88 }
89 unset($arRow);
90 }
91 unset($arClear);
92 }
93 unset($arRes);
94 }
95 return $dblQuantity;
96 }
97
98 public static function RowFilter(&$arOrder, $func)
99 {
100 $intCount = 0;
101 if (!empty($arOrder['BASKET_ITEMS']) && is_array($arOrder['BASKET_ITEMS']))
102 {
103 reset($arOrder['BASKET_ITEMS']);
104 $arRes = (is_callable($func) ? array_filter($arOrder['BASKET_ITEMS'], $func) : $arOrder['BASKET_ITEMS']);
105 if (!empty($arRes))
106 {
107 $arClear = array_filter($arRes, '\CSaleBasketFilter::ClearBasket');
108 $intCount = count($arClear);
109 unset($arClear);
110 }
111 unset($arRes);
112 }
113 return $intCount;
114 }
115
116 public static function ProductFilter(&$arOrder, $func)
117 {
118 $boolFound = false;
119 if (!empty($arOrder['BASKET_ITEMS']) && is_array($arOrder['BASKET_ITEMS']))
120 {
121 reset($arOrder['BASKET_ITEMS']);
122 $arRes = (is_callable($func) ? array_filter($arOrder['BASKET_ITEMS'], $func) : $arOrder['BASKET_ITEMS']);
123 if (!empty($arRes))
124 {
125 $arClear = array_filter($arRes, '\CSaleBasketFilter::ClearBasket');
126 if (!empty($arClear))
127 $boolFound = true;
128 unset($arClear);
129 }
130 unset($arRes);
131 }
132 return $boolFound;
133 }
134
135 public static function BasketPropertyFilter($basketItem, $parameters)
136 {
137 $result = false;
138 if (empty($basketItem['PROPERTIES']))
139 return $result;
140
141 $entity = '';
142 if (isset($parameters['ENTITY_ID']))
143 $entity = $parameters['ENTITY_ID'];
144 if ($entity == '')
145 return $result;
146
147 foreach ($basketItem['PROPERTIES'] as $row)
148 {
149 if ($row[$entity] != $parameters['ENTITY_VALUE'])
150 continue;
151
152 switch ($parameters['LOGIC'])
153 {
154 case BT_COND_LOGIC_EQ:
155 if ($row['VALUE'] === $parameters['VALUE'])
156 $result = true;
157 break;
159 if ($row['VALUE'] !== $parameters['VALUE'])
160 $result = true;
161 break;
163 if (mb_strpos($row['VALUE'], $parameters['VALUE']) !== false)
164 $result = true;
165 break;
167 if (mb_strpos($row['VALUE'], $parameters['VALUE']) === false)
168 $result = true;
169 break;
170 }
171 }
172 unset($row, $entity);
173
174 return $result;
175 }
176}
177
179{
180}
181
185
187{
188 public static function GetControlDescr()
189 {
190 $description = parent::GetControlDescr();
191 $description['SORT'] = 100;
192 return $description;
193 }
194
195 public static function GetShowIn($arControls)
196 {
197 return array(static::GetControlID());
198 }
199}
200
202{
203 public static function GetControlID()
204 {
205 return array(
206 'CondBsktSubGroup',
207 'CondBsktCntGroup',
208 'CondCumulativeGroup',
209 'CondBsktAmtGroup',
210 'CondBsktAmtBaseGroup',
211 'CondBsktProductGroup',
212 'CondBsktRowGroup'
213 );
214 }
215
216 public static function GetControlDescr()
217 {
218 $className = get_called_class();
219 $controls = static::GetControlID();
220 if (empty($controls) || !is_array($controls))
221 return false;
222 $result = array();
223 $sort = 200;
224 foreach ($controls as $controlId)
225 {
226 $row = array(
227 'ID' => $controlId,
228 'GROUP' => 'Y',
229 'GetControlShow' => array($className, 'GetControlShow'),
230 'GetConditionShow' => array($className, 'GetConditionShow'),
231 'IsGroup' => array($className, 'IsGroup'),
232 'Parse' => array($className, 'Parse'),
233 'Generate' => array($className, 'Generate'),
234 'ApplyValues' => array($className, 'ApplyValues'),
235 'InitParams' => array($className, 'InitParams'),
236 'SORT' => $sort,
237 );
238 if ($controlId !== 'CondBsktSubGroup' && $controlId !== 'CondBsktProductGroup')
239 {
240 $row['EXECUTE_MODULE'] = 'sale';
241 }
242 if ($controlId === 'CondCumulativeGroup')
243 {
244 $row['FORCED_SHOW_LIST'] = array('Period', 'PeriodRelative');
245 }
246 $result[] = $row;
247 $sort++;
248 }
249 unset($row, $controlId, $sort, $controls, $className);
250 return $result;
251 }
252
253 public static function GetControlShow($arParams)
254 {
255 $result = array();
256
257 $controls = static::GetControls();
258 if (empty($controls) || !is_array($controls))
259 return false;
260 foreach ($controls as &$oneControl)
261 {
262 $row = array(
263 'controlId' => $oneControl['ID'],
264 'group' => true,
265 'label' => $oneControl['LABEL'],
266 'showIn' => $oneControl['SHOW_IN'],
267 'visual' => $oneControl['VISUAL'],
268 'control' => array()
269 );
270 if (isset($oneControl['PREFIX']))
271 $row['control'][] = $oneControl['PREFIX'];
272 switch ($oneControl['ID'])
273 {
274 case 'CondBsktCntGroup':
275 case 'CondBsktAmtGroup':
276 case 'CondBsktAmtBaseGroup':
277 case 'CondBsktRowGroup':
278 $row['control'][] = $oneControl['ATOMS']['All'];
279 $row['control'][] = $oneControl['ATOMS']['Logic'];
280 $row['control'][] = $oneControl['ATOMS']['Value'];
281 break;
282 case 'CondBsktProductGroup':
283 $row['control'][] = $oneControl['ATOMS']['Found'];
284 $row['control'][] = Loc::getMessage('BT_SALE_COND_GROUP_PRODUCT_DESCR');
285 $row['control'][] = $oneControl['ATOMS']['All'];
286 break;
287 default:
288 $oneControl['ATOMS'] = array_values($oneControl['ATOMS']);
289 $row['control'] = (empty($row['control']) ? $oneControl['ATOMS'] : array_merge($row['control'], $oneControl['ATOMS']));
290 break;
291 }
292 if ($oneControl['ID'] == 'CondBsktAmtGroup' || $oneControl['ID'] == 'CondBsktAmtBaseGroup' || $oneControl['ID'] == 'CondCumulativeGroup')
293 {
294 if (static::$boolInit)
295 {
296 $currency = '';
297 if (isset(static::$arInitParams['CURRENCY']))
298 $currency = static::$arInitParams['CURRENCY'];
299 elseif (isset(static::$arInitParams['SITE_ID']))
300 $currency = Sale\Internals\SiteCurrencyTable::getSiteCurrency(static::$arInitParams['SITE_ID']);
301 if (!empty($currency))
302 {
303 if ($oneControl['ID'] == 'CondCumulativeGroup')
304 {
305 $row['containsOneAction'] = true;
306 }
307 $row['control'][] = $currency;
308 }
309 unset($currency);
310 }
311 }
312 if (!empty($row['control']))
313 $result[] = $row;
314 unset($row);
315 }
316 unset($oneControl);
317
318 return $result;
319 }
320
321 public static function GetConditionShow($arParams)
322 {
323 if (!isset($arParams['ID']))
324 return false;
325 $arControl = static::GetControls($arParams['ID']);
326 if ($arControl === false)
327 return false;
328 $arControl['ATOMS'] = static::GetAtomsEx($arControl['ID'], true);
329
330 return static::CheckAtoms($arParams['DATA'], $arParams, $arControl, true);
331 }
332
333 public static function Parse($arOneCondition)
334 {
335 if (!isset($arOneCondition['controlId']))
336 return false;
337 $arControl = static::GetControls($arOneCondition['controlId']);
338 if ($arControl === false)
339 return false;
340 $arControl['ATOMS'] = static::GetAtomsEx($arControl['ID'], true);
341
342 return static::CheckAtoms($arOneCondition, $arOneCondition, $arControl, false);
343 }
344
345 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
346 {
347 $mxResult = '';
348
349 if (is_string($arControl))
350 $arControl = static::GetControls($arControl);
351
352 $boolError = !is_array($arControl);
353
354 if (!isset($arSubs) || !is_array($arSubs))
355 $boolError = true;
356
357 $arValues = array();
358 if (!$boolError)
359 {
360 $arControl['ATOMS'] = static::GetAtomsEx($arControl['ID'], true);
361 $arParams['COND_NUM'] = $arParams['FUNC_ID'];
362 $arValues = static::CheckAtoms($arOneCondition, $arParams, $arControl, true);
363 $boolError = ($arValues === false);
364 }
365
366 if (!$boolError)
367 {
368 switch($arControl['ID'])
369 {
370 case 'CondBsktCntGroup':
371 $mxResult = self::__GetCntGroupCond($arOneCondition, $arValues['values'], $arParams, $arControl, $arSubs);
372 break;
373 case 'CondBsktAmtGroup':
374 $mxResult = self::__GetAmtGroupCond($arOneCondition, $arValues['values'], $arParams, $arControl, $arSubs);
375 break;
376 case 'CondBsktAmtBaseGroup':
377 $mxResult = self::__GetAmtBaseGroupCond($arOneCondition, $arValues['values'], $arParams, $arControl, $arSubs);
378 break;
379 case 'CondBsktProductGroup':
380 $mxResult = self::__GetProductGroupCond($arOneCondition, $arValues['values'], $arParams, $arControl, $arSubs);
381 break;
382 case 'CondBsktRowGroup':
383 $mxResult = self::__GetRowGroupCond($arOneCondition, $arValues['values'], $arParams, $arControl, $arSubs);
384 break;
385 case 'CondBsktSubGroup':
386 $mxResult = self::__GetSubGroupCond($arOneCondition, $arValues['values'], $arParams, $arControl, $arSubs);
387 break;
388 case 'CondCumulativeGroup':
389 $mxResult = self::getCodeForCumulativeGroupCondition($arOneCondition, $arValues['values'], $arParams, $arControl, $arSubs);
390 break;
391 }
392 }
393
394 return (!$boolError ? $mxResult : false);
395 }
396
397 public static function GetAtomsEx($strControlID = false, $boolEx = false)
398 {
399 $boolEx = ($boolEx === true);
400 $arAmtLabels = array(
401 BT_COND_LOGIC_EQ => Loc::getMessage('BT_SALE_AMOUNT_LOGIC_EQ_LABEL'),
402 BT_COND_LOGIC_NOT_EQ => Loc::getMessage('BT_SALE_AMOUNT_LOGIC_NOT_EQ_LABEL'),
403 BT_COND_LOGIC_GR => Loc::getMessage('BT_SALE_AMOUNT_LOGIC_GR_LABEL'),
404 BT_COND_LOGIC_LS => Loc::getMessage('BT_SALE_AMOUNT_LOGIC_LS_LABEL'),
405 BT_COND_LOGIC_EGR => Loc::getMessage('BT_SALE_AMOUNT_LOGIC_EGR_LABEL'),
406 BT_COND_LOGIC_ELS => Loc::getMessage('BT_SALE_AMOUNT_LOGIC_ELS_LABEL')
407 );
408
409 $arAtomList = array(
410 'CondBsktCntGroup' => array(
411 'Logic' => array(
412 'JS' => static::GetLogicAtom(
413 static::GetLogic(
414 array(
421 )
422 )
423 ),
424 'ATOM' => array(
425 'ID' => 'logic',
426 'FIELD_TYPE' => 'string',
427 'FIELD_LENGTH' => 255,
428 'MULTIPLE' => 'N',
429 'VALIDATE' => 'list'
430 )
431 ),
432 'Value' => array(
433 'JS' => array(
434 'id' => 'Value',
435 'name' => 'value',
436 'type' => 'input'
437 ),
438 'ATOM' => array(
439 'ID' => 'Value',
440 'FIELD_TYPE' => 'double',
441 'MULTIPLE' => 'N',
442 'VALIDATE' => ''
443 )
444 ),
445 'All' => array(
446 'JS' => array(
447 'id' => 'All',
448 'name' => 'aggregator',
449 'type' => 'select',
450 'values' => array(
451 'AND' => Loc::getMessage('BT_SALE_COND_GROUP_SELECT_ALL'),
452 'OR' => Loc::getMessage('BT_SALE_COND_GROUP_SELECT_ANY')
453 ),
454 'defaultText' => Loc::getMessage('BT_SALE_COND_GROUP_BASKET_NUMBER_GROUP_SELECT_DEF'),
455 'defaultValue' => 'AND',
456 'first_option' => '...'
457 ),
458 'ATOM' => array(
459 'ID' => 'All',
460 'FIELD_TYPE' => 'string',
461 'FIELD_LENGTH' => 255,
462 'MULTIPLE' => 'N',
463 'VALIDATE' => 'list'
464 )
465 )
466 ),
467 'CondCumulativeGroup' => array(
468 'Logic' => array(
469 'JS' => static::GetLogicAtom(
470 static::GetLogic(
471 array(
478 )
479 )
480 ),
481 'ATOM' => array(
482 'ID' => 'logic',
483 'FIELD_TYPE' => 'string',
484 'FIELD_LENGTH' => 255,
485 'MULTIPLE' => 'N',
486 'VALIDATE' => 'list'
487 )
488 ),
489 'Value' => array(
490 'JS' => array(
491 'id' => 'Value',
492 'name' => 'value',
493 'type' => 'input'
494 ),
495 'ATOM' => array(
496 'ID' => 'Value',
497 'FIELD_TYPE' => 'double',
498 'MULTIPLE' => 'N',
499 'VALIDATE' => ''
500 )
501 ),
502 ),
503 'CondBsktAmtGroup' => array(
504 'Logic' => array(
505 'JS' => static::GetLogicAtom(
506 static::GetLogicEx(
507 array_keys($arAmtLabels), $arAmtLabels
508 )
509 ),
510 'ATOM' => array(
511 'ID' => 'logic',
512 'FIELD_TYPE' => 'string',
513 'FIELD_LENGTH' => 255,
514 'MULTIPLE' => 'N',
515 'VALIDATE' => 'list'
516 )
517 ),
518 'Value' => array(
519 'JS' => array(
520 'id' => 'Value',
521 'name' => 'value',
522 'type' => 'input'
523 ),
524 'ATOM' => array(
525 'ID' => 'Value',
526 'FIELD_TYPE' => 'double',
527 'MULTIPLE' => 'N',
528 'VALIDATE' => ''
529 )
530 ),
531 'All' => array(
532 'JS' => array(
533 'id' => 'All',
534 'name' => 'aggregator',
535 'type' => 'select',
536 'values' => array(
537 'AND' => Loc::getMessage('BT_SALE_COND_GROUP_SELECT_ALL'),
538 'OR' => Loc::getMessage('BT_SALE_COND_GROUP_SELECT_ANY')
539 ),
540 'defaultText' => Loc::getMessage('BT_SALE_COND_BASKET_AMOUNT_GROUP_SELECT_DEF'),
541 'defaultValue' => 'AND',
542 'first_option' => '...'
543 ),
544 'ATOM' => array(
545 'ID' => 'All',
546 'FIELD_TYPE' => 'string',
547 'FIELD_LENGTH' => 255,
548 'MULTIPLE' => 'N',
549 'VALIDATE' => 'list'
550 )
551 )
552 ),
553 'CondBsktAmtBaseGroup' => array(
554 'Logic' => array(
555 'JS' => static::GetLogicAtom(
556 static::GetLogicEx(
557 array_keys($arAmtLabels), $arAmtLabels
558 )
559 ),
560 'ATOM' => array(
561 'ID' => 'logic',
562 'FIELD_TYPE' => 'string',
563 'FIELD_LENGTH' => 255,
564 'MULTIPLE' => 'N',
565 'VALIDATE' => 'list'
566 )
567 ),
568 'Value' => array(
569 'JS' => array(
570 'id' => 'Value',
571 'name' => 'value',
572 'type' => 'input'
573 ),
574 'ATOM' => array(
575 'ID' => 'Value',
576 'FIELD_TYPE' => 'double',
577 'MULTIPLE' => 'N',
578 'VALIDATE' => ''
579 )
580 ),
581 'All' => array(
582 'JS' => array(
583 'id' => 'All',
584 'name' => 'aggregator',
585 'type' => 'select',
586 'values' => array(
587 'AND' => Loc::getMessage('BT_SALE_COND_GROUP_SELECT_ALL'),
588 'OR' => Loc::getMessage('BT_SALE_COND_GROUP_SELECT_ANY')
589 ),
590 'defaultText' => Loc::getMessage('BT_SALE_COND_BASKET_AMOUNT_GROUP_SELECT_DEF'),
591 'defaultValue' => 'AND',
592 'first_option' => '...'
593 ),
594 'ATOM' => array(
595 'ID' => 'All',
596 'FIELD_TYPE' => 'string',
597 'FIELD_LENGTH' => 255,
598 'MULTIPLE' => 'N',
599 'VALIDATE' => 'list'
600 )
601 )
602 ),
603 'CondBsktProductGroup' => array(
604 'Found' => array(
605 'JS' => array(
606 'id' => 'Found',
607 'name' => 'search',
608 'type' => 'select',
609 'values' => array(
610 'Found' => Loc::getMessage('BT_SALE_COND_PRODUCT_GROUP_SELECT_FOUND'),
611 'NoFound' => Loc::getMessage('BT_SALE_COND_PRODUCT_GROUP_SELECT_NO_FOUND')
612 ),
613 'defaultText' => Loc::getMessage('BT_SALE_COND_PRODUCT_GROUP_SELECT_DEF'),
614 'defaultValue' => 'Found',
615 'first_option' => '...'
616 ),
617 'ATOM' => array(
618 'ID' => 'Found',
619 'FIELD_TYPE' => 'string',
620 'FIELD_LENGTH' => 255,
621 'MULTIPLE' => 'N',
622 'VALIDATE' => 'list'
623 )
624 ),
625 'All' => array(
626 'JS' => array(
627 'id' => 'All',
628 'name' => 'aggregator',
629 'type' => 'select',
630 'values' => array(
631 'AND' => Loc::getMessage('BT_SALE_COND_GROUP_SELECT_ALL'),
632 'OR' => Loc::getMessage('BT_SALE_COND_GROUP_SELECT_ANY')
633 ),
634 'defaultText' => Loc::getMessage('BT_SALE_COND_PRODUCT_GROUP_SELECT_DEF'),
635 'defaultValue' => 'AND',
636 'first_option' => '...'
637 ),
638 'ATOM' => array(
639 'ID' => 'All',
640 'FIELD_TYPE' => 'string',
641 'FIELD_LENGTH' => 255,
642 'MULTIPLE' => 'N',
643 'VALIDATE' => 'list'
644 )
645 )
646 ),
647 'CondBsktRowGroup' => array(
648 'Logic' => array(
649 'JS' => static::GetLogicAtom(
650 static::GetLogic(
651 array(
658 )
659 )
660 ),
661 'ATOM' => array(
662 'ID' => 'logic',
663 'FIELD_TYPE' => 'string',
664 'FIELD_LENGTH' => 255,
665 'MULTIPLE' => 'N',
666 'VALIDATE' => 'list'
667 )
668 ),
669 'Value' => array(
670 'JS' => array(
671 'id' => 'Value',
672 'name' => 'value',
673 'type' => 'input'
674 ),
675 'ATOM' => array(
676 'ID' => 'Value',
677 'FIELD_TYPE' => 'int',
678 'MULTIPLE' => 'N',
679 'VALIDATE' => ''
680 )
681 ),
682 'All' => array(
683 'JS' => array(
684 'id' => 'All',
685 'name' => 'aggregator',
686 'type' => 'select',
687 'values' => array(
688 'AND' => Loc::getMessage('BT_SALE_COND_GROUP_SELECT_ALL'),
689 'OR' => Loc::getMessage('BT_SALE_COND_GROUP_SELECT_ANY')
690 ),
691 'defaultText' => Loc::getMessage('BT_SALE_COND_GROUP_BASKET_ROW_GROUP_SELECT_DEF'),
692 'defaultValue' => 'AND',
693 'first_option' => '...'
694 ),
695 'ATOM' => array(
696 'ID' => 'All',
697 'FIELD_TYPE' => 'string',
698 'FIELD_LENGTH' => 255,
699 'MULTIPLE' => 'N',
700 'VALIDATE' => 'list'
701 )
702 )
703 ),
704 'CondBsktSubGroup' => array(
705 'All' => array(
706 'JS' => array(
707 'id' => 'All',
708 'name' => 'aggregator',
709 'type' => 'select',
710 'values' => array(
711 'AND' => Loc::getMessage('BT_CLOBAL_COND_GROUP_SELECT_ALL'),
712 'OR' => Loc::getMessage('BT_CLOBAL_COND_GROUP_SELECT_ANY')
713 ),
714 'defaultText' => Loc::getMessage('BT_CLOBAL_COND_GROUP_SELECT_DEF'),
715 'defaultValue' => 'AND',
716 'first_option' => '...'
717 ),
718 'ATOM' => array(
719 'ID' => 'All',
720 'FIELD_TYPE' => 'string',
721 'FIELD_LENGTH' => 255,
722 'MULTIPLE' => 'N',
723 'VALIDATE' => 'list'
724 )
725 ),
726 'True' => array(
727 'JS' => array(
728 'id' => 'True',
729 'name' => 'value',
730 'type' => 'select',
731 'values' => array(
732 'True' => Loc::getMessage('BT_CLOBAL_COND_GROUP_SELECT_TRUE'),
733 'False' => Loc::getMessage('BT_CLOBAL_COND_GROUP_SELECT_FALSE')
734 ),
735 'defaultText' => Loc::getMessage('BT_CLOBAL_COND_GROUP_SELECT_DEF'),
736 'defaultValue' => 'True',
737 'first_option' => '...'
738 ),
739 'ATOM' => array(
740 'ID' => 'True',
741 'FIELD_TYPE' => 'string',
742 'FIELD_LENGTH' => 255,
743 'MULTIPLE' => 'N',
744 'VALIDATE' => 'list'
745 )
746 )
747 )
748 );
749
750 if (!$boolEx)
751 {
752 foreach ($arAtomList as &$arOneControl)
753 {
754 foreach ($arOneControl as &$arOneAtom)
755 $arOneAtom = $arOneAtom['JS'];
756 unset($arOneAtom);
757 }
758 unset($arOneControl);
759 }
760
761 if ($strControlID === false)
762 return $arAtomList;
763 elseif (isset($arAtomList[$strControlID]))
764 return $arAtomList[$strControlID];
765 else
766 return false;
767 }
768
773 public static function GetControls($strControlID = false)
774 {
775 $arAtoms = static::GetAtomsEx();
776 $arControlList = array(
777 'CondCumulativeGroup' => array(
778 'ID' => 'CondCumulativeGroup',
779 'LABEL' => Loc::getMessage('BT_SALE_COND_GROUP_CUMULATIVE_LABEL'),
780 'PREFIX' => Loc::getMessage('BT_SALE_COND_GROUP_CUMULATIVE_PREFIX'),
781 'SHOW_IN' => array(parent::GetControlID()),
782 'VISUAL' => self::__GetVisual(),
783 'ATOMS' => $arAtoms['CondCumulativeGroup']
784 ),
785 'CondBsktCntGroup' => array(
786 'ID' => 'CondBsktCntGroup',
787 'LABEL' => Loc::getMessage('BT_SALE_COND_GROUP_BASKET_NUMBER_LABEL'),
788 'PREFIX' => Loc::getMessage('BT_SALE_COND_GROUP_BASKET_NUMBER_PREFIX'),
789 'SHOW_IN' => array(parent::GetControlID()),
790 'VISUAL' => self::__GetVisual(),
791 'ATOMS' => $arAtoms['CondBsktCntGroup']
792 ),
793 'CondBsktAmtGroup' => array(
794 'ID' => 'CondBsktAmtGroup',
795 'LABEL' => Loc::getMessage('BT_SALE_COND_GROUP_BASKET_AMOUNT_LABEL'),
796 'PREFIX' => Loc::getMessage('BT_SALE_COND_GROUP_BASKET_AMOUNT_PREFIX'),
797 'SHOW_IN' => array(parent::GetControlID()),
798 'VISUAL' => self::__GetVisual(),
799 'ATOMS' => $arAtoms['CondBsktAmtGroup']
800 ),
801 'CondBsktAmtBaseGroup' => array(
802 'ID' => 'CondBsktAmtBaseGroup',
803 'LABEL' => Loc::getMessage('BT_SALE_COND_GROUP_BASKET_AMOUNT_BASE_LABEL'),
804 'PREFIX' => Loc::getMessage('BT_SALE_COND_GROUP_BASKET_AMOUNT_BASE_PREFIX'),
805 'SHOW_IN' => array(parent::GetControlID()),
806 'VISUAL' => self::__GetVisual(),
807 'ATOMS' => $arAtoms['CondBsktAmtBaseGroup']
808 ),
809 'CondBsktProductGroup' => array(
810 'ID' => 'CondBsktProductGroup',
811 'LABEL' => Loc::getMessage('BT_SALE_COND_GROUP_BASKET_PRODUCT_LABEL'),
812 'PREFIX' => Loc::getMessage('BT_SALE_COND_GROUP_PRODUCT_PREFIX'),
813 'SHOW_IN' => array(parent::GetControlID()),
814 'VISUAL' => self::__GetVisual(),
815 'ATOMS' => $arAtoms['CondBsktProductGroup']
816 ),
817 'CondBsktRowGroup' => array(
818 'ID' => 'CondBsktRowGroup',
819 'LABEL' => Loc::getMessage('BT_SALE_COND_GROUP_BASKET_ROW_LABEL'),
820 'PREFIX' => Loc::getMessage('BT_SALE_COND_GROUP_BASKET_ROW_PREFIX'),
821 'SHOW_IN' => array(parent::GetControlID()),
822 'VISUAL' => self::__GetVisual(),
823 'ATOMS' => $arAtoms['CondBsktRowGroup']
824 ),
825 'CondBsktSubGroup' => array(
826 'ID' => 'CondBsktSubGroup',
827 'LABEL' => Loc::getMessage('BT_SALE_COND_GROUP_BASKET_SUB_LABEL'),
828 'SHOW_IN' => array_diff(self::GetControlID(), array('CondCumulativeGroup')),
829 'VISUAL' => self::__GetVisual(true),
830 'ATOMS' => $arAtoms['CondBsktSubGroup']
831 )
832 );
833
834 foreach ($arControlList as &$control)
835 {
836 $control['MODULE_ID'] = 'sale';
837 $control['MODULE_ENTITY'] = 'sale';
838 $control['ENTITY'] = 'BASKET';
839 $control['GROUP'] = 'Y';
840 }
841 unset($control);
842
843 return static::searchControl($arControlList, $strControlID);
844 }
845
846 private static function __GetVisual($boolExt = false)
847 {
848 $boolExt = ($boolExt === true);
849 if ($boolExt)
850 {
852 'controls' => array(
853 'All',
854 'True'
855 ),
856 'values' => array(
857 array(
858 'All' => 'AND',
859 'True' => 'True'
860 ),
861 array(
862 'All' => 'AND',
863 'True' => 'False'
864 ),
865 array(
866 'All' => 'OR',
867 'True' => 'True'
868 ),
869 array(
870 'All' => 'OR',
871 'True' => 'False'
872 )
873 ),
874 'logic' => array(
875 array(
876 'style' => 'condition-logic-and',
877 'message' => Loc::getMessage('BT_SALE_COND_GROUP_LOGIC_AND')
878 ),
879 array(
880 'style' => 'condition-logic-and',
881 'message' => Loc::getMessage('BT_SALE_COND_GROUP_LOGIC_NOT_AND')
882 ),
883 array(
884 'style' => 'condition-logic-or',
885 'message' => Loc::getMessage('BT_SALE_COND_GROUP_LOGIC_OR')
886 ),
887 array(
888 'style' => 'condition-logic-or',
889 'message' => Loc::getMessage('BT_SALE_COND_GROUP_LOGIC_NOT_OR')
890 )
891 )
892 );
893 }
894 else
895 {
897 'controls' => array(
898 'All'
899 ),
900 'values' => array(
901 array(
902 'All' => 'AND'
903 ),
904 array(
905 'All' => 'OR'
906 ),
907 ),
908 'logic' => array(
909 array(
910 'style' => 'condition-logic-and',
911 'message' => Loc::getMessage('BT_SALE_COND_GROUP_LOGIC_AND')
912 ),
913 array(
914 'style' => 'condition-logic-or',
915 'message' => Loc::getMessage('BT_SALE_COND_GROUP_LOGIC_OR')
916 )
917 )
918 );
919 }
920 return $arResult;
921 }
922
923 private static function getCodeForCumulativeGroupCondition($oneCondition, $values, $params, $control, $subs)
924 {
925 $dataSumConfiguration = 'array()';
926 if ($subs && $subs[0])
927 {
928 $dataSumConfiguration = $subs[0];
929 }
930
931 $logic = static::SearchLogic(
932 $values['logic'],
933 static::GetLogic(
934 array(
941 )
942 )
943 );
944
945 if (!isset($logic['OP']['N']) || empty($logic['OP']['N']))
946 {
947 return '';
948 }
949
951 return str_replace(
952 array('#FIELD#', '#VALUE#'),
953 array("\CSaleCondCumulativeCtrl::getCumulativeValue({$params['ORDER']}, {$dataSumConfiguration}) ", $values['Value']),
954 $logic['OP']['N']
955 );
956 }
957
958 private static function __GetSubGroupCond($arOneCondition, $arValues, $arParams, $arControl, $arSubs)
959 {
960 $mxResult = '';
961 $boolError = false;
962
963 if (empty($arSubs))
964 return '(1 == 1)';
965
966 if (!$boolError)
967 {
968 $strPrefix = '';
969 $strLogic = '';
970 $strItemPrefix = '';
971
972 if ('AND' == $arOneCondition['All'])
973 {
974 $strLogic = ' && ';
975 $strItemPrefix = ('True' == $arOneCondition['True'] ? '' : '!');
976 }
977 else
978 {
979 if ('True' == $arOneCondition['True'])
980 {
981 $strPrefix = '';
982 $strLogic = ' || ';
983 }
984 else
985 {
986 $strPrefix = '!';
987 $strLogic = ' && ';
988 }
989 }
990
991 $strEval = $strItemPrefix.implode($strLogic.$strItemPrefix, $arSubs);
992 if ('' != $strPrefix)
993 $strEval = $strPrefix.'('.$strEval.')';
994 $mxResult = $strEval;
995 }
996
997 return $mxResult;
998 }
999
1000 private static function __GetRowGroupCond($arOneCondition, $arValues, $arParams, $arControl, $arSubs)
1001 {
1002 $boolError = false;
1003 $strFunc = '';
1004 $strCond = '';
1005
1006 $arLogic = static::SearchLogic(
1007 $arValues['logic'],
1008 static::GetLogic(
1009 array(
1016 )
1017 )
1018 );
1019
1020 if (!isset($arLogic['OP']['N']) || empty($arLogic['OP']['N']))
1021 {
1022 $boolError = true;
1023 }
1024 else
1025 {
1026 if (!empty($arSubs))
1027 {
1028 $strFuncName = '$salecond'.$arParams['FUNC_ID'];
1029
1030 $strLogic = ('AND' == $arValues['All'] ? '&&' : '||');
1031
1032 $strFunc = $strFuncName.'=function($row){';
1033 $strFunc .= 'return ('.implode(') '.$strLogic.' (', $arSubs).');';
1034 $strFunc .= '};';
1035
1036 $strCond = str_replace(
1037 array('#FIELD#', '#VALUE#'),
1038 array('CSaleBasketFilter::RowFilter('.$arParams['ORDER'].', '.$strFuncName.')', $arValues['Value']),
1039 $arLogic['OP']['N']
1040 );
1041 }
1042 else
1043 {
1044 $strCond = str_replace(
1045 array('#FIELD#', '#VALUE#'),
1046 array('CSaleBasketFilter::RowFilter('.$arParams['ORDER'].', "")', $arValues['Value']),
1047 $arLogic['OP']['N']
1048 );
1049 }
1050 }
1051
1052 if (!$boolError)
1053 {
1054 if (!empty($strFunc))
1055 {
1056 return array(
1057 'FUNC' => $strFunc,
1058 'COND' => $strCond,
1059 );
1060 }
1061 else
1062 {
1063 return $strCond;
1064 }
1065 }
1066 else
1067 {
1068 return '';
1069 }
1070 }
1071
1072 private static function __GetProductGroupCond($arOneCondition, $arValues, $arParams, $arControl, $arSubs)
1073 {
1074 $strFunc = '';
1075
1076 if (!empty($arSubs))
1077 {
1078 $strFuncName = '$salecond'.$arParams['FUNC_ID'];
1079
1080 $strLogic = ('AND' == $arValues['All'] ? '&&' : '||');
1081
1082 $strFunc = $strFuncName.'=function($row){';
1083 $strFunc .= 'return ('.implode(') '.$strLogic.' (', $arSubs).');';
1084 $strFunc .= '};';
1085
1086 $strCond = ('Found' == $arValues['Found'] ? '' : '!').'CSaleBasketFilter::ProductFilter('.$arParams['ORDER'].', '.$strFuncName.')';
1087 }
1088 else
1089 {
1090 $strCond = ('Found' == $arValues['Found'] ? '' : '!').'CSaleBasketFilter::ProductFilter('.$arParams['ORDER'].', "")';
1091 }
1092
1093 if (!empty($strFunc))
1094 {
1095 return array(
1096 'FUNC' => $strFunc,
1097 'COND' => $strCond,
1098 );
1099 }
1100 else
1101 {
1102 return $strCond;
1103 }
1104 }
1105
1106 private static function __GetAmtGroupCond($arOneCondition, $arValues, $arParams, $arControl, $arSubs)
1107 {
1108 $boolError = false;
1109
1110 $strFunc = '';
1111 $strCond = '';
1112
1113 $arLogic = static::SearchLogic(
1114 $arValues['logic'],
1115 static::GetLogic(
1116 array(
1123 )
1124 )
1125 );
1126
1127 if (!isset($arLogic['OP']['N']) || empty($arLogic['OP']['N']))
1128 {
1129 $boolError = true;
1130 }
1131 else
1132 {
1133 if (!empty($arSubs))
1134 {
1135 $strFuncName = '$salecond'.$arParams['FUNC_ID'];
1136
1137 $strLogic = ('AND' == $arValues['All'] ? '&&' : '||');
1138
1139 $strFunc = $strFuncName.'=function($row){';
1140 $strFunc .= 'return ('.implode(') '.$strLogic.' (', $arSubs).');';
1141 $strFunc .= '};';
1142
1143 $strCond = str_replace(
1144 array('#FIELD#', '#VALUE#'),
1145 array('CSaleBasketFilter::AmountFilter('.$arParams['ORDER'].', '.$strFuncName.')',
1146 $arValues['Value']),
1147 $arLogic['OP']['N']
1148 );
1149 }
1150 else
1151 {
1152 $strCond = str_replace(
1153 array('#FIELD#', '#VALUE#'),
1154 array('CSaleBasketFilter::AmountFilter('.$arParams['ORDER'].', "")',
1155 $arValues['Value']),
1156 $arLogic['OP']['N']
1157 );
1158 }
1159 }
1160
1161 if (!$boolError)
1162 {
1163 if (!empty($strFunc))
1164 {
1165 return array(
1166 'FUNC' => $strFunc,
1167 'COND' => $strCond,
1168 );
1169 }
1170 else
1171 {
1172 return $strCond;
1173 }
1174 }
1175 else
1176 {
1177 return '';
1178 }
1179 }
1180
1181 private static function __GetAmtBaseGroupCond($arOneCondition, $arValues, $arParams, $arControl, $arSubs)
1182 {
1183 $boolError = false;
1184
1185 $strFunc = '';
1186 $strCond = '';
1187
1188 $arLogic = static::SearchLogic(
1189 $arValues['logic'],
1190 static::GetLogic(
1191 array(
1198 )
1199 )
1200 );
1201
1202 if (!isset($arLogic['OP']['N']) || empty($arLogic['OP']['N']))
1203 {
1204 $boolError = true;
1205 }
1206 else
1207 {
1208 if (!empty($arSubs))
1209 {
1210 $strFuncName = '$salecond'.$arParams['FUNC_ID'];
1211
1212 $strLogic = ('AND' == $arValues['All'] ? '&&' : '||');
1213
1214 $strFunc = $strFuncName.'=function($row){';
1215 $strFunc .= 'return ('.implode(') '.$strLogic.' (', $arSubs).');';
1216 $strFunc .= '};';
1217
1218 $strCond = str_replace(
1219 array('#FIELD#', '#VALUE#'),
1220 array('CSaleBasketFilter::AmountBaseFilter('.$arParams['ORDER'].', '.$strFuncName.')',
1221 $arValues['Value']),
1222 $arLogic['OP']['N']
1223 );
1224 }
1225 else
1226 {
1227 $strCond = str_replace(
1228 array('#FIELD#', '#VALUE#'),
1229 array('CSaleBasketFilter::AmountBaseFilter('.$arParams['ORDER'].', "")',
1230 $arValues['Value']),
1231 $arLogic['OP']['N']
1232 );
1233 }
1234 }
1235
1236 if (!$boolError)
1237 {
1238 if (!empty($strFunc))
1239 {
1240 return array(
1241 'FUNC' => $strFunc,
1242 'COND' => $strCond,
1243 );
1244 }
1245 else
1246 {
1247 return $strCond;
1248 }
1249 }
1250 else
1251 {
1252 return '';
1253 }
1254 }
1255
1256 private static function __GetCntGroupCond($arOneCondition, $arValues, $arParams, $arControl, $arSubs)
1257 {
1258 $boolError = false;
1259
1260 $strFunc = '';
1261 $strCond = '';
1262
1263 $arLogic = static::SearchLogic(
1264 $arValues['logic'],
1265 static::GetLogic(
1266 array(
1273 )
1274 )
1275 );
1276
1277 if (!isset($arLogic['OP']['N']) || empty($arLogic['OP']['N']))
1278 {
1279 $boolError = true;
1280 }
1281 else
1282 {
1283 if (!empty($arSubs))
1284 {
1285 $strFuncName = '$salecond'.$arParams['FUNC_ID'];
1286
1287 $strLogic = ('AND' == $arValues['All'] ? '&&' : '||');
1288
1289 $strFunc = $strFuncName.'=function($row){';
1290 $strFunc .= 'return ('.implode(') '.$strLogic.' (', $arSubs).');';
1291 $strFunc .= '};';
1292
1293 $strCond = str_replace(
1294 array('#FIELD#', '#VALUE#'),
1295 array('CSaleBasketFilter::CountFilter('.$arParams['ORDER'].', '.$strFuncName.')',
1296 $arValues['Value']),
1297 $arLogic['OP']['N']
1298 );
1299 }
1300 else
1301 {
1302 $strCond = str_replace(
1303 array('#FIELD#', '#VALUE#'),
1304 array('CSaleBasketFilter::CountFilter('.$arParams['ORDER'].', "")',
1305 $arValues['Value']),
1306 $arLogic['OP']['N']
1307 );
1308 }
1309 }
1310
1311 if (!$boolError)
1312 {
1313 if (!empty($strFunc))
1314 {
1315 return array(
1316 'FUNC' => $strFunc,
1317 'COND' => $strCond,
1318 );
1319 }
1320 else
1321 {
1322 return $strCond;
1323 }
1324 }
1325 else
1326 {
1327 return '';
1328 }
1329 }
1330}
1331
1333{
1334 const ENTITY_BASKET_POSITION_WEIGHT = 'BX:CondBsktFldSummWeight';
1335
1336 public static function GetControlDescr()
1337 {
1338 $description = parent::GetControlDescr();
1339 $description['SORT'] = 300;
1340 return $description;
1341 }
1342
1343 public static function GetControlShow($arParams)
1344 {
1345 $arControls = static::GetControls();
1346 $arResult = array(
1347 'controlgroup' => true,
1348 'group' => false,
1349 'label' => Loc::getMessage('BT_MOD_SALE_COND_GROUP_BASKET_FIELDS_LABEL'),
1350 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
1351 'children' => array()
1352 );
1353 foreach ($arControls as $arOneControl)
1354 {
1355 $arOne = array(
1356 'controlId' => $arOneControl['ID'],
1357 'group' => ('Y' == $arOneControl['GROUP']),
1358 'label' => $arOneControl['LABEL'],
1359 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
1360 );
1361 if (
1364 )
1365 {
1366 $arOne['control'] = array();
1367 if (isset($arOneControl['PREFIX']))
1368 $arOne['control'][] = array(
1369 'id' => 'prefix',
1370 'type' => 'prefix',
1371 'text' => $arOneControl['PREFIX']
1372 );
1373 foreach ($arOneControl['ATOMS'] as $atom)
1374 $arOne['control'][] = $atom;
1375 unset($atom);
1376 }
1377 else
1378 {
1379 $arOne['control'] = array(
1380 array(
1381 'id' => 'prefix',
1382 'type' => 'prefix',
1383 'text' => $arOneControl['PREFIX']
1384 ),
1385 static::GetLogicAtom($arOneControl['LOGIC']),
1386 static::GetValueAtom($arOneControl['JS_VALUE'])
1387 );
1388 if ($arOneControl['ID'] == 'CondBsktFldPrice' || $arOneControl['ID'] == 'CondBsktFldSumm')
1389 {
1390 $boolCurrency = false;
1391 if (static::$boolInit)
1392 {
1393 if (isset(static::$arInitParams['CURRENCY']))
1394 {
1395 $arOne['control'][] = static::$arInitParams['CURRENCY'];
1396 $boolCurrency = true;
1397 }
1398 elseif (isset(static::$arInitParams['SITE_ID']))
1399 {
1400 $strCurrency = Sale\Internals\SiteCurrencyTable::getSiteCurrency(static::$arInitParams['SITE_ID']);
1401 if (!empty($strCurrency))
1402 {
1403 $arOne['control'][] = $strCurrency;
1404 $boolCurrency = true;
1405 }
1406 }
1407 }
1408 if (!$boolCurrency)
1409 $arOne = array();
1410 }
1411 elseif ($arOneControl['ID'] == 'CondBsktFldWeight' || $arOneControl['ID'] == self::ENTITY_BASKET_POSITION_WEIGHT)
1412 {
1413 $arOne['control'][] = Loc::getMessage('BT_MOD_SALE_COND_MESS_WEIGHT_UNIT');
1414 }
1415 }
1416 if (!empty($arOne))
1417 $arResult['children'][] = $arOne;
1418 }
1419 unset($arOneControl);
1420
1421 return $arResult;
1422 }
1423
1424 public static function GetConditionShow($arParams)
1425 {
1426 if (!isset($arParams['ID']))
1427 return false;
1429 return \CSaleCondCtrlBasketProperties::GetConditionShow($arParams);
1431 return \CSaleCondCtrlBasketItemConditions::GetConditionShow($arParams);
1432 return parent::GetConditionShow($arParams);
1433 }
1434
1435 public static function Parse($arOneCondition)
1436 {
1437 if (!isset($arOneCondition['controlId']))
1438 return false;
1439 if ($arOneCondition['controlId'] == \CSaleCondCtrlBasketProperties::ENTITY_BASKET_PROPERTY)
1440 return \CSaleCondCtrlBasketProperties::Parse($arOneCondition);
1442 return \CSaleCondCtrlBasketItemConditions::Parse($arOneCondition);
1443 return parent::Parse($arOneCondition);
1444 }
1445
1446 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
1447 {
1448 $strResult = '';
1449
1450 if (is_string($arControl))
1451 $arControl = static::GetControls($arControl);
1452 $boolError = !is_array($arControl);
1453
1454 if (!$boolError)
1455 {
1457 return \CSaleCondCtrlBasketProperties::Generate($arOneCondition, $arParams, $arControl, $arSubs);
1459 return \CSaleCondCtrlBasketItemConditions::Generate($arOneCondition, $arParams, $arControl, $arSubs);
1460 }
1461
1462 $arValues = array();
1463 if (!$boolError)
1464 {
1465 $arValues = static::Check($arOneCondition, $arOneCondition, $arControl, false);
1466 $boolError = ($arValues === false);
1467 }
1468
1469 if (!$boolError)
1470 {
1471 $arLogic = static::SearchLogic($arValues['logic'], $arControl['LOGIC']);
1472 if (!isset($arLogic['OP'][$arControl['MULTIPLE']]) || empty($arLogic['OP'][$arControl['MULTIPLE']]))
1473 {
1474 $boolError = true;
1475 }
1476 else
1477 {
1478 $multyField = is_array($arControl['FIELD']);
1479 if ($multyField)
1480 {
1481 $fieldsList = array();
1482 foreach ($arControl['FIELD'] as &$oneField)
1483 {
1484 $fieldsList[] = $arParams['BASKET_ROW'].'[\''.$oneField.'\']';
1485 }
1486 unset($oneField);
1487 $issetField = implode(') && isset (', $fieldsList);
1488 $valueField = implode('*',$fieldsList);
1489 unset($fieldsList);
1490 }
1491 else
1492 {
1493 $issetField = $arParams['BASKET_ROW'].'[\''.$arControl['FIELD'].'\']';
1494 $valueField = $issetField;
1495 }
1496 switch ($arControl['FIELD_TYPE'])
1497 {
1498 case 'int':
1499 case 'double':
1500 $strResult = str_replace(array('#FIELD#', '#VALUE#'), array($valueField, $arValues['value']), $arLogic['OP'][$arControl['MULTIPLE']]);
1501 break;
1502 case 'char':
1503 case 'string':
1504 case 'text':
1505 $strResult = str_replace(array('#FIELD#', '#VALUE#'), array($valueField, '"'.EscapePHPString($arValues['value']).'"'), $arLogic['OP'][$arControl['MULTIPLE']]);
1506 break;
1507 case 'date':
1508 case 'datetime':
1509 $strResult = str_replace(array('#FIELD#', '#VALUE#'), array($valueField, $arValues['value']), $arLogic['OP'][$arControl['MULTIPLE']]);
1510 break;
1511 }
1512 $strResult = 'isset('.$issetField.') && '.$strResult;
1513 }
1514 }
1515
1516 return (!$boolError ? $strResult : false);
1517 }
1518
1523 public static function GetControls($strControlID = false)
1524 {
1525 $arControlList = array(
1526 'CondBsktFldProduct' => array(
1527 'ID' => 'CondBsktFldProduct',
1528 'FIELD' => 'PRODUCT_ID',
1529 'FIELD_TYPE' => 'int',
1530 'LABEL' => Loc::getMessage('BT_MOD_SALE_COND_BASKET_PRODUCT_ID_LABEL'),
1531 'PREFIX' => Loc::getMessage('BT_MOD_SALE_COND_BASKET_PRODUCT_ID_PREFIX'),
1532 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
1533 'JS_VALUE' => array(
1534 'type' => 'dialog',
1535 'popup_url' => '/bitrix/tools/sale/product_search_dialog.php',
1536 'popup_params' => array(
1537 'lang' => LANGUAGE_ID,
1538 'caller' => 'discount_rules'
1539 ),
1540 'param_id' => 'n',
1541 'show_value' => 'Y'
1542 ),
1543 'PHP_VALUE' => array(
1544 'VALIDATE' => 'element'
1545 ),
1546 ),
1547 'CondBsktFldName' => array(
1548 'ID' => 'CondBsktFldName',
1549 'FIELD' => 'NAME',
1550 'FIELD_TYPE' => 'string',
1551 'FIELD_LENGTH' => 255,
1552 'LABEL' => Loc::getMessage('BT_MOD_SALE_COND_BASKET_PRODUCT_NAME_LABEL'),
1553 'PREFIX' => Loc::getMessage('BT_MOD_SALE_COND_BASKET_PRODUCT_NAME_PREFIX'),
1554 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ, BT_COND_LOGIC_CONT, BT_COND_LOGIC_NOT_CONT)),
1555 'JS_VALUE' => array(
1556 'type' => 'input'
1557 ),
1558 'PHP_VALUE' => ''
1559 ),
1560 'CondBsktFldSumm' => array(
1561 'ID' => 'CondBsktFldSumm',
1562 'FIELD' => array(
1563 'PRICE',
1564 'QUANTITY'
1565 ),
1566 'FIELD_TYPE' => 'double',
1567 'LABEL' => Loc::getMessage('BT_MOD_SALE_COND_BASKET_ROW_SUMM_LABEL'),
1568 'PREFIX' => Loc::getMessage('BT_MOD_SALE_COND_BASKET_ROW_SUMM_EXT_PREFIX'),
1569 'LOGIC' => static::GetLogic(
1570 array(
1571 BT_COND_LOGIC_EQ,
1572 BT_COND_LOGIC_NOT_EQ,
1573 BT_COND_LOGIC_GR,
1574 BT_COND_LOGIC_LS,
1575 BT_COND_LOGIC_EGR,
1576 BT_COND_LOGIC_ELS
1577 )
1578 ),
1579 'JS_VALUE' => array(
1580 'type' => 'input'
1581 )
1582 ),
1583 'CondBsktFldPrice' => array(
1584 'ID' => 'CondBsktFldPrice',
1585 'FIELD' => 'PRICE',
1586 'FIELD_TYPE' => 'double',
1587 'LABEL' => Loc::getMessage('BT_MOD_SALE_COND_BASKET_ROW_PRICE_LABEL'),
1588 'PREFIX' => Loc::getMessage('BT_MOD_SALE_COND_BASKET_ROW_PRICE_EXT_PREFIX'),
1589 'LOGIC' => static::GetLogic(
1590 array(
1591 BT_COND_LOGIC_EQ,
1592 BT_COND_LOGIC_NOT_EQ,
1593 BT_COND_LOGIC_GR,
1594 BT_COND_LOGIC_LS,
1595 BT_COND_LOGIC_EGR,
1596 BT_COND_LOGIC_ELS
1597 )
1598 ),
1599 'JS_VALUE' => array(
1600 'type' => 'input'
1601 )
1602 ),
1603 'CondBsktFldQuantity' => array(
1604 'ID' => 'CondBsktFldQuantity',
1605 'FIELD' => 'QUANTITY',
1606 'FIELD_TYPE' => 'double',
1607 'LABEL' => Loc::getMessage('BT_MOD_SALE_COND_BASKET_ROW_QUANTITY_LABEL'),
1608 'PREFIX' => Loc::getMessage('BT_MOD_SALE_COND_BASKET_ROW_QUANTITY_EXT_PREFIX'),
1609 'LOGIC' => static::GetLogic(
1610 array(
1611 BT_COND_LOGIC_EQ,
1612 BT_COND_LOGIC_NOT_EQ,
1613 BT_COND_LOGIC_GR,
1614 BT_COND_LOGIC_LS,
1615 BT_COND_LOGIC_EGR,
1616 BT_COND_LOGIC_ELS
1617 )
1618 ),
1619 'JS_VALUE' => array(
1620 'type' => 'input'
1621 )
1622 ),
1623 self::ENTITY_BASKET_POSITION_WEIGHT => array(
1624 'ID' => self::ENTITY_BASKET_POSITION_WEIGHT,
1625 'FIELD' => array(
1626 'WEIGHT',
1627 'QUANTITY'
1628 ),
1629 'FIELD_TYPE' => 'double',
1630 'LABEL' => Loc::getMessage('BT_SALE_COND_BASKET_POSITION_WEIGHT_LABEL'),
1631 'PREFIX' => Loc::getMessage('BT_SALE_COND_BASKET_POSITION_WEIGHT_PREFIX'),
1632 'LOGIC' => static::GetLogic(
1633 array(
1634 BT_COND_LOGIC_EQ,
1635 BT_COND_LOGIC_NOT_EQ,
1636 BT_COND_LOGIC_GR,
1637 BT_COND_LOGIC_LS,
1638 BT_COND_LOGIC_EGR,
1639 BT_COND_LOGIC_ELS
1640 )
1641 ),
1642 'JS_VALUE' => array(
1643 'type' => 'input'
1644 )
1645 ),
1646 'CondBsktFldWeight' => array(
1647 'ID' => 'CondBsktFldWeight',
1648 'FIELD' => 'WEIGHT',
1649 'FIELD_TYPE' => 'double',
1650 'LABEL' => Loc::getMessage('BT_MOD_SALE_COND_BASKET_ROW_WEIGHT_LABEL'),
1651 'PREFIX' => Loc::getMessage('BT_MOD_SALE_COND_BASKET_ROW_WEIGHT_EXT_PREFIX'),
1652 'LOGIC' => static::GetLogic(
1653 array(
1654 BT_COND_LOGIC_EQ,
1655 BT_COND_LOGIC_NOT_EQ,
1656 BT_COND_LOGIC_GR,
1657 BT_COND_LOGIC_LS,
1658 BT_COND_LOGIC_EGR,
1659 BT_COND_LOGIC_ELS
1660 )
1661 ),
1662 'JS_VALUE' => array(
1663 'type' => 'input'
1664 )
1665 )
1666 );
1667
1668 $additionalControls = \CSaleCondCtrlBasketItemConditions::GetControls(false);
1669 foreach ($additionalControls as $id => $data)
1670 $arControlList[$id] = $data;
1671 $additionalControls = \CSaleCondCtrlBasketProperties::GetControls(false);
1672 foreach ($additionalControls as $id => $data)
1673 $arControlList[$id] = $data;
1674 unset($id, $data, $additionalControls);
1675
1676 foreach ($arControlList as &$control)
1677 {
1678 $control['MODULE_ID'] = 'sale';
1679 $control['MODULE_ENTITY'] = 'sale';
1680 if (!isset($control['ENTITY']))
1681 $control['ENTITY'] = 'BASKET';
1682 $control['MULTIPLE'] = 'N';
1683 $control['GROUP'] = 'N';
1684 }
1685 unset($control);
1686
1687 return static::searchControl($arControlList, $strControlID);
1688 }
1689
1690 public static function GetShowIn($arControls)
1691 {
1692 $arControls = CSaleCondCtrlBasketGroup::GetControlID();
1693 $index = array_search('CondCumulativeGroup', $arControls);
1694 if ($index !== false)
1695 {
1696 unset($arControls[$index]);
1697 $arControls = array_values($arControls);
1698 }
1699 unset($index);
1700
1701 return $arControls;
1702 }
1703}
1704
1705class CSaleCondCtrlBasketItemConditions extends CGlobalCondCtrlAtoms
1706{
1707 const ENTITY_BASKET_POSITION_ACTION_APPLIED = 'CondBsktAppliedDiscount';
1708
1709 public static function GetControlDescr()
1710 {
1711 return [];
1712 }
1713
1714 public static function GetAtomsEx($controlId = false, $extendedMode = false)
1715 {
1716 $atomList = [
1717 self::ENTITY_BASKET_POSITION_ACTION_APPLIED => [
1718 'value' => [
1719 'JS' => [
1720 'id' => 'value',
1721 'name' => 'value',
1722 'type' => 'select',
1723 'values' => [
1724 'Y' => Loc::getMessage('BT_SALE_COND_BASKET_DISCOUNT_APPLIED_YES'),
1725 'N' => Loc::getMessage('BT_SALE_COND_BASKET_DISCOUNT_APPLIED_NO')
1726 ],
1727 'defaultText' => '...',
1728 'defaultValue' => '',
1729 'first_option' => '...'
1730 ],
1731 'ATOM' => [
1732 'ID' => 'value',
1733 'FIELD_TYPE' => 'char',
1734 'FIELD' => 'ACTION_APPLIED',
1735 'MULTIPLE' => 'N',
1736 'VALIDATE' => 'list'
1737 ]
1738 ]
1739 ]
1740 ];
1741
1742 return static::searchControlAtoms($atomList, $controlId, $extendedMode);
1743 }
1744
1745 public static function GetControls($controlId = false)
1746 {
1747 $atoms = static::GetAtomsEx();
1748 $controlList = array(
1749 self::ENTITY_BASKET_POSITION_ACTION_APPLIED => array(
1750 'ID' => self::ENTITY_BASKET_POSITION_ACTION_APPLIED,
1751 'LABEL' => Loc::getMessage('BT_SALE_COND_BASKET_DISCOUNT_APPLIED_LABEL'),
1752 'PREFIX' => Loc::getMessage('BT_SALE_COND_BASKET_DISCOUNT_APPLIED_PREFIX'),
1753 'ATOMS' => $atoms[self::ENTITY_BASKET_POSITION_ACTION_APPLIED],
1754 'FIELD' => 'ACTION_APPLIED',
1755 )
1756 );
1757 unset($atoms);
1758
1759 return static::searchControl($controlList, $controlId);
1760 }
1761
1762 public static function GetShowIn($arControls)
1763 {
1764 $arControls = \CSaleCondCtrlBasketGroup::GetControlID();
1765 $index = array_search('CondCumulativeGroup', $arControls);
1766 if ($index !== false)
1767 {
1768 unset($arControls[$index]);
1769 $arControls = array_values($arControls);
1770 }
1771 unset($index);
1772
1773 return $arControls;
1774 }
1775
1776 public static function GetConditionShow($params)
1777 {
1778 // remove excess condition - only for compatibility
1779 if (isset($params['DATA']['logic']))
1780 {
1781 if ($params['DATA']['logic'] == 'Not' && isset($params['DATA']['value']))
1782 {
1783 if ($params['DATA']['value'] == 'Y')
1784 $params['DATA']['value'] = 'N';
1785 elseif ($params['DATA']['value'] == 'N')
1786 $params['DATA']['value'] = 'Y';
1787 }
1788 unset($params['DATA']['logic']);
1789 }
1790 return parent::GetConditionShow($params);
1791 }
1792
1793 public static function Parse($condition)
1794 {
1795 // remove excess condition - only for compatibility
1796 if (isset($condition['logic']))
1797 {
1798 if ($condition['logic'] == 'Not' && isset($condition['value']))
1799 {
1800 if ($condition['value'] == 'Y')
1801 $condition['value'] = 'N';
1802 elseif ($condition['value'] == 'N')
1803 $condition['value'] = 'Y';
1804 }
1805 unset($condition['logic']);
1806 }
1807 return parent::Parse($condition);
1808 }
1809
1810 public static function Generate($condition, $params, $control, $childrens = false)
1811 {
1812 $result = '';
1813
1814 if (is_string($control))
1815 $control = static::GetControls($control);
1816 $error = !is_array($control);
1817
1818 $values = [];
1819 if (!$error)
1820 {
1821 $control['ATOMS'] = static::GetAtomsEx($control['ID'], true);
1822 $values = static::CheckAtoms($condition, $params, $control, false);
1823 $error = ($values === false);
1824 }
1825
1826 if (!$error)
1827 {
1828 $field = $params['BASKET_ROW'].'[\''.$control['FIELD'].'\']';
1829 $result = 'isset('.$field.') && '.$field.'==\''.\CUtil::JSEscape($values['value']).'\'';
1830 unset($field);
1831 }
1832 unset($values);
1833
1834 return $result;
1835 }
1836}
1837
1839{
1840 const ENTITY_BASKET_PROPERTY = 'BX:CondBsktProp';
1841
1842 const ENTITY_TYPE_NAME = 'NAME';
1843 const ENTITY_TYPE_CODE = 'CODE';
1844
1845 public static function GetControlDescr()
1846 {
1847 return array();
1848 }
1849
1850 public static function GetAtomsEx($controlId = false, $extendedMode = false)
1851 {
1852 $logic = array();
1853 $logicList = static::GetLogic(array(
1855 ));
1856 foreach ($logicList as $row)
1857 $logic[$row['ID']] = $row['LABEL'];
1858 unset($row, $logicList);
1859
1860 $atomList = array(
1861 self::ENTITY_BASKET_PROPERTY => array(
1862 'Entity' => array(
1863 'JS' => array(
1864 'id' => 'Entity',
1865 'name' => 'Entity',
1866 'type' => 'select',
1867 'values' => array(
1868 self::ENTITY_TYPE_CODE => Loc::getMessage('BT_SALE_COND_BASKET_PROPERTY_ENTITY_TYPE_CODE'),
1869 self::ENTITY_TYPE_NAME => Loc::getMessage('BT_SALE_COND_BASKET_PROPERTY_ENTITY_TYPE_NAME')
1870 ),
1871 'defaultText' => Loc::getMessage('BT_SALE_COND_BASKET_PROPERTY_ENTITY_TYPE_SELECT_DEF'),
1872 'defaultValue' => self::ENTITY_TYPE_CODE,
1873 'first_option' => '...'
1874 ),
1875 'ATOM' => array(
1876 'ID' => 'Entity',
1877 'FIELD_TYPE' => 'string',
1878 'FIELD_LENGTH' => 255,
1879 'MULTIPLE' => 'N',
1880 'VALIDATE' => 'list'
1881 )
1882 ),
1883 'Name' => array(
1884 'JS' => array(
1885 'id' => 'Name',
1886 'name' => 'Name',
1887 'type' => 'input'
1888 ),
1889 'ATOM' => array(
1890 'ID' => 'Name',
1891 'FIELD_TYPE' => 'string',
1892 'FIELD_LENGTH' => 255,
1893 'MULTIPLE' => 'N',
1894 'VALIDATE' => ''
1895 )
1896 ),
1897 'Logic' => array(
1898 'JS' => array(
1899 'id' => 'Logic',
1900 'name' => 'Logic',
1901 'type' => 'select',
1902 'values' => $logic,
1903 'defaultText' => '',
1904 'defaultValue' => BT_COND_LOGIC_EQ,
1905 ),
1906 'ATOM' => array(
1907 'ID' => 'Logic',
1908 'FIELD_TYPE' => 'string',
1909 'FIELD_LENGTH' => 255,
1910 'MULTIPLE' => 'N',
1911 'VALIDATE' => 'list'
1912 )
1913 ),
1914 'Value' => array(
1915 'JS' => array(
1916 'id' => 'Value',
1917 'name' => 'Value',
1918 'type' => 'input'
1919 ),
1920 'ATOM' => array(
1921 'ID' => 'Value',
1922 'FIELD_TYPE' => 'string',
1923 'FIELD_LENGTH' => 255,
1924 'MULTIPLE' => 'N',
1925 'VALIDATE' => ''
1926 )
1927 )
1928 )
1929 );
1930
1931 return static::searchControlAtoms($atomList, $controlId, $extendedMode);
1932 }
1933
1934 public static function GetControls($controlId = false)
1935 {
1936 $atoms = static::GetAtomsEx();
1937 $controlList = array(
1938 self::ENTITY_BASKET_PROPERTY => array(
1939 'ID' => self::ENTITY_BASKET_PROPERTY,
1940 'LABEL' => Loc::getMessage('BT_SALE_COND_BASKET_PROPERTY_LABEL'),
1941 'PREFIX' => Loc::getMessage('BT_SALE_COND_BASKET_PROPERTY_PREFIX'),
1942 'ATOMS' => $atoms[self::ENTITY_BASKET_PROPERTY],
1943 'MODULE_ID' => 'sale',
1944 'MODULE_ENTITY' => 'sale',
1945 'ENTITY' => 'BASKET_PROPERTY',
1946 'FIELD' => array(
1947 'VALUE',
1948 'NAME',
1949 'CODE'
1950 ),
1951 'MULTIPLE' => 'N',
1952 'GROUP' => 'N'
1953 )
1954 );
1955
1956 return static::searchControl($controlList, $controlId);
1957 }
1958
1959 public static function GetShowIn($arControls)
1960 {
1962 $index = array_search('CondCumulativeGroup', $arControls);
1963 if ($index !== false)
1964 {
1965 unset($arControls[$index]);
1966 $arControls = array_values($arControls);
1967 }
1968 unset($index);
1969
1970 return $arControls;
1971 }
1972
1973 public static function Generate($condition, $params, $control, $childrens = false)
1974 {
1975 $result = '';
1976
1977 if (is_string($control))
1978 $control = static::GetControls($control);
1979 $error = !is_array($control);
1980
1981 $values = array();
1982 if (!$error)
1983 {
1984 $control['ATOMS'] = static::GetAtomsEx($control['ID'], true);
1985 $values = static::CheckAtoms($condition, $params, $control, false);
1986 $error = ($values === false);
1987 }
1988
1989 if (!$error)
1990 {
1991 $data = 'array('.
1992 '\'ENTITY_ID\' => \''.$values['Entity'].'\', '.
1993 '\'ENTITY_VALUE\' => \''.\CUtil::JSEscape($values['Name']).'\', '.
1994 '\'LOGIC\' => '.$values['Logic'].', '.
1995 '\'VALUE\' => \''.\CUtil::JSEscape($values['Value']).'\''.
1996 ')';
1997 $result = '\CSaleBasketFilter::BasketPropertyFilter('.$params['BASKET_ROW'].', '.$data.')';
1998 unset($data);
1999 }
2000
2001 return $result;
2002 }
2003}
2004
2006{
2007 public static function GetControlDescr()
2008 {
2009 $description = parent::GetControlDescr();
2010 $description['SORT'] = 300;
2011 return $description;
2012 }
2013
2014 public static function GetControlShow($arParams)
2015 {
2016 $arControls = static::GetControls();
2017 $arResult = array(
2018 'controlgroup' => true,
2019 'group' => false,
2020 'label' => Loc::getMessage('BT_MOD_SALE_COND_CMP_ORDER_CONTROLGROUP_LABEL'),
2021 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
2022 'children' => array()
2023 );
2024 foreach ($arControls as &$arOneControl)
2025 {
2026 if ('ORDER_PRICE' == $arOneControl['FIELD'])
2027 {
2028 $arJSControl = array(
2029 array(
2030 'id' => 'prefix',
2031 'type' => 'prefix',
2032 'text' => $arOneControl['PREFIX']
2033 ),
2034 static::GetLogicAtom($arOneControl['LOGIC']),
2035 static::GetValueAtom($arOneControl['JS_VALUE'])
2036 );
2037 if (static::$boolInit)
2038 {
2039 if (isset(static::$arInitParams['CURRENCY']))
2040 {
2041 $arJSControl[] = static::$arInitParams['CURRENCY'];
2042 }
2043 elseif (isset(static::$arInitParams['SITE_ID']))
2044 {
2045 $strCurrency = Sale\Internals\SiteCurrencyTable::getSiteCurrency(static::$arInitParams['SITE_ID']);
2046 if (!empty($strCurrency))
2047 {
2048 $arJSControl[] = $strCurrency;
2049 }
2050 }
2051 }
2052 $arOne = array(
2053 'controlId' => $arOneControl['ID'],
2054 'group' => ('Y' == $arOneControl['GROUP']),
2055 'label' => $arOneControl['LABEL'],
2056 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
2057 'control' => $arJSControl
2058 );
2059 }
2060 else
2061 {
2062 $arOne = array(
2063 'controlId' => $arOneControl['ID'],
2064 'group' => ('Y' == $arOneControl['GROUP']),
2065 'label' => $arOneControl['LABEL'],
2066 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
2067 'control' => array(
2068 array(
2069 'id' => 'prefix',
2070 'type' => 'prefix',
2071 'text' => $arOneControl['PREFIX']
2072 ),
2073 static::GetLogicAtom($arOneControl['LOGIC']),
2074 static::GetValueAtom($arOneControl['JS_VALUE'])
2075 )
2076 );
2077 }
2078 if ('ORDER_WEIGHT' == $arOneControl['FIELD'])
2079 {
2080 $arOne['control'][] = Loc::getMessage('BT_MOD_SALE_COND_MESS_WEIGHT_UNIT');
2081 }
2082 $arResult['children'][] = $arOne;
2083 }
2084 if (isset($arOneControl))
2085 unset($arOneControl);
2086
2087 return $arResult;
2088 }
2089
2090 public static function Parse($arOneCondition)
2091 {
2092 if (!isset($arOneCondition['controlId']))
2093 return false;
2094 $arControl = static::GetControls($arOneCondition['controlId']);
2095 if (false === $arControl)
2096 return false;
2097 return static::Check($arOneCondition, $arOneCondition, $arControl, false);
2098 }
2099
2100 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
2101 {
2102 $strResult = '';
2103
2104 if (is_string($arControl))
2105 {
2106 $arControl = static::GetControls($arControl);
2107 }
2108 $boolError = !is_array($arControl);
2109
2110 $arValues = array();
2111 if (!$boolError)
2112 {
2113 $arValues = static::Check($arOneCondition, $arOneCondition, $arControl, false);
2114 $boolError = (false === $arValues);
2115 }
2116
2117 if (!$boolError)
2118 {
2119 $arLogic = static::SearchLogic($arValues['logic'], $arControl['LOGIC']);
2120 if (!isset($arLogic['OP'][$arControl['MULTIPLE']]) || empty($arLogic['OP'][$arControl['MULTIPLE']]))
2121 {
2122 $boolError = true;
2123 }
2124 else
2125 {
2126 $strJoinOperator = '';
2127 $boolMulti = false;
2128 if (isset($arControl['JS_VALUE']['multiple']) && 'Y' == $arControl['JS_VALUE']['multiple'])
2129 {
2130 $boolMulti = true;
2131 $strJoinOperator = (isset($arLogic['MULTI_SEP']) ? $arLogic['MULTI_SEP'] : ' && ');
2132 }
2133 $strField = $arParams['ORDER'].'[\''.$arControl['FIELD'].'\']';
2134 switch ($arControl['FIELD_TYPE'])
2135 {
2136 case 'int':
2137 case 'double':
2138 if (!$boolMulti)
2139 {
2140 $strResult = str_replace(array('#FIELD#', '#VALUE#'), array($strField, $arValues['value']), $arLogic['OP'][$arControl['MULTIPLE']]);
2141 }
2142 else
2143 {
2144 $arResult = array();
2145 foreach ($arValues['value'] as &$mxValue)
2146 {
2147 $arResult[] = str_replace(array('#FIELD#', '#VALUE#'), array($strField, $mxValue), $arLogic['OP'][$arControl['MULTIPLE']]);
2148 }
2149 if (isset($mxValue))
2150 unset($mxValue);
2151 $strResult = '(('.implode(')'.$strJoinOperator.'(', $arResult).'))';
2152 }
2153 break;
2154 case 'char':
2155 case 'string':
2156 case 'text':
2157 if (!$boolMulti)
2158 {
2159 $strResult = str_replace(array('#FIELD#', '#VALUE#'), array($strField, '"'.EscapePHPString($arValues['value']).'"'), $arLogic['OP'][$arControl['MULTIPLE']]);
2160 }
2161 else
2162 {
2163 $arResult = array();
2164 foreach ($arValues['value'] as &$mxValue)
2165 {
2166 $arResult[] = str_replace(array('#FIELD#', '#VALUE#'), array($strField, '"'.EscapePHPString($mxValue).'"'), $arLogic['OP'][$arControl['MULTIPLE']]);
2167 }
2168 if (isset($mxValue))
2169 unset($mxValue);
2170 $strResult = '(('.implode(')'.$strJoinOperator.'(', $arResult).'))';
2171 }
2172 break;
2173 case 'date':
2174 case 'datetime':
2175 if (!$boolMulti)
2176 {
2177 $strResult = str_replace(array('#FIELD#', '#VALUE#'), array($strField, $arValues['value']), $arLogic['OP'][$arControl['MULTIPLE']]);
2178 }
2179 else
2180 {
2181 $arResult = array();
2182 foreach ($arValues['value'] as &$mxValue)
2183 {
2184 $arResult[] = str_replace(array('#FIELD#', '#VALUE#'), array($strField, $mxValue), $arLogic['OP'][$arControl['MULTIPLE']]);
2185 }
2186 if (isset($mxValue))
2187 unset($mxValue);
2188 $strResult = '(('.implode(')'.$strJoinOperator.'(', $arResult).'))';
2189 }
2190 break;
2191 }
2192 $strResult = 'isset('.$strField.') && '.$strResult;
2193 }
2194 }
2195
2196 return (!$boolError ? $strResult : false);
2197 }
2198
2203 public static function GetControls($strControlID = false)
2204 {
2205 $arSalePersonTypes = array();
2206 $arFilter = array();
2207 if (static::$boolInit)
2208 {
2209 if (isset(static::$arInitParams['SITE_ID']))
2210 $arFilter['LID'] = static::$arInitParams['SITE_ID'];
2211 }
2212 $rsPersonTypes = CSalePersonType::GetList(
2213 array('SORT' => 'ASC', 'NAME' => 'ASC'),
2214 $arFilter,
2215 false,
2216 false,
2217 array('ID', 'NAME', 'LIDS', 'SORT')
2218 );
2219 while ($arPersonType = $rsPersonTypes->Fetch())
2220 {
2221 $id = (int)$arPersonType['ID'];
2222 $arSalePersonTypes[$id] = $arPersonType['NAME'].' ('.implode(' ', $arPersonType['LIDS']).')';
2223 unset($id);
2224 }
2225 unset($arPersonType, $rsPersonTypes);
2226
2227 ;
2228 $salePaySystemList = [];
2229 $filter = [
2230 '!=ID' => Sale\PaySystem\Manager::getInnerPaySystemId(),
2231 ];
2232 $iterator = Sale\PaySystem\Manager::getList([
2233 'select' => ['ID', 'NAME', 'SORT'],
2234 'filter' => $filter,
2235 'order' => ['SORT' => 'ASC', 'NAME' => 'ASC']
2236 ]);
2237 while ($row = $iterator->fetch())
2238 {
2239 $salePaySystemList[$row['ID']] = $row['NAME'];
2240 }
2241 unset($row, $iterator);
2242
2243 $linearDeliveryList = array();
2244 $deliveryList = array();
2245 $groupIds = array();
2246 $iterator = Sale\Delivery\Services\Table::getList(array(
2247 'select' => array('ID', 'CLASS_NAME'),
2248 'filter' => array('=CLASS_NAME' => '\Bitrix\Sale\Delivery\Services\Group')
2249 ));
2250 while ($row = $iterator->fetch())
2251 $groupIds[] = (int)$row['ID'];
2252 unset($row, $iterator);
2253
2254 $deliveryIterator = Sale\Delivery\Services\Table::getList(array(
2255 'select' => array('ID', 'CODE', 'NAME', 'PARENT_ID', 'SORT', 'CLASS_NAME'),
2256 'order' => array('ID' => 'ASC')
2257 ));
2258 while ($delivery = $deliveryIterator->fetch())
2259 {
2260 if ($delivery['CLASS_NAME'] == '\Bitrix\Sale\Delivery\Services\Group')
2261 continue;
2262 $deliveryId = (int)$delivery['ID'];
2263 $parentId = (int)$delivery['PARENT_ID'];
2264 if ($parentId > 0 && !in_array($parentId, $groupIds))
2265 {
2266 if (isset($deliveryList[$parentId]))
2267 {
2268 $deliveryList[$parentId]['PROFILES'][$deliveryId] = array(
2269 'ID' => $deliveryId,
2270 'TITLE' => $delivery['NAME'],
2271 'SORT' => (int)$delivery['SORT']
2272 );
2273 }
2274 }
2275 else
2276 {
2277 $deliveryList[$deliveryId] = array(
2278 'ID' => $deliveryId,
2279 'TITLE' => $delivery['NAME'],
2280 'SORT' => (int)$delivery['SORT'],
2281 'PROFILES' => array()
2282 );
2283 }
2284 unset($parentId, $deliveryId);
2285 }
2286 unset($delivery, $deliveryIterator);
2287 unset($groupIds);
2288 if (!empty($deliveryList))
2289 {
2290 Main\Type\Collection::sortByColumn($deliveryList, array('SORT' => SORT_ASC, 'TITLE' => SORT_ASC, 'ID' => SORT_ASC));
2291 foreach ($deliveryList as $delivery)
2292 {
2293 if (empty($delivery['PROFILES']))
2294 {
2295 $linearDeliveryList[$delivery['ID']] = $delivery['TITLE'];
2296 }
2297 else
2298 {
2299 $profileList = $delivery['PROFILES'];
2300 Main\Type\Collection::sortByColumn($profileList, array('SORT' => SORT_ASC, 'TITLE' => SORT_ASC, 'ID' => SORT_ASC));
2301 foreach ($profileList as $profile)
2302 $linearDeliveryList[$profile['ID']] = $delivery['TITLE'].': '.$profile['TITLE'];
2303 unset($profile, $profileList);
2304 }
2305 }
2306 unset($delivery);
2307 }
2308 unset($deliveryList);
2309
2310 $arLabels = array(
2311 BT_COND_LOGIC_EQ => Loc::getMessage('BT_SALE_AMOUNT_LOGIC_EQ_LABEL'),
2312 BT_COND_LOGIC_NOT_EQ => Loc::getMessage('BT_SALE_AMOUNT_LOGIC_NOT_EQ_LABEL'),
2313 BT_COND_LOGIC_GR => Loc::getMessage('BT_SALE_AMOUNT_LOGIC_GR_LABEL'),
2314 BT_COND_LOGIC_LS => Loc::getMessage('BT_SALE_AMOUNT_LOGIC_LS_LABEL'),
2315 BT_COND_LOGIC_EGR => Loc::getMessage('BT_SALE_AMOUNT_LOGIC_EGR_LABEL'),
2316 BT_COND_LOGIC_ELS => Loc::getMessage('BT_SALE_AMOUNT_LOGIC_ELS_LABEL')
2317 );
2318 $arLabelsWeight = array(
2319 BT_COND_LOGIC_EQ => Loc::getMessage('BT_SALE_WEIGHT_LOGIC_EQ_LABEL'),
2320 BT_COND_LOGIC_NOT_EQ => Loc::getMessage('BT_SALE_WEIGHT_LOGIC_NOT_EQ_LABEL'),
2321 BT_COND_LOGIC_GR => Loc::getMessage('BT_SALE_WEIGHT_LOGIC_GR_LABEL'),
2322 BT_COND_LOGIC_LS => Loc::getMessage('BT_SALE_WEIGHT_LOGIC_LS_LABEL'),
2323 BT_COND_LOGIC_EGR => Loc::getMessage('BT_SALE_WEIGHT_LOGIC_EGR_LABEL'),
2324 BT_COND_LOGIC_ELS => Loc::getMessage('BT_SALE_WEIGHT_LOGIC_ELS_LABEL')
2325 );
2326
2327 $arControlList = array(
2328 'CondSaleOrderSumm' => array(
2329 'ID' => 'CondSaleOrderSumm',
2330 'FIELD' => 'ORDER_PRICE',
2331 'FIELD_TYPE' => 'double',
2332 'LABEL' => Loc::getMessage('BT_MOD_SALE_COND_CMP_SALE_ORDER_SUMM_LABEL_EXT'),
2333 'PREFIX' => Loc::getMessage('BT_MOD_SALE_COND_CMP_SALE_ORDER_SUMM_PREFIX_EXT'),
2334 'LOGIC' => static::GetLogicEx(array_keys($arLabels), $arLabels),
2335 'JS_VALUE' => array(
2336 'type' => 'input'
2337 )
2338 ),
2339 'CondSalePersonType' => array(
2340 'ID' => 'CondSalePersonType',
2341 'FIELD' => 'PERSON_TYPE_ID',
2342 'FIELD_TYPE' => 'int',
2343 'LABEL' => Loc::getMessage('BT_MOD_SALE_COND_CMP_SALE_PERSON_TYPE_LABEL'),
2344 'PREFIX' => Loc::getMessage('BT_MOD_SALE_COND_CMP_SALE_PERSON_TYPE_PREFIX'),
2345 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
2346 'JS_VALUE' => array(
2347 'type' => 'select',
2348 'multiple' => 'Y',
2349 'values' => $arSalePersonTypes,
2350 'size' => self::getSelectSize($arSalePersonTypes),
2351 'show_value' => 'Y'
2352 ),
2353 'PHP_VALUE' => array(
2354 'VALIDATE' => 'list'
2355 )
2356 ),
2357 'CondSalePaySystem' => array(
2358 'ID' => 'CondSalePaySystem',
2359 'FIELD' => 'PAY_SYSTEM_ID',
2360 'FIELD_TYPE' => 'int',
2361 'LABEL' => Loc::getMessage('BT_MOD_SALE_COND_CMP_SALE_PAY_SYSTEM_LABEL'),
2362 'PREFIX' => Loc::getMessage('BT_MOD_SALE_COND_CMP_SALE_PAY_SYSTEM_PREFIX'),
2363 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
2364 'JS_VALUE' => array(
2365 'type' => 'select',
2366 'multiple' => 'Y',
2367 'values' => $salePaySystemList,
2368 'size' => self::getSelectSize($salePaySystemList),
2369 'show_value' => 'Y'
2370 ),
2371 'PHP_VALUE' => array(
2372 'VALIDATE' => 'list'
2373 )
2374 ),
2375 'CondSaleDelivery' => array(
2376 'ID' => 'CondSaleDelivery',
2377 'FIELD' => 'DELIVERY_ID',
2378 'FIELD_TYPE' => 'string',
2379 'FIELD_LENGTH' => 50,
2380 'LABEL' => Loc::getMessage('BT_MOD_SALE_COND_CMP_SALE_DELIVERY_LABEL'),
2381 'PREFIX' => Loc::getMessage('BT_MOD_SALE_COND_CMP_SALE_DELIVERY_PREFIX'),
2382 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
2383 'JS_VALUE' => array(
2384 'type' => 'select',
2385 'multiple' => 'Y',
2386 'values' => $linearDeliveryList,
2387 'size' => self::getSelectSize($linearDeliveryList),
2388 'show_value' => 'Y'
2389 ),
2390 'PHP_VALUE' => array(
2391 'VALIDATE' => 'list'
2392 )
2393 ),
2394 'CondSaleOrderWeight' => array(
2395 'ID' => 'CondSaleOrderWeight',
2396 'FIELD' => 'ORDER_WEIGHT',
2397 'FIELD_TYPE' => 'double',
2398 'LABEL' => Loc::getMessage('BT_MOD_SALE_COND_SALE_ORDER_WEIGHT_LABEL'),
2399 'PREFIX' => Loc::getMessage('BT_MOD_SALE_COND_SALE_ORDER_WEIGHT_PREFIX'),
2400 'LOGIC' => static::GetLogicEx(array_keys($arLabelsWeight), $arLabelsWeight),
2401 'JS_VALUE' => array(
2402 'type' => 'input'
2403 )
2404 )
2405 );
2406 foreach ($arControlList as &$control)
2407 {
2408 $control['EXECUTE_MODULE'] = 'sale';
2409 $control['MODULE_ID'] = 'sale';
2410 $control['MODULE_ENTITY'] = 'sale';
2411 $control['ENTITY'] = 'ORDER';
2412 $control['MULTIPLE'] = 'N';
2413 $control['GROUP'] = 'N';
2414 }
2415 unset($control);
2416
2417 return static::searchControl($arControlList, $strControlID);
2418 }
2419
2420 public static function GetShowIn($arControls)
2421 {
2422 $arControls = array(CSaleCondCtrlGroup::GetControlID());
2423 return $arControls;
2424 }
2425
2426 public static function GetJSControl($arControl, $arParams = array())
2427 {
2428 return array();
2429 }
2430
2431 private static function getSelectSize(array $rows): int
2432 {
2433 $result = 3;
2434 $rowCount = count($rows);
2435 if ($rowCount > 10)
2436 {
2437 $result = 10;
2438 }
2439 elseif ($rowCount > 3)
2440 {
2441 $result = $rowCount;
2442 }
2443 return $result;
2444 }
2445}
2446
2447class CSaleCondCtrlPastOrder extends CSaleCondCtrlOrderFields
2448{
2449 public static function GetControlDescr()
2450 {
2451 $description = parent::GetControlDescr();
2452 $description['SORT'] = 330;
2453 return $description;
2454 }
2455
2456 public static function onBuildDiscountConditionInterfaceControls()
2457 {
2458 return new EventResult(
2459 EventResult::SUCCESS,
2460 static::getControlDescr(),
2461 'sale'
2462 );
2463 }
2464
2465 public static function checkPastOrder($currentOrder, $callable)
2466 {
2467 if(!is_callable($callable))
2468 {
2469 return false;
2470 }
2471
2472 if(empty($currentOrder['USER_ID']))
2473 {
2474 return false;
2475 }
2476
2477 $orderUserId = (int)$currentOrder['USER_ID'];
2478 $pastOrder = static::getPastOrder($orderUserId);
2479
2480 if (!$pastOrder)
2481 {
2482 return false;
2483 }
2484
2485 if (!$pastOrder->isPaid())
2486 {
2487 return false;
2488 }
2489
2490 return call_user_func_array($callable, array(static::convertToArray($pastOrder)));
2491 }
2492
2493 private static function convertToArray(Sale\Order $order)
2494 {
2495 $orderData = array(
2496 'ID' => $order->getId(),
2497 'USER_ID' => $order->getUserId(),
2498 'SITE_ID' => $order->getSiteId(),
2499 'LID' => $order->getSiteId(), // compatibility only
2500 'ORDER_PRICE' => $order->getPrice(),
2501 'ORDER_WEIGHT' => $order->getBasket()->getWeight(),
2502 'CURRENCY' => $order->getCurrency(),
2503 'PERSON_TYPE_ID' => $order->getPersonTypeId(),
2504 'RECURRING_ID' => $order->getField('RECURRING_ID'),
2505 'BASKET_ITEMS' => array(),
2506 'PRICE_DELIVERY' => 0,
2507 'PRICE_DELIVERY_DIFF' => 0,
2508 'CUSTOM_PRICE_DELIVERY' => 'N',
2509 'SHIPMENT_CODE' => 0,
2510 'SHIPMENT_ID' => 0,
2511 'ORDER_PROP' => array(),
2512 'DELIVERY_ID' => array(),
2513 'PAY_SYSTEM_ID' => array(),
2514 );
2515
2517 foreach ($order->getShipmentCollection() as $shipment)
2518 {
2519 if (!$shipment->isShipped())
2520 {
2521 continue;
2522 }
2523
2524 $orderData['DELIVERY_ID'][] = (int)$shipment->getDeliveryId();
2525 }
2526
2528 foreach ($order->getPaymentCollection() as $payment)
2529 {
2530 if ($payment->isInner())
2531 {
2532 continue;
2533 }
2534
2535 $orderData['PAY_SYSTEM_ID'][] = (int)$payment->getPaymentSystemId();
2536 }
2537
2538 return $orderData;
2539 }
2540
2541 private static function getPastOrder($userId)
2542 {
2543 $registry = \Bitrix\Sale\Registry::getInstance(\Bitrix\Sale\Registry::REGISTRY_TYPE_ORDER);
2544
2546 $orderClass = $registry->getOrderClassName();
2547
2548 $orderData = $orderClass::getList(
2549 array(
2550 'select' => array('ID'),
2551 'filter' => array(
2552 '=CANCELED' => 'N',
2553 '=USER_ID' => $userId
2554 ),
2555 'order' => array('ID' => 'DESC'),
2556 'limit' => 1
2557
2558 )
2559 )->fetch();
2560
2561 if (empty($orderData['ID']))
2562 {
2563 return null;
2564 }
2565
2566 return $orderClass::load($orderData['ID']);
2567 }
2568
2569 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
2570 {
2571 $code = parent::Generate($arOneCondition, $arParams, $arControl, $arSubs);
2572
2573 return static::GetClassName() . "::checkPastOrder({$arParams['ORDER']}, function({$arParams['ORDER']}){
2574 return {$code};
2575 })";
2576 }
2577
2578 public static function GetControlShow($arParams)
2579 {
2580 $controlShow = parent::GetControlShow($arParams);
2581 $controlShow['label'] = Loc::getMessage('BT_SALE_COND_GROUP_PAST_ORDER_NAME');
2582
2583 return $controlShow;
2584 }
2585
2586 public static function GetControls($strControlID = false)
2587 {
2588 $controls = array();
2589 foreach (parent::GetControls() as $control)
2590 {
2591 $control['ID'] = 'Past' . $control['ID'];
2592 $control['PREFIX'] = $control['PREFIX'] . Loc::getMessage("BT_SALE_COND_GROUP_PAST_ORDER_NAME_SUFFIX");
2593
2594 if (in_array($control['FIELD'], array('PAY_SYSTEM_ID', 'DELIVERY_ID')))
2595 {
2596 $control['MULTIPLE'] = 'Y';
2597 }
2598
2599 $controls[$control['ID']] = $control;
2600 }
2601
2602 return static::searchControl($controls, $strControlID);
2603 }
2604}
2605
2606class CSaleCondCtrlCommon extends CSaleCondCtrlComplex
2607{
2608 public static function GetControlDescr()
2609 {
2610 $description = parent::GetControlDescr();
2611 $description['EXECUTE_MODULE'] = 'sale';
2612 $description['SORT'] = 2000;
2613 return $description;
2614 }
2615
2616 public static function GetControlShow($arParams)
2617 {
2618 $arControls = static::GetControls();
2619 $arResult = array(
2620 'controlgroup' => true,
2621 'group' => false,
2622 'label' => Loc::getMessage('BT_MOD_SALE_COND_CMP_COMMON_CONTROLGROUP_LABEL'),
2623 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
2624 'children' => array()
2625 );
2626 foreach ($arControls as &$arOneControl)
2627 {
2628 $arResult['children'][] = array(
2629 'controlId' => $arOneControl['ID'],
2630 'group' => false,
2631 'label' => $arOneControl['LABEL'],
2632 'showIn' => static::GetShowIn($arParams['SHOW_IN_GROUPS']),
2633 'control' => array(
2634 $arOneControl['PREFIX'],
2635 static::GetLogicAtom($arOneControl['LOGIC']),
2636 static::GetValueAtom($arOneControl['JS_VALUE'])
2637 )
2638 );
2639 }
2640 if (isset($arOneControl))
2641 unset($arOneControl);
2642
2643 return $arResult;
2644 }
2645
2646 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
2647 {
2648 $strResult = '';
2649
2650 if (is_string($arControl))
2651 {
2652 $arControl = static::GetControls($arControl);
2653 }
2654 $boolError = !is_array($arControl);
2655
2656 $arValues = array();
2657 if (!$boolError)
2658 {
2659 $arValues = static::Check($arOneCondition, $arOneCondition, $arControl, false);
2660 $boolError = ($arValues === false);
2661 }
2662
2663 if (!$boolError)
2664 {
2665 $arLogic = static::SearchLogic($arValues['logic'], $arControl['LOGIC']);
2666 if (!isset($arLogic['OP'][$arControl['MULTIPLE']]) || empty($arLogic['OP'][$arControl['MULTIPLE']]))
2667 {
2668 $boolError = true;
2669 }
2670 else
2671 {
2672 $boolMulti = false;
2673 if (isset($arControl['JS_VALUE']['multiple']) && 'Y' == $arControl['JS_VALUE']['multiple'])
2674 {
2675 $boolMulti = true;
2676 }
2677 $intDayOfWeek = "(int)date('N')";
2678 if (!$boolMulti)
2679 {
2680 $strResult = str_replace(array('#FIELD#', '#VALUE#'), array($intDayOfWeek, $arValues['value']), $arLogic['OP'][$arControl['MULTIPLE']]);
2681 }
2682 else
2683 {
2684 $arResult = array();
2685 foreach ($arValues['value'] as &$mxValue)
2686 {
2687 $arResult[] = str_replace(array('#FIELD#', '#VALUE#'), array($intDayOfWeek, $mxValue), $arLogic['OP'][$arControl['MULTIPLE']]);
2688 }
2689 if (isset($mxValue))
2690 unset($mxValue);
2691 $strResult = '(('.implode(') || (', $arResult).'))';
2692 }
2693 }
2694 }
2695
2696 return (!$boolError ? $strResult : false);
2697 }
2698
2703 public static function GetControls($strControlID = false)
2704 {
2705 $arDayOfWeek = array(
2706 1 => Loc::getMessage('BT_MOD_SALE_COND_DAY_OF_WEEK_1'),
2707 2 => Loc::getMessage('BT_MOD_SALE_COND_DAY_OF_WEEK_2'),
2708 3 => Loc::getMessage('BT_MOD_SALE_COND_DAY_OF_WEEK_3'),
2709 4 => Loc::getMessage('BT_MOD_SALE_COND_DAY_OF_WEEK_4'),
2710 5 => Loc::getMessage('BT_MOD_SALE_COND_DAY_OF_WEEK_5'),
2711 6 => Loc::getMessage('BT_MOD_SALE_COND_DAY_OF_WEEK_6'),
2712 7 => Loc::getMessage('BT_MOD_SALE_COND_DAY_OF_WEEK_7')
2713 );
2714 $arControlList = array(
2715 'CondSaleCmnDayOfWeek' => array(
2716 'ID' => 'CondSaleCmnDayOfWeek',
2717 'EXECUTE_MODULE' => 'sale',
2718 'MODULE_ID' => false,
2719 'MODULE_ENTITY' => 'datetime',
2720 'FIELD' => 'DAY_OF_WEEK',
2721 'FIELD_TYPE' => 'int',
2722 'MULTIPLE' => 'N',
2723 'GROUP' => 'N',
2724 'LABEL' => Loc::getMessage('BT_MOD_SALE_COND_CMP_CMN_DAYOFWEEK_LABEL'),
2725 'PREFIX' => Loc::getMessage('BT_MOD_SALE_COND_CMP_CMN_DAYOFWEEK_PREFIX'),
2726 'LOGIC' => static::GetLogic(array(BT_COND_LOGIC_EQ, BT_COND_LOGIC_NOT_EQ)),
2727 'JS_VALUE' => array(
2728 'type' => 'select',
2729 'multiple' => 'Y',
2730 'values' => $arDayOfWeek
2731 ),
2732 'PHP_VALUE' => array(
2733 'VALIDATE' => 'list'
2734 )
2735 )
2736 );
2737
2738 return static::searchControl($arControlList, $strControlID);
2739 }
2740
2741 public static function GetShowIn($arControls)
2742 {
2743 $arControls = array(CSaleCondCtrlGroup::GetControlID());
2744 return $arControls;
2745 }
2746}
2747
2748class CSaleCondTree extends CGlobalCondTree
2749{
2750 protected $arExecuteFunc = array();
2751 protected $executeModule = array();
2752
2753 public function __construct()
2754 {
2755 parent::__construct();
2756 }
2757
2758 public function __destruct()
2759 {
2760 parent::__destruct();
2761 }
2762
2763 public function Generate($arConditions, $arParams)
2764 {
2765 $strFinal = '';
2766 $this->arExecuteFunc = array();
2767 $this->usedModules = array();
2768 $this->usedExtFiles = array();
2769 $this->usedEntity = array();
2770 $this->executeModule = array();
2771
2772 if (!$this->boolError)
2773 {
2774 $strResult = '';
2775 if (!empty($arConditions) && is_array($arConditions))
2776 {
2777 $arParams['FUNC_ID'] = '';
2778 $arResult = $this->GenerateLevel($arConditions, $arParams, true);
2779 if (empty($arResult))
2780 {
2781 $strResult = '';
2782 $this->boolError = true;
2783 }
2784 else
2785 {
2786 $strResult = current($arResult);
2787 }
2788 }
2789 else
2790 {
2791 $this->boolError = true;
2792 }
2793 if (!$this->boolError)
2794 {
2795 $strFinal = 'function('.$arParams['ORDER'].'){';
2796 if (!empty($this->arExecuteFunc))
2797 {
2798 $strFinal .= implode('; ', $this->arExecuteFunc).'; ';
2799 }
2800 $strFinal .= 'return '.$strResult.'; };';
2801 $strFinal = preg_replace("#;{2,}#",";", $strFinal);
2802 }
2803 return $strFinal;
2804 }
2805 else
2806 {
2807 return '';
2808 }
2809 }
2810
2811 public function GenerateLevel(&$arLevel, $arParams, $boolFirst = false)
2812 {
2813 $arResult = array();
2814 $boolFirst = ($boolFirst === true);
2815 if (empty($arLevel) || !is_array($arLevel))
2816 {
2817 return $arResult;
2818 }
2819 if (!isset($arParams['FUNC_ID']))
2820 {
2821 $arParams['FUNC_ID'] = '';
2822 }
2823 $intRowNum = 0;
2824 if ($boolFirst)
2825 {
2826 $arParams['ROW_NUM'] = $intRowNum;
2827 if (!empty($arLevel['CLASS_ID']))
2828 {
2829 $defaultBlock = $this->GetDefaultConditions();
2830 if ($arLevel['CLASS_ID'] !== $defaultBlock['CLASS_ID'])
2831 {
2832 return false;
2833 }
2834 if (isset($this->arControlList[$arLevel['CLASS_ID']]))
2835 {
2836 $arOneControl = $this->arControlList[$arLevel['CLASS_ID']];
2837 if ($arOneControl['GROUP'] == 'Y')
2838 {
2839 $arSubParams = $arParams;
2840 $arSubParams['FUNC_ID'] .= '_'.$intRowNum;
2841 $arSubEval = $this->GenerateLevel($arLevel['CHILDREN'], $arSubParams);
2842 if (false === $arSubEval || !is_array($arSubEval))
2843 return false;
2844 $arGroupParams = $arParams;
2845 $arGroupParams['FUNC_ID'] .= '_'.$intRowNum;
2846 $mxEval = call_user_func_array($arOneControl['Generate'],
2847 array($arLevel['DATA'], $arGroupParams, $arLevel['CLASS_ID'], $arSubEval)
2848 );
2849 if (is_array($mxEval))
2850 {
2851 if (isset($mxEval['FUNC']))
2852 {
2853 $this->arExecuteFunc[] = $mxEval['FUNC'];
2854 }
2855 $strEval = (isset($mxEval['COND']) ? $mxEval['COND'] : false);
2856 }
2857 else
2858 {
2859 $strEval = $mxEval;
2860 }
2861 }
2862 else
2863 {
2864 $strEval = call_user_func_array($arOneControl['Generate'],
2865 array($arLevel['DATA'], $arParams, $arLevel['CLASS_ID'])
2866 );
2867 }
2868 if ($strEval === false || !is_string($strEval) || $strEval === 'false')
2869 {
2870 return false;
2871 }
2872 $arResult[] = '('.$strEval.')';
2873 $this->fillUsedData($arOneControl);
2874 }
2875 }
2876 }
2877 else
2878 {
2879 foreach ($arLevel as $arOneCondition)
2880 {
2881 $arParams['ROW_NUM'] = $intRowNum;
2882 if (!empty($arOneCondition['CLASS_ID']))
2883 {
2884 if (isset($this->arControlList[$arOneCondition['CLASS_ID']]))
2885 {
2886 $arOneControl = $this->arControlList[$arOneCondition['CLASS_ID']];
2887 if ($arOneControl['GROUP'] == 'Y')
2888 {
2889 $arSubParams = $arParams;
2890 $arSubParams['FUNC_ID'] .= '_'.$intRowNum;
2891 $arSubEval = $this->GenerateLevel($arOneCondition['CHILDREN'], $arSubParams);
2892 if ($arSubEval === false || !is_array($arSubEval))
2893 return false;
2894 $arGroupParams = $arParams;
2895 $arGroupParams['FUNC_ID'] .= '_'.$intRowNum;
2896 $mxEval = call_user_func_array($arOneControl['Generate'],
2897 array($arOneCondition['DATA'], $arGroupParams, $arOneCondition['CLASS_ID'], $arSubEval)
2898 );
2899 if (is_array($mxEval))
2900 {
2901 if (isset($mxEval['FUNC']))
2902 {
2903 $this->arExecuteFunc[] = $mxEval['FUNC'];
2904 }
2905 $strEval = (isset($mxEval['COND']) ? $mxEval['COND'] : false);
2906 }
2907 else
2908 {
2909 $strEval = $mxEval;
2910 }
2911 }
2912 else
2913 {
2914 $strEval = call_user_func_array($arOneControl['Generate'],
2915 array($arOneCondition['DATA'], $arParams, $arOneCondition['CLASS_ID'])
2916 );
2917 }
2918 if ($strEval === false || !is_string($strEval) || $strEval === 'false')
2919 {
2920 return false;
2921 }
2922 $arResult[] = '('.$strEval.')';
2923 $this->fillUsedData($arOneControl);
2924 }
2925 }
2926 $intRowNum++;
2927 }
2928 unset($arOneCondition);
2929 }
2930
2931 if (!empty($arResult))
2932 {
2933 foreach ($arResult as $key => $value)
2934 {
2935 if ($value == '' || $value == '()')
2936 unset($arResult[$key]);
2937 }
2938 }
2939 if (!empty($arResult))
2940 $arResult = array_values($arResult);
2941
2942 return $arResult;
2943 }
2944
2945 public function GetExecuteModule()
2946 {
2947 return (!empty($this->executeModule) ? array_keys($this->executeModule) : array());
2948 }
2949
2950 protected function fillUsedData(&$control)
2951 {
2952 parent::fillUsedData($control);
2953 if (!empty($control['EXECUTE_MODULE']))
2954 $this->executeModule[$control['EXECUTE_MODULE']] = true;
2955 }
2956}
2957
2958class CSaleCondCumulativeCtrl extends \CSaleCondCtrlComplex
2959{
2960 const TYPE_ORDER_ARCHIVED = CumulativeCalculator::TYPE_ORDER_ARCHIVED;
2961 const TYPE_ORDER_NON_ARCHIVED = CumulativeCalculator::TYPE_ORDER_NON_ARCHIVED;
2962
2963 public static function onBuildDiscountConditionInterfaceControls()
2964 {
2965 return new EventResult(
2966 EventResult::SUCCESS,
2967 static::getControlDescr(),
2968 'sale'
2969 );
2970 }
2971
2972 public static function getControlDescr()
2973 {
2974 $description = parent::getControlDescr();
2975 $description['SORT'] = 700;
2976 return $description;
2977 }
2978
2979 public static function getControlShow($params)
2980 {
2981 $result = array(
2982 'controlgroup' => true,
2983 'group' => false,
2984 'label' => Loc::getMessage('BT_SALE_COND_GROUP_CUMULATIVE_COND_GROUP_TITLE'),
2985 'showIn' => static::getShowIn($params['SHOW_IN_GROUPS']),
2986 'children' => array()
2987 );
2988
2989 foreach (static::getControls() as $control)
2990 {
2991 $controlShow = array(
2992 'controlId' => $control['ID'],
2993 'group' => false,
2994 'label' => $control['LABEL'],
2995 'showIn' => static::getShowIn($params['SHOW_IN_GROUPS']),
2996 'control' => array()
2997 );
2998
2999 if ($controlShow['controlId'] === 'Period')
3000 {
3001 $controlShow['control'] = array(
3002 $control['PREFIX'],
3003 Loc::getMessage('BT_SALE_COND_GROUP_CUMULATIVE_COND_PERIOD_START'),
3004 $control['ATOMS']['ValueStart'],
3005 Loc::getMessage('BT_SALE_COND_GROUP_CUMULATIVE_COND_PERIOD_END'),
3006 $control['ATOMS']['ValueEnd'],
3007 );
3008 }
3009
3010 if ($controlShow['controlId'] === 'PeriodRelative')
3011 {
3012 $controlShow['control'] = array(
3013 $control['PREFIX'],
3014 $control['ATOMS']['Value'],
3015 $control['ATOMS']['TypeRelativePeriod'],
3016 );
3017 }
3018
3019 $result['children'][] = $controlShow;
3020 }
3021
3022 return $result;
3023 }
3024
3025 public static function GetConditionShow($arParams)
3026 {
3027 if (!isset($arParams['ID']))
3028 return false;
3029 $arControl = static::GetControls($arParams['ID']);
3030 if ($arControl === false)
3031 return false;
3032 $arControl['ATOMS'] = static::GetAtomsEx($arControl['ID'], true);
3033
3034 return static::CheckAtoms($arParams['DATA'], $arParams, $arControl, true);
3035 }
3036
3037 public static function generate($oneCondition, $params, $control, $subs = false)
3038 {
3039 if (is_string($control))
3040 {
3041 $control = static::getControls($control);
3042 }
3043
3044 if (!is_array($control))
3045 {
3046 return false;
3047 }
3048
3049 $control['ATOMS'] = static::GetAtomsEx($control['ID'], true);
3050 $params['COND_NUM'] = $params['FUNC_ID'];
3051
3052 $values = static::CheckAtoms($oneCondition, $params, $control, true);
3053 if ($values === false)
3054 {
3055 return false;
3056 }
3057
3058 //be careful! this conditions have to work only with CSaleCondCtrlBasketGroup because this class provide filter to
3059 //sum orders.
3060 return static::exportConfiguration($values);
3061 }
3062
3063 private static function exportConfiguration(array $configuration)
3064 {
3065 unset($configuration['id']);
3066
3067 $controlId = $configuration['controlId'];
3068 if ($controlId === 'Period')
3069 {
3070 if (!empty($configuration['values']['ValueStart']))
3071 {
3072 static::ConvertDateTime2Int(
3073 $configuration['values']['ValueStart'],
3074 'FULL',
3075 \CTimeZone::getOffset()
3076 );
3077 }
3078 if (!empty($configuration['values']['ValueEnd']))
3079 {
3080 static::ConvertDateTime2Int(
3081 $configuration['values']['ValueEnd'],
3082 'FULL',
3083 \CTimeZone::getOffset()
3084 );
3085 }
3086 }
3087
3088 return var_export($configuration, true);
3089 }
3090
3091 public static function getCumulativeValue($currentOrder, array $dataSumConfiguration = array())
3092 {
3093 if(empty($currentOrder['USER_ID']))
3094 {
3095 return false;
3096 }
3097
3098 $cumulativeCalculator = new CumulativeCalculator((int)$currentOrder['USER_ID'], $currentOrder['SITE_ID']);
3099 $cumulativeCalculator->setSumConfiguration(
3100 static::convertDataToSumConfiguration($dataSumConfiguration)
3101 );
3102
3103 return $cumulativeCalculator->calculate();
3104 }
3105
3106 protected static function convertDataToSumConfiguration(array $dataSumConfiguration)
3107 {
3108 $sumConfiguration = array(
3109 'type_sum_period' => CumulativeCalculator::TYPE_COUNT_PERIOD_ALL_TIME,
3110 );
3111
3112 $controlId = $dataSumConfiguration['controlId'];
3113 if ($controlId === 'Period')
3114 {
3115 $sumConfiguration['type_sum_period'] = CumulativeCalculator::TYPE_COUNT_PERIOD_INTERVAL;
3116 $sumConfiguration['sum_period_data'] = array(
3117 'order_start' => $dataSumConfiguration['values']['ValueStart'],
3118 'order_end' => $dataSumConfiguration['values']['ValueEnd'],
3119 );
3120 }
3121 elseif ($controlId == 'PeriodRelative')
3122 {
3123 $sumConfiguration['type_sum_period'] = CumulativeCalculator::TYPE_COUNT_PERIOD_RELATIVE;
3124 $sumConfiguration['sum_period_data'] = array(
3125 'period_value' => $dataSumConfiguration['values']['Value'],
3126 'period_type' => $dataSumConfiguration['values']['TypeRelativePeriod'],
3127 );
3128 }
3129
3130 return $sumConfiguration;
3131 }
3132
3138 public static function getControls($controlId = false)
3139 {
3140 $atoms = static::GetAtomsEx();
3141 $controlList = array(
3142 'Period' => array(
3143 'ID' => 'Period',
3144 'LABEL' => Loc::getMessage('BT_SALE_COND_GROUP_CUMULATIVE_COND_PERIOD'),
3145 'PREFIX' => Loc::getMessage('BT_SALE_COND_GROUP_CUMULATIVE_COND_PERIOD'),
3146 'ATOMS' => $atoms['Period']
3147 ),
3148 'PeriodRelative' => array(
3149 'ID' => 'PeriodRelative',
3150 'LABEL' => Loc::getMessage('BT_SALE_COND_GROUP_CUMULATIVE_COND_PERIOD_RELATIVE'),
3151 'PREFIX' => Loc::getMessage('BT_SALE_COND_GROUP_CUMULATIVE_COND_PERIOD_RELATIVE'),
3152 'ATOMS' => $atoms['PeriodRelative']
3153 ),
3154 );
3155
3156 if (false === $controlId)
3157 {
3158 return $controlList;
3159 }
3160 elseif (isset($controlList[$controlId]))
3161 {
3162 return $controlList[$controlId];
3163 }
3164 else
3165 {
3166 return false;
3167 }
3168 }
3169
3170 public static function getShowIn($arControls)
3171 {
3172 return array('CondCumulativeGroup');
3173 }
3174
3175 public static function Parse($arOneCondition)
3176 {
3177 if (!isset($arOneCondition['controlId']))
3178 return false;
3179 $arControl = static::GetControls($arOneCondition['controlId']);
3180 if ($arControl === false)
3181 return false;
3182 $arControl['ATOMS'] = static::GetAtomsEx($arControl['ID'], true);
3183
3184 $checkAtoms = static::CheckAtoms($arOneCondition, $arOneCondition, $arControl, false);
3185
3186 return $checkAtoms;
3187 }
3188
3189 public static function ConvertInt2DateTime(&$value, $format, $offset)
3190 {
3191 $error = false;
3192 if (is_array($value))
3193 {
3194 foreach ($value as $i => $piece)
3195 {
3196 if (static::ConvertInt2DateTime($piece, $format, $offset))
3197 {
3198 $error = true;
3199 }
3200 $value[$i] = $piece;
3201 }
3202
3203 return $error;
3204 }
3205 else
3206 {
3207 if (!$value)
3208 {
3209 return false;
3210 }
3211
3212 return parent::ConvertInt2DateTime($value, $format, $offset);
3213 }
3214 }
3215
3216 public static function ConvertDateTime2Int(&$value, $format, $offset)
3217 {
3218 $error = false;
3219 if (is_array($value))
3220 {
3221 foreach ($value as $i => $piece)
3222 {
3223 if (static::ConvertDateTime2Int($piece, $format, $offset))
3224 {
3225 $error = true;
3226 }
3227 $value[$i] = $piece;
3228 }
3229
3230 return $error;
3231 }
3232 else
3233 {
3234 if (!$value)
3235 {
3236 return false;
3237 }
3238
3239 return parent::ConvertDateTime2Int($value, $format, $offset);
3240 }
3241 }
3242
3243 public static function GetAtomsEx($strControlID = false, $boolEx = false)
3244 {
3245 $arAtomList = array(
3246 'Period' => array(
3247 'ValueStart' => array(
3248 'JS' => array(
3249 'id' => 'ValueStart',
3250 'name' => 'ValueStart',
3251 'type' => 'datetime',
3252 'format' => 'datetime'
3253 ),
3254 'ATOM' => array(
3255 'ID' => 'ValueStart',
3256 'FIELD_TYPE' => 'datetime',
3257 'MULTIPLE' => 'N'
3258 )
3259 ),
3260 'ValueEnd' => array(
3261 'JS' => array(
3262 'id' => 'ValueEnd',
3263 'name' => 'ValueEnd',
3264 'type' => 'datetime',
3265 'format' => 'datetime'
3266 ),
3267 'ATOM' => array(
3268 'ID' => 'ValueEnd',
3269 'FIELD_TYPE' => 'datetime',
3270 'MULTIPLE' => 'N'
3271 )
3272 )
3273 ),
3274 'PeriodRelative' => array(
3275 'Value' => array(
3276 'JS' => array(
3277 'id' => 'Value',
3278 'name' => 'Value',
3279 'type' => 'input',
3280 ),
3281 'ATOM' => array(
3282 'ID' => 'Value',
3283 'FIELD_TYPE' => 'int',
3284 'MULTIPLE' => 'N'
3285 )
3286 ),
3287 'TypeRelativePeriod' => array(
3288 'JS' => array(
3289 'id' => 'TypeRelativePeriod',
3290 'name' => 'TypeRelativePeriod',
3291 'type' => 'select',
3292 'values' => array(
3293 'Y' => Loc::getMessage('BT_SALE_COND_GROUP_CUMULATIVE_COND_PERIOD_RELATIVE_Y'),
3294 'M' => Loc::getMessage('BT_SALE_COND_GROUP_CUMULATIVE_COND_PERIOD_RELATIVE_M'),
3295 'D' => Loc::getMessage('BT_SALE_COND_GROUP_CUMULATIVE_COND_PERIOD_RELATIVE_D'),
3296 ),
3297 'defaultText' => '...',
3298 'defaultValue' => 'Y',
3299 'first_option' => '...'
3300 ),
3301 'ATOM' => array(
3302 'ID' => 'TypeRelativePeriod',
3303 'FIELD_TYPE' => 'char',
3304 'MULTIPLE' => 'N',
3305 'VALIDATE' => 'list'
3306 )
3307 )
3308 ),
3309 );
3310
3311 if (!$boolEx)
3312 {
3313 foreach ($arAtomList as &$arOneControl)
3314 {
3315 foreach ($arOneControl as &$arOneAtom)
3316 $arOneAtom = $arOneAtom['JS'];
3317 unset($arOneAtom);
3318 }
3319 unset($arOneControl);
3320 }
3321
3322 if ($strControlID === false)
3323 return $arAtomList;
3324 elseif (isset($arAtomList[$strControlID]))
3325 return $arAtomList[$strControlID];
3326 else
3327 return false;
3328 }
3329}
$arParams
Определения access_dialog.php:21
return select
Определения access_edit.php:440
$arResult
Определения generate_coupon.php:16
const BT_COND_LOGIC_CONT
Определения catalog_cond.php:15
const BT_COND_LOGIC_ELS
Определения catalog_cond.php:14
const BT_COND_LOGIC_EGR
Определения catalog_cond.php:13
const BT_COND_LOGIC_LS
Определения catalog_cond.php:12
const BT_COND_LOGIC_NOT_CONT
Определения catalog_cond.php:16
const BT_COND_LOGIC_NOT_EQ
Определения catalog_cond.php:10
const BT_COND_LOGIC_EQ
Определения catalog_cond.php:9
const BT_COND_LOGIC_GR
Определения catalog_cond.php:11
Определения loader.php:13
static getMessage($code, $replace=null, $language=null)
Определения loc.php:30
static getSiteCurrency($siteId)
Определения sitecurrency.php:96
const TYPE_SET
Определения basket.php:13
Определения catalog_cond.php:29
Определения sale_cond.php:15
static ProductFilter(&$arOrder, $func)
Определения sale_cond.php:116
static AmountBaseFilter(&$order, $func)
Определения sale_cond.php:50
static CountFilter(&$arOrder, $func)
Определения sale_cond.php:73
static AmountFilter(&$arOrder, $func)
Определения sale_cond.php:27
static ClearBasket($row)
Определения sale_cond.php:16
static BasketPropertyFilter($basketItem, $parameters)
Определения sale_cond.php:135
static RowFilter(&$arOrder, $func)
Определения sale_cond.php:98
static GetControlDescr()
Определения sale_cond.php:1336
static GetConditionShow($arParams)
Определения sale_cond.php:1424
static Generate($arOneCondition, $arParams, $arControl, $arSubs=false)
Определения sale_cond.php:1446
static Parse($arOneCondition)
Определения sale_cond.php:1435
const ENTITY_BASKET_POSITION_WEIGHT
Определения sale_cond.php:1334
static GetControlShow($arParams)
Определения sale_cond.php:1343
static GetControlDescr()
Определения sale_cond.php:216
static GetConditionShow($arParams)
Определения sale_cond.php:321
static Generate($arOneCondition, $arParams, $arControl, $arSubs=false)
Определения sale_cond.php:345
static GetControlID()
Определения sale_cond.php:203
static Parse($arOneCondition)
Определения sale_cond.php:333
static GetControls($strControlID=false)
Определения sale_cond.php:773
static GetAtomsEx($strControlID=false, $boolEx=false)
Определения sale_cond.php:397
static GetControlShow($arParams)
Определения sale_cond.php:253
const ENTITY_BASKET_POSITION_ACTION_APPLIED
Определения sale_cond.php:1707
static GetControlDescr()
Определения sale_cond.php:1845
const ENTITY_TYPE_NAME
Определения sale_cond.php:1842
const ENTITY_BASKET_PROPERTY
Определения sale_cond.php:1840
static GetAtomsEx($controlId=false, $extendedMode=false)
Определения sale_cond.php:1850
static GetShowIn($arControls)
Определения sale_cond.php:1959
const ENTITY_TYPE_CODE
Определения sale_cond.php:1843
static GetControls($controlId=false)
Определения sale_cond.php:1934
static Generate($condition, $params, $control, $childrens=false)
Определения sale_cond.php:1973
static GetControlDescr()
Определения sale_cond.php:188
static GetShowIn($arControls)
Определения sale_cond.php:195
Определения sale_cond.php:179
static GetControlDescr()
Определения sale_cond.php:2007
static Generate($arOneCondition, $arParams, $arControl, $arSubs=false)
Определения sale_cond.php:2100
static Parse($arOneCondition)
Определения sale_cond.php:2090
static GetControlShow($arParams)
Определения sale_cond.php:2014
Generate($arConditions, $arParams)
Определения sale_cond.php:2763
$arValues
Определения component_props.php:25
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$entity
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
$control
Определения iblock_catalog_edit.php:61
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
lang
Определения options.php:182
font size
Определения invoice.php:442
</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
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$arRes
Определения options.php:104
const SITE_ID
Определения sonet_set_content_view.php:12
$error
Определения subscription_card_product.php:20