1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sale_act.php
См. документацию.
1<?php
2
4
6{
7 public static function GetControlDescr()
8 {
9 $description = parent::GetControlDescr();
10 $description['SORT'] = 200;
11 return $description;
12 }
13
14 public static function GetControlShow($arParams)
15 {
16 $result = parent::GetControlShow($arParams);
17 $result['label'] = Loc::getMessage('BT_MOD_SALE_ACT_IBLOCK_CONTROLGROUP_LABEL');
18 return $result;
19 }
20
21 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
22 {
23 $strParentResult = '';
24 $strResult = '';
25 $parentResultValues = array();
26 $resultValues = array();
27
28 if (is_string($arControl))
29 {
30 $arControl = static::GetControls($arControl);
31 }
32 $boolError = !is_array($arControl);
33
34 $arValues = array();
35 if (!$boolError)
36 {
37 $arValues = static::Check($arOneCondition, $arOneCondition, $arControl, false);
38 $boolError = ($arValues === false);
39 }
40
41 if (!$boolError)
42 {
43 $arLogic = static::SearchLogic($arValues['logic'], $arControl['LOGIC']);
44 if (!isset($arLogic['OP'][$arControl['MULTIPLE']]) || empty($arLogic['OP'][$arControl['MULTIPLE']]))
45 {
46 $boolError = true;
47 }
48 else
49 {
50 $useParent = ($arControl['PARENT'] && isset($arLogic['PARENT']));
51 $strParent = $arParams['BASKET_ROW'].'[\'CATALOG\'][\'PARENT_'.$arControl['FIELD'].'\']';
52 $strField = $arParams['BASKET_ROW'].'[\'CATALOG\'][\''.$arControl['FIELD'].'\']';
53 switch ($arControl['FIELD_TYPE'])
54 {
55 case 'int':
56 case 'double':
57 if (is_array($arValues['value']))
58 {
59 if (!isset($arLogic['MULTI_SEP']))
60 {
61 $boolError = true;
62 }
63 else
64 {
65 foreach ($arValues['value'] as &$value)
66 {
67 if ($useParent)
68 $parentResultValues[] = str_replace(
69 array('#FIELD#', '#VALUE#'),
70 array($strParent, $value),
71 $arLogic['OP'][$arControl['MULTIPLE']]
72 );
73 $resultValues[] = str_replace(
74 array('#FIELD#', '#VALUE#'),
75 array($strField, $value),
76 $arLogic['OP'][$arControl['MULTIPLE']]
77 );
78 }
79 unset($value);
80 if ($useParent)
81 $strParentResult = '('.implode($arLogic['MULTI_SEP'], $parentResultValues).')';
82 $strResult = '('.implode($arLogic['MULTI_SEP'], $resultValues).')';
83 unset($resultValues, $parentResultValues);
84 }
85 }
86 else
87 {
88 if ($useParent)
89 $strParentResult = str_replace(
90 array('#FIELD#', '#VALUE#'),
91 array($strParent, $arValues['value']),
92 $arLogic['OP'][$arControl['MULTIPLE']]
93 );
94 $strResult = str_replace(
95 array('#FIELD#', '#VALUE#'),
96 array($strField, $arValues['value']),
97 $arLogic['OP'][$arControl['MULTIPLE']]
98 );
99 }
100 break;
101 case 'char':
102 case 'string':
103 case 'text':
104 if (is_array($arValues['value']))
105 {
106 $boolError = true;
107 }
108 else
109 {
110 if ($useParent)
111 $strParentResult = str_replace(
112 array('#FIELD#', '#VALUE#'),
113 array($strParent, '"'.EscapePHPString($arValues['value']).'"'),
114 $arLogic['OP'][$arControl['MULTIPLE']]
115 );
116 $strResult = str_replace(
117 array('#FIELD#', '#VALUE#'),
118 array($strField, '"'.EscapePHPString($arValues['value']).'"'),
119 $arLogic['OP'][$arControl['MULTIPLE']]
120 );
121 }
122 break;
123 case 'date':
124 case 'datetime':
125 if (is_array($arValues['value']))
126 {
127 $boolError = true;
128 }
129 else
130 {
131 if ($useParent)
132 $strParentResult = str_replace(
133 array('#FIELD#', '#VALUE#'),
134 array($strParent, $arValues['value']),
135 $arLogic['OP'][$arControl['MULTIPLE']]
136 );
137 $strResult = str_replace(
138 array('#FIELD#', '#VALUE#'),
139 array($strField, $arValues['value']),
140 $arLogic['OP'][$arControl['MULTIPLE']]
141 );
142 }
143 break;
144 }
145
146 $strResult = 'isset('.$strField.') && '.$strResult;
147 if ($useParent)
148 $strResult = 'isset('.$strParent.') ? (('.$strResult.')'.$arLogic['PARENT'].$strParentResult.') : ('.$strResult.')';
149 $strResult = '('.$strResult.')';
150 }
151 }
152
153 return (!$boolError ? $strResult : false);
154 }
155
156 public static function GetShowIn($arControls)
157 {
158 $key = array_search(CSaleActionCtrlAction::GetControlID(), $arControls);
159 if (false !== $key)
160 {
161 unset($arControls[$key]);
162 $arControls = array_values($arControls);
163 }
164 return $arControls;
165 }
166
171 public static function GetControls($strControlID = false)
172 {
173 $priceTypeList = array();
174 foreach (\CCatalogGroup::GetListArray() as $priceType)
175 {
176 $priceType['ID'] = (int)$priceType['ID'];
177 $priceType['NAME_LANG'] = (string)$priceType['NAME_LANG'];
178 $priceTypeList[$priceType['ID']] = $priceType['NAME'].($priceType['NAME_LANG'] != '' ? ' ('.$priceType['NAME_LANG'].')' : '');
179 }
180 unset($priceType);
181
182 $priceTypeLogic = array(
183 BT_COND_LOGIC_EQ => Loc::getMessage('BT_MOD_SALE_ACT_CATALOG_PRICE_TYPE_LOGIC_EQ_LABEL'),
184 BT_COND_LOGIC_NOT_EQ => Loc::getMessage('BT_MOD_SALE_ACT_CATALOG_PRICE_TYPE_LOGIC_NOT_EQ_LABEL'),
185 );
186
187 $controls = parent::GetControls(false);
188
189 $controls['CondCatalogPriceType'] = array(
190 'ID' => 'CondCatalogPriceType',
191 'PARENT' => false,
192 'EXECUTE_MODULE' => 'catalog',
193 'EXIST_HANDLER' => 'Y',
194 'MODULE_ID' => 'catalog',
195 'MODULE_ENTITY' => 'catalog',
196 'ENTITY' => 'PRICE',
197 'FIELD' => 'CATALOG_GROUP_ID',
198 'FIELD_TABLE' => 'CATALOG_GROUP_ID',
199 'FIELD_TYPE' => 'int',
200 'MULTIPLE' => 'N',
201 'GROUP' => 'N',
202 'LABEL' => Loc::getMessage('BT_MOD_SALE_ACT_CATALOG_PRICE_TYPE_LABEL'),
203 'PREFIX' => Loc::getMessage('BT_MOD_SALE_ACT_CATALOG_PRICE_TYPE_PREFIX'),
204 'LOGIC' => static::GetLogicEx(array_keys($priceTypeLogic), $priceTypeLogic),
205 'JS_VALUE' => array(
206 'type' => 'select',
207 'values' => $priceTypeList,
208 'multiple' => 'Y',
209 'show_value' => 'Y',
210 ),
211 'PHP_VALUE' => array(
212 'VALIDATE' => 'list'
213 )
214 );
215
216 return static::searchControl($controls, $strControlID);
217 }
218
222 public static function GetControlID()
223 {
224 $result = parent::GetControlID();
225 $result[] = 'CondCatalogPriceType';
226 return $result;
227 }
228}
229
230class CCatalogActionCtrlBasketProductProps extends CCatalogCondCtrlIBlockProps
231{
232 public static function GetControlDescr()
233 {
234 $description = parent::GetControlDescr();
235 $description['SORT'] = 300;
236 return $description;
237 }
238
239 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
240 {
241 $strResult = '';
242 $resultValues = array();
243 $arValues = false;
244
245 if (is_string($arControl))
246 {
247 $arControl = static::GetControls($arControl);
248 }
249 $boolError = !is_array($arControl);
250
251 if (!$boolError)
252 {
253 $arValues = static::Check($arOneCondition, $arOneCondition, $arControl, false);
254 $boolError = ($arValues === false);
255 }
256
257 if (!$boolError)
258 {
259 $arLogic = static::SearchLogic($arValues['logic'], $arControl['LOGIC']);
260 if (!isset($arLogic['OP'][$arControl['MULTIPLE']]) || empty($arLogic['OP'][$arControl['MULTIPLE']]))
261 {
262 $boolError = true;
263 }
264 else
265 {
266 $strField = $arParams['BASKET_ROW'].'[\'CATALOG\'][\''.$arControl['FIELD'].'\']';
267 switch ($arControl['FIELD_TYPE'])
268 {
269 case 'int':
270 case 'double':
271 if (is_array($arValues['value']))
272 {
273 if (!isset($arLogic['MULTI_SEP']))
274 {
275 $boolError = true;
276 }
277 else
278 {
279 foreach ($arValues['value'] as &$value)
280 {
281 $resultValues[] = str_replace(
282 array('#FIELD#', '#VALUE#'),
283 array($strField, $value),
284 $arLogic['OP'][$arControl['MULTIPLE']]
285 );
286 }
287 unset($value);
288 $strResult = '('.implode($arLogic['MULTI_SEP'], $resultValues).')';
289 unset($resultValues);
290 }
291 }
292 else
293 {
294 $strResult = str_replace(
295 array('#FIELD#', '#VALUE#'),
296 array($strField, $arValues['value']),
297 $arLogic['OP'][$arControl['MULTIPLE']]
298 );
299 }
300 break;
301 case 'char':
302 case 'string':
303 case 'text':
304 if (is_array($arValues['value']))
305 {
306 $boolError = true;
307 }
308 else
309 {
310 $strResult = str_replace(
311 array('#FIELD#', '#VALUE#'),
312 array($strField, '"'.EscapePHPString($arValues['value']).'"'),
313 $arLogic['OP'][$arControl['MULTIPLE']]
314 );
315 }
316 break;
317 case 'date':
318 case 'datetime':
319 if (is_array($arValues['value']))
320 {
321 $boolError = true;
322 }
323 else
324 {
325 $strResult = str_replace(
326 array('#FIELD#', '#VALUE#'),
327 array($strField, $arValues['value']),
328 $arLogic['OP'][$arControl['MULTIPLE']]
329 );
330 }
331 break;
332 }
333 $strResult = '(isset('.$strField.') && '.$strResult.')';
334 }
335 }
336
337 return (!$boolError ? $strResult : false);
338 }
339
340 public static function GetShowIn($arControls)
341 {
342 $key = array_search(CSaleActionCtrlAction::GetControlID(), $arControls);
343 if (false !== $key)
344 {
345 unset($arControls[$key]);
346 $arControls = array_values($arControls);
347 }
348 return $arControls;
349 }
350
351}
352
353class CCatalogGifterProduct extends CGlobalCondCtrlAtoms
354{
355 public static function GetShowIn($params)
356 {
357 return array();
358 }
359
360 public static function Generate($arOneCondition, $arParams, $arControl, $arSubs = false)
361 {
362 $result = '';
363 if (is_string($arControl))
364 $arControl = static::GetControls($arControl);
365 $boolError = !is_array($arControl);
366
367 if (!$boolError)
368 {
369 $arControl['ATOMS'] = static::GetAtomsEx($arControl['ID'], true);
370 $arValues = static::CheckAtoms($arOneCondition, $arOneCondition, $arControl, false);
371 $boolError = ($arValues === false);
372 }
373
374 if (!$boolError)
375 {
376 if (!is_array($arOneCondition['Value']))
377 $arOneCondition['Value'] = array($arOneCondition['Value']);
378 $stringDataArray = 'array('.implode(',', $arOneCondition['Value']).')';
379 $type = $arOneCondition['Type'];
380
381 $result = static::GetClassName() . "::GenerateApplyCallableFilter('{$arControl['ID']}', {$stringDataArray}, '{$type}')";
382 }
383
384 return $result;
385 }
386
387 public static function GetControls($strControlID = false)
388 {
389 $arAtoms = static::GetAtomsEx(false, false);
390 $arControlList = array(
391 'GifterCondIBElement' => array(
392 'ID' => 'GifterCondIBElement',
393 'PARENT' => true,
394 'FIELD' => 'ID',
395 'FIELD_TYPE' => 'int',
396 'LABEL' => Loc::getMessage('BT_MOD_SALE_ACT_IBLOCK_ELEMENT_ID_LABEL'),
397 'PREFIX' => Loc::getMessage('BT_MOD_SALE_ACT_IBLOCK_ELEMENT_ID_LABEL'),
398 'ATOMS' => $arAtoms['GifterCondIBElement'],
399 ),
400 'GifterCondIBSection' => array(
401 'ID' => 'GifterCondIBSection',
402 'PARENT' => false,
403 'FIELD' => 'SECTION_ID',
404 'FIELD_TYPE' => 'int',
405 'LABEL' => Loc::getMessage('BT_MOD_SALE_ACT_IBLOCK_SECTION_ID_LABEL'),
406 'PREFIX' => Loc::getMessage('BT_MOD_SALE_ACT_IBLOCK_SECTION_ID_LABEL'),
407 'ATOMS' => $arAtoms['GifterCondIBSection'],
408 ),
409 );
410
411 foreach ($arControlList as &$control)
412 {
413 $control['EXIST_HANDLER'] = 'Y';
414 $control['MODULE_ID'] = 'catalog';
415 $control['MODULE_ENTITY'] = 'iblock';
416 $control['ENTITY'] = 'ELEMENT';
417 }
418 unset($control);
419
420 if ($strControlID === false)
421 {
422 return $arControlList;
423 }
424 elseif (isset($arControlList[$strControlID]))
425 {
426 return $arControlList[$strControlID];
427 }
428 else
429 {
430 return false;
431 }
432 }
433
434 public static function GetAtomsEx($strControlID = false, $boolEx = false)
435 {
436 $atomList = array(
437 'GifterCondIBElement' => array(
438 'Type' => array(
439 'JS' => array(
440 'id' => 'Type',
441 'name' => 'Type',
442 'type' => 'select',
443 'values' => array(
444 CSaleDiscountActionApply::GIFT_SELECT_TYPE_ONE => Loc::getMessage('BT_SALE_ACT_GIFT_SELECT_TYPE_SELECT_ONE'),
445 CSaleDiscountActionApply::GIFT_SELECT_TYPE_ALL => Loc::getMessage('BT_SALE_ACT_GIFT_SELECT_TYPE_SELECT_ALL'),
446 ),
447 'defaultText' => Loc::getMessage('BT_SALE_ACT_GIFT_SELECT_TYPE_SELECT_DEF'),
448 'defaultValue' => CSaleDiscountActionApply::GIFT_SELECT_TYPE_ONE,
449 'first_option' => '...'
450 ),
451 'ATOM' => array(
452 'ID' => 'Type',
453 'FIELD_TYPE' => 'string',
454 'FIELD_LENGTH' => 255,
455 'MULTIPLE' => 'N',
456 'VALIDATE' => 'list'
457 )
458 ),
459 'Value' => array(
460 'JS' => array(
461 'id' => 'Value',
462 'name' => 'Value',
463 'type' => 'multiDialog',
464 'popup_url' => self::getAdminSection().'cat_product_search_dialog.php',
465 'popup_params' => array(
466 'lang' => LANGUAGE_ID,
467 'caller' => 'discount_rules',
468 'allow_select_parent' => 'Y',
469 ),
470 'param_id' => 'n',
471 'show_value' => 'Y'
472 ),
473 'ATOM' => array(
474 'ID' => 'Value',
475 'FIELD_TYPE' => 'int',
476 'MULTIPLE' => 'Y',
477 'VALIDATE' => 'element'
478 )
479 )
480 ),
481 'GifterCondIBSection' => array(
482 'Type' => array(
483 'JS' => array(
484 'id' => 'Type',
485 'name' => 'Type',
486 'type' => 'select',
487 'values' => array(
488 CSaleDiscountActionApply::GIFT_SELECT_TYPE_ONE => Loc::getMessage('BT_SALE_ACT_GIFT_SELECT_TYPE_SELECT_ONE'),
489 CSaleDiscountActionApply::GIFT_SELECT_TYPE_ALL => Loc::getMessage('BT_SALE_ACT_GIFT_SELECT_TYPE_SELECT_ALL'),
490 ),
491 'defaultText' => Loc::getMessage('BT_SALE_ACT_GIFT_SELECT_TYPE_SELECT_DEF'),
492 'defaultValue' => CSaleDiscountActionApply::GIFT_SELECT_TYPE_ONE,
493 'first_option' => '...'
494 ),
495 'ATOM' => array(
496 'ID' => 'Type',
497 'FIELD_TYPE' => 'string',
498 'FIELD_LENGTH' => 255,
499 'MULTIPLE' => 'N',
500 'VALIDATE' => 'list'
501 )
502 ),
503 'Value' => array(
504 'JS' => array(
505 'id' => 'Value',
506 'name' => 'Value',
507 'type' => 'popup',
508 'popup_url' => self::getAdminSection().'iblock_section_search.php',
509 'popup_params' => array(
510 'lang' => LANGUAGE_ID,
511 'discount' => 'Y',
512 'simplename' => 'Y'
513 ),
514 'param_id' => 'n',
515 'show_value' => 'Y',
516 ),
517 'ATOM' => array(
518 'ID' => 'Value',
519 'FIELD_TYPE' => 'int',
520 'MULTIPLE' => 'N',
521 'VALIDATE' => 'section'
522 )
523 )
524 )
525 );
526
527 return static::searchControlAtoms($atomList, $strControlID, $boolEx);
528 }
529
530 public static function GenerateApplyCallableFilter($controlId, array $gifts, $type)
531 {
532 $gifts = array_combine($gifts, $gifts);
533 return function($row) use($controlId, $gifts, $type)
534 {
535 static $isApplied = false;
536 if($isApplied && $type === CSaleDiscountActionApply::GIFT_SELECT_TYPE_ONE)
537 {
538 return false;
539 }
540 $right = false;
541 switch($controlId)
542 {
543 case 'GifterCondIBElement':
544 $right =
545 (
546 (isset($row['CATALOG']['PARENT_ID']) && array_intersect($gifts, (array)$row['CATALOG']['PARENT_ID'])) ||
547 (isset($row['CATALOG']['ID']) && isset($gifts[$row['CATALOG']['ID']]))
548 ) &&
549 isset($row['QUANTITY']) && $row['QUANTITY'] == \CCatalogGifterProduct::getRatio($row['CATALOG']['ID'])
550 && isset($row['PRICE']) && $row['PRICE'] > 0
551 ;
552 break;
553
554 case 'GifterCondIBSection':
555 $right =
556 (
557 isset($row['CATALOG']['SECTION_ID']) && array_intersect($gifts, (array)$row['CATALOG']['SECTION_ID'])
558 ) &&
559 isset($row['QUANTITY']) && $row['QUANTITY'] == \CCatalogGifterProduct::getRatio($row['CATALOG']['ID'])
560 && isset($row['PRICE']) && $row['PRICE'] > 0
561 ;
562
563 break;
564 }
565
566 if($right)
567 {
568 $isApplied = true;
569 }
570
571 return $right;
572 };
573 }
574
575 public static function getRatio($productId)
576 {
577 if (!\Bitrix\Main\Loader::includeModule('catalog'))
578 {
579 return 1;
580 }
581
582 $ratio = \Bitrix\Catalog\MeasureRatioTable::getList(
583 array(
584 'select' => array('RATIO'),
585 'filter' => array('PRODUCT_ID' => $productId, '=IS_DEFAULT' => 'Y')
586 )
587 )->fetch();
588
589 return empty($ratio['RATIO'])? 1 : $ratio['RATIO'];
590 }
591
592 public static function ProvideGiftData(array $actionData)
593 {
594 $type = $actionData['DATA']['Type'];
595 $values = (array)$actionData['DATA']['Value'];
596
597 switch($actionData['CLASS_ID'])
598 {
599 case 'GifterCondIBElement':
600 return array(
601 'Type' => $type,
602 'GiftValue' => $values,
603 );
604 case 'GifterCondIBSection':
605 return array(
606 'Type' => $type,
607 'GiftValue' => static::GetProductIdsBySection(array_pop($values)),
608 );
609 }
610
611 return array();
612 }
613
614 protected static function GetProductIdsBySection($sectionId)
615 {
616 if(!\Bitrix\Main\Loader::includeModule('iblock'))
617 {
618 return array();
619 }
620 $ids = array();
621 $query = CIBlockElement::getList(array(), array(
622 'ACTIVE_DATE' => 'Y',
623 'SECTION_ID' => $sectionId,
624 'CHECK_PERMISSIONS' => 'Y',
625 'MIN_PERMISSION' => 'R',
626 'ACTIVE' => 'Y',
627 ), false, false, array('ID'));
628
629 while($row = $query->fetch())
630 {
631 $ids[] = $row['ID'];
632 }
633
634 return $ids;
635 }
636
637 public static function ExtendProductIds(array $giftedProductIds)
638 {
639 $products = CCatalogSku::getProductList($giftedProductIds);
640 if (empty($products))
641 return $giftedProductIds;
642
643 foreach($products as $product)
644 $giftedProductIds[] = $product['ID'];
645 unset($product);
646
647 return $giftedProductIds;
648 }
649
653 private static function getAdminSection()
654 {
655 //TODO: need use \CAdminPage::getSelfFolderUrl, but in general it is impossible now
656 return (defined('SELF_FOLDER_URL') ? SELF_FOLDER_URL : '/bitrix/admin/');
657 }
658}
$arParams
Определения access_dialog.php:21
return select
Определения access_edit.php:440
$type
Определения options.php:106
static GetControlDescr()
Определения sale_act.php:7
static Generate($arOneCondition, $arParams, $arControl, $arSubs=false)
Определения sale_act.php:21
static GetControlShow($arParams)
Определения sale_act.php:14
$arValues
Определения component_props.php:25
</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
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
lang
Определения options.php:182