1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
basepreset.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\Discount\Preset;
4
5use Bitrix\Crm\Order\BuyerGroup;
6use Bitrix\Main;
7use Bitrix\Main\Config\Option;
8use Bitrix\Main\Context;
9use Bitrix\Main\Error;
10use Bitrix\Main\ErrorCollection;
11use Bitrix\Main\Loader;
12use Bitrix\Main\Localization\Loc;
13use Bitrix\Main\SiteTable;
14use Bitrix\Main\SystemException;
15use Bitrix\Main\Web\Json;
16use Bitrix\Sale\Helpers\Admin\Blocks\OrderBasket;
17use Bitrix\Sale\Internals\DiscountGroupTable;
18
19abstract class BasePreset
20{
21 public const FINAL_STEP = 'FINALSTEP';
22 public const STEP_NAME_VAR = '__next_step';
23
24 public const RUN_PREV_STEP_NAME_VAR = '__run_prev_step';
25
26 public const MODE_SHOW = 2;
27 public const MODE_SAVE = 3;
28
29 public const ACTION_TYPE_DISCOUNT = 'Discount';
30 public const ACTION_TYPE_EXTRA = 'Extra';
31
32 public const AVAILABLE_STATE_ALLOW = 0x01;
33 public const AVAILABLE_STATE_DISALLOW = 0x02;
34 public const AVAILABLE_STATE_TARIFF = 0x04;
35
39 protected $request;
41 protected $nextStep;
43 protected $stepTitle;
47 private $stepResult;
49 private $stepResultState;
51 private array $discount;
53 private bool $restrictedGroupsMode = false;
54
56 protected bool $bitrix24Included;
57
61 public static function className()
62 {
63 return get_called_class();
64 }
65
70 public static function classShortName(BasePreset $classObject)
71 {
72 return (new \ReflectionClass($classObject))->getShortName();
73 }
74
75 public function __construct()
76 {
77 $this->errorCollection = new ErrorCollection;
78 $this->request = Context::getCurrent()->getRequest();
79 $this->bitrix24Included = Loader::includeModule('bitrix24');
80
81 $this->init();
82 }
83
84 public function enableRestrictedGroupsMode($state)
85 {
86 $this->restrictedGroupsMode = $state === true;
87 }
88
90 {
91 return $this->restrictedGroupsMode;
92 }
93
94 protected function init()
95 {}
96
97 public function hasErrors()
98 {
99 return !$this->errorCollection->isEmpty();
100 }
101
105 public function getErrors()
106 {
107 return $this->errorCollection->toArray();
108 }
109
110 public function getStepNumber()
111 {
112 if ($this->stepResultState)
113 {
114 return $this->stepResultState->getStepNumber();
115 }
116
117 return 1;
118 }
119
123 protected function getState()
124 {
125 return State::createFromRequest($this->request);
126 }
127
128 public function getView()
129 {
130 return
131 $this->beginForm($this->stepResultState)
132 . $this->stepResult
133 . $this->endForm($this->stepResultState)
134 ;
135 }
136
137 protected function isRunningPrevStep()
138 {
139 return (bool)$this->request->getPost(static::RUN_PREV_STEP_NAME_VAR);
140 }
141
142 public function executeAjaxAction($actionName)
143 {
144 $methodName = 'processAjaxAction' . $actionName;
145 if (!method_exists($this, $methodName))
146 {
147 throw new SystemException("Could not find method {$methodName}");
148 }
149
150 $result = call_user_func_array([$this, $methodName], []);
151
152 header('Content-Type:application/json; charset=UTF-8');
153 \CMain::FinalActions(Json::encode($result));
154 }
155
157 {
158 $productId = !empty($params['productId']) ? $params['productId'] : $this->request->get('productId');
159 if (is_array($productId))
160 {
161 $productId = array_pop($productId);
162 }
163
164 $quantity = !empty($params['quantity']) ? $params['quantity'] : $this->request->get('quantity');
165 $quantity = (float)$quantity;
166
167 $siteId = !empty($params['siteId']) ? $params['siteId'] : $this->request->get('siteId');
168 $siteId = (string)$siteId;
169
170 global $USER;
171 $userId = $USER->getId();
172
173 if (empty($productId))
174 {
175 throw new SystemException("Could not find product id");
176 }
177 if (empty($quantity))
178 {
179 $quantity = 1;
180 }
181
182 $productDetails = OrderBasket::getProductDetails($productId, $quantity, $userId, $siteId);
183 if (!$productDetails || empty($productDetails['PRODUCT_ID']))
184 {
185 return $this->getProductInfo($productId);
186 }
187
188 return $productDetails;
189 }
190
191 private function getProductInfo($elementId): array
192 {
193 $elementId = (int)$elementId;
194 if ($elementId <= 0)
195 {
196 return [];
197 }
198
199 $dbProduct = \CIBlockElement::getList(
200 [],
201 ['ID' => $elementId],
202 false,
203 false,
204 [
205 'ID',
206 'IBLOCK_ID',
207 'IBLOCK_SECTION_ID',
208 'DETAIL_PICTURE',
209 'PREVIEW_PICTURE',
210 'NAME',
211 'XML_ID',
212 ]
213 );
214 $product = $dbProduct->fetch();
215 unset($dbProduct);
216 if (empty($product))
217 {
218 return [];
219 }
220
221 $imgCode = 0;
222 if ($product["IBLOCK_ID"] > 0)
223 {
224 $product["EDIT_PAGE_URL"] = \CIBlock::getAdminElementEditLink(
225 $product["IBLOCK_ID"],
226 $elementId,
227 ["find_section_section" => $product["IBLOCK_SECTION_ID"]]
228 );
229 }
230
231 if ($product["DETAIL_PICTURE"] > 0)
232 {
233 $imgCode = $product["DETAIL_PICTURE"];
234 }
235 elseif ($product["PREVIEW_PICTURE"] > 0)
236 {
237 $imgCode = $product["PREVIEW_PICTURE"];
238 }
239
240 if ($imgCode > 0)
241 {
242 $imgProduct = \CFile::resizeImageGet(
243 \CFile::getFileArray($imgCode),
244 [
245 'width' => 80,
246 'height' => 80,
247 ],
249 false,
250 false
251 );
252 $product["PICTURE_URL"] = $imgProduct['src'];
253 }
254 $product['PRODUCT_ID'] = $product['ID'];
255
256 return $product;
257 }
258
259 public function exec()
260 {
261 $isPost = $this->request->isPost();
262
263 $stepName = $this->getStepName();
264 $state = $this->getState();
265
266 //edit existing discount
267 if ($stepName === $this->getFirstStepName() && !$isPost && $this->isDiscountEditing())
268 {
269 $state = $this->generateState($this->discount);
270 }
271
272 if ($this->isRunningPrevStep())
273 {
274 $stepName = $state->getPrevStep();
275 }
276
277 if ($isPost && !$this->isRunningPrevStep())
278 {
280 list($state, $nextStep) = $this->runStep($stepName, $state, self::MODE_SAVE);
281
282 if ($stepName != $nextStep)
283 {
284 $state->addStepChain($stepName);
285 }
286
287 $this->setNextStep($nextStep);
288 if ($nextStep === static::FINAL_STEP)
289 {
290 $discountFields = $this->generateDiscount($state);
291
292 if ($this->isDiscountEditing())
293 {
294 $this->updateDiscount($this->discount['ID'], $discountFields);
295 }
296 else
297 {
298 $this->addDiscount($discountFields);
299 }
300
301 if ($this->hasErrors())
302 {
303 $step = $state->popStepChain();
304 $stepName = $step;
305
306 $this->setNextStep($step);
307 }
308 }
309
310 if (!$this->hasErrors())
311 {
312 $stepName = $nextStep;
313 }
314 }
315 elseif ($this->isRunningPrevStep())
316 {
317 $step = $state->popStepChain();
318
319 $this->setNextStep($step);
320 }
321
322 $this->stepResult = $this->runStep($stepName, $state, self::MODE_SHOW);
323 $this->stepResultState = $state;
324
325 return $this;
326 }
327
328 private function runStep($actionName, State $state, $mode = self::MODE_SHOW)
329 {
330 $methodName = '';
331 if ($mode === self::MODE_SHOW)
332 {
333 $methodName = 'processShow' . $actionName;
334 }
335 elseif ($mode === self::MODE_SAVE)
336 {
337 $methodName = 'processSave' . $actionName;
338 }
339
340 if (!$methodName)
341 {
342 throw new SystemException("Unknown mode {$mode}");
343 }
344
345 if (!method_exists($this, $methodName))
346 {
347 throw new SystemException("Method {$methodName} is not exist");
348 }
349
350 return call_user_func_array(array($this, $methodName), array($state));
351 }
352
353 private function getStepName()
354 {
355 return $this->request->getPost(static::STEP_NAME_VAR) ?: static::getFirstStepName();
356 }
357
361 public function getDiscount()
362 {
363 return
364 $this->discount ?? []
365 ;
366 }
367
368 protected function isDiscountEditing()
369 {
370 return !empty($this->discount);
371 }
372
377 public function setDiscount($discount)
378 {
379 if (!is_array($discount))
380 {
381 $discount = [];
382 }
383
384 $this->discount = $this->prepareDiscountFields($discount);
385
386 return $this;
387 }
388
392 public function getStepTitle()
393 {
394 return $this->stepTitle;
395 }
396
400 public function setStepTitle($stepTitle)
401 {
402 $this->stepTitle = $stepTitle;
403 }
404
408 public function getStepDescription()
409 {
411 }
412
418 {
419 $this->stepDescription = $stepDescription;
420
421 return $this;
422 }
423
428 public function getSort()
429 {
430 return 100;
431 }
432
436 abstract public function getTitle();
437
446 public function isAvailable()
447 {
448 return $this->getAvailableState() === self::AVAILABLE_STATE_ALLOW;
449 }
450
451 public function getPossible(): bool
452 {
453 return $this->getAvailableState() !== self::AVAILABLE_STATE_DISALLOW;
454 }
455
456 public function getAvailableState(): int
457 {
458 return self::AVAILABLE_STATE_ALLOW;
459 }
460
461 public function getAvailableHelpLink(): ?array
462 {
463 return null;
464 }
465
469 abstract public function getDescription();
470
471 public function getExtendedDescription()
472 {
473 return [
474 'DISCOUNT_TYPE' => '',
475 'DISCOUNT_VALUE' => '',
476 'DISCOUNT_CONDITION' => '',
477 ];
478 }
479
483 abstract public function getFirstStepName();
484
488 public function getCategory()
489 {
491 }
492
496 public function getNextStep()
497 {
498 return $this->nextStep;
499 }
500
501 public function hasPrevStep()
502 {
503 $prevStep = $this->stepResultState->getPrevStep();
504
505 return $prevStep && $prevStep != $this->getNextStep() && !$this->isLastStep();
506 }
507
508 public function isLastStep()
509 {
510 return $this->getNextStep() == static::FINAL_STEP;
511 }
512
517 public function setNextStep($nextStep)
518 {
519 $this->nextStep = $nextStep;
520
521 return $this;
522 }
523
524 public function beginForm(State $state)
525 {
526 return '
527 <form action="' . htmlspecialcharsbx($this->request->getRequestUri()) . '"'
528 . ' enctype="multipart/form-data" method="post" name="__preset_form" id="__preset_form">'
529 . $state->toString()
530 . '<input type="hidden" name="' . static::STEP_NAME_VAR . '" id="' . static::STEP_NAME_VAR . '" value="' . htmlspecialcharsbx($this->getNextStep()) . '">
531 <input type="hidden" name="' . static::RUN_PREV_STEP_NAME_VAR . '" id="' . static::RUN_PREV_STEP_NAME_VAR . '" value="">
532 ' . bitrix_sessid_post() . '
533 <input type="hidden" name="lang" value="' . LANGUAGE_ID . '">
534 ';
535 }
536
537 public function endForm(State $state)
538 {
539 return '</form>';
540 }
541
542 protected function filterUserGroups(array $discountGroups)
543 {
545 {
546 if (Main\Loader::includeModule('crm'))
547 {
548 $existingGroups = [];
549
550 if ($this->isDiscountEditing())
551 {
552 $existingGroups = $this->getUserGroupsByDiscount($this->discount['ID']);
553 }
554
555 $discountGroups = BuyerGroup::prepareGroupIds($existingGroups, $discountGroups);
556 }
557 }
558
559 return $discountGroups;
560 }
561
566 public function generateDiscount(State $state)
567 {
568 $siteId = $state->get('discount_lid');
569
570 $discountGroups = $state->get('discount_groups') ?: [];
571 $userGroups = $this->filterUserGroups($discountGroups);
572
573 return [
574 'LID' => $siteId,
575 'NAME' => $state->get('discount_name'),
577 'ACTIVE_FROM' => $state->get('discount_active_from'),
578 'ACTIVE_TO' => $state->get('discount_active_to'),
579 'ACTIVE' => 'Y',
580 'SORT' => $state->get('discount_sort'),
581 'PRIORITY' => $state->get('discount_priority'),
582 'LAST_DISCOUNT' => $state->get('discount_last_discount'),
583 'LAST_LEVEL_DISCOUNT' => $state->get('discount_last_level_discount'),
584 'USER_GROUPS' => $userGroups,
585 ];
586 }
587
592 public function generateState(array $discountFields)
593 {
594 return new State([
595 'discount_id' => $discountFields['ID'],
596 'discount_lid' => $discountFields['LID'],
597 'discount_name' => $discountFields['NAME'],
598 'discount_active_from' => $discountFields['ACTIVE_FROM'],
599 'discount_active_to' => $discountFields['ACTIVE_TO'],
600 'discount_last_discount' => $discountFields['LAST_DISCOUNT'],
601 'discount_last_level_discount' => $discountFields['LAST_LEVEL_DISCOUNT'],
602 'discount_priority' => $discountFields['PRIORITY'],
603 'discount_sort' => $discountFields['SORT'],
604 'discount_groups' => $this->getUserGroupsByDiscount($discountFields['ID']),
605 ]);
606 }
607
608 final protected function normalizeDiscountFields(array $discountFields): array
609 {
610 if (isset($discountFields['CONDITIONS']) && is_array($discountFields['CONDITIONS']))
611 {
612 $discountFields['CONDITIONS_LIST'] = $discountFields['CONDITIONS'];
613 }
614
615 if (isset($discountFields['CONDITIONS_LIST']) && is_string($discountFields['CONDITIONS_LIST']))
616 {
617 $discountFields['CONDITIONS_LIST'] = unserialize($discountFields['CONDITIONS_LIST'], ['allowed_classes' => false]);
618 }
619
620 if (isset($discountFields['CONDITIONS_LIST']) && is_array($discountFields['CONDITIONS_LIST']))
621 {
622 $discountFields['CONDITIONS'] = $discountFields['CONDITIONS_LIST'];
623 }
624
625 if (isset($discountFields['ACTIONS']) && is_array($discountFields['ACTIONS']))
626 {
627 $discountFields['ACTIONS_LIST'] = $discountFields['ACTIONS'];
628 }
629
630 if (isset($discountFields['ACTIONS_LIST']) && is_string($discountFields['ACTIONS_LIST']))
631 {
632 $discountFields['ACTIONS_LIST'] = unserialize($discountFields['ACTIONS_LIST'], ['allowed_classes' => false]);
633 }
634
635 if (isset($discountFields['ACTIONS_LIST']) && is_array($discountFields['ACTIONS_LIST']))
636 {
637 $discountFields['ACTIONS'] = $discountFields['ACTIONS_LIST'];
638 }
639
640 if (isset($discountFields['PREDICTIONS_LIST']) && is_string($discountFields['PREDICTIONS_LIST']))
641 {
642 $discountFields['PREDICTIONS_LIST'] = unserialize($discountFields['PREDICTIONS_LIST'], ['allowed_classes' => false]);
643 }
644
645 if (isset($discountFields['PREDICTIONS_LIST']) && is_array($discountFields['PREDICTIONS_LIST']))
646 {
647 $discountFields['PREDICTIONS'] = $discountFields['PREDICTIONS_LIST'];
648 }
649
650 return $discountFields;
651 }
652
653 protected function updateDiscount($id, array $discountFields)
654 {
655 $discountFields['PRESET_ID'] = $this->className();
656
657 if (!\CSaleDiscount::update($id, $discountFields))
658 {
659 global $APPLICATION;
660 $ex = $APPLICATION->getException();
661 if ($ex)
662 {
663 $this->errorCollection[] = new Error($ex->getString());
664 }
665 else
666 {
667 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_DISCOUNT_EDIT_ERR_UPDATE'));
668 }
669 }
670 }
671
672 protected function addDiscount(array $discountFields)
673 {
674 $discountFields['PRESET_ID'] = $this->className();
675
676 $discountId = \CSaleDiscount::add($discountFields);
677
678 if ($discountId <= 0)
679 {
680 global $APPLICATION;
681 $ex = $APPLICATION->getException();
682 if ($ex)
683 {
684 $this->errorCollection[] = new Error($ex->getString());
685 }
686 else
687 {
688 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_DISCOUNT_EDIT_ERR_ADD'));
689 }
690 }
691 }
692
693 public function processShowFinalStep(State $state)
694 {
695 return Loc::getMessage(
696 'SALE_BASE_PRESET_FINAL_OK',
697 [
698 '#NAME#' => htmlspecialcharsbx($state->get('discount_name')),
699 ]
700 );
701 }
702
703 protected function getUserGroupsByDiscount($discountId)
704 {
705 $groups = [];
706 $groupDiscountIterator = DiscountGroupTable::getList([
707 'select' => [
708 'GROUP_ID',
709 ],
710 'filter' => [
711 'DISCOUNT_ID' => $discountId,
712 '=ACTIVE' => 'Y',
713 ],
714 ]);
715 while ($groupDiscount = $groupDiscountIterator->fetch())
716 {
717 $groups[] = (int)$groupDiscount['GROUP_ID'];
718 }
719 unset(
720 $groupDiscount,
721 $groupDiscountIterator,
722 );
723
724 return $groups;
725 }
726
727 protected function getSiteList(): array
728 {
729 return $this->getSaleSiteList() ?: $this->getFullSiteList();
730 }
731
732 private function getSaleSiteList(): array
733 {
734 $siteList = [];
735 $siteIterator = SiteTable::getList([
736 'select' => [
737 'LID',
738 'NAME',
739 'SORT',
740 ],
741 'filter' => [
742 '=ACTIVE' => 'Y',
743 ],
744 'order' => [
745 'SORT' => 'ASC',
746 ],
747 ]);
748 while ($site = $siteIterator->fetch())
749 {
750 $saleSite = Option::get('sale', 'SHOP_SITE_' . $site['LID']);
751 if ($site['LID'] == $saleSite)
752 {
753 $siteList[$site['LID']] = '(' . $site['LID'] . ') ' . $site['NAME'];
754 }
755 }
756 unset(
757 $site,
759 );
760
761 return $siteList;
762 }
763
764 private function getFullSiteList(): array
765 {
766 $siteList = [];
767 $siteIterator = SiteTable::getList([
768 'select' => [
769 'LID',
770 'NAME',
771 'SORT',
772 ],
773 'order' => [
774 'SORT' => 'ASC',
775 ],
776 ]);
777 while ($site = $siteIterator->fetch())
778 {
779 $siteList[$site['LID']] = '(' . $site['LID'] . ') ' . $site['NAME'];
780 }
781 unset(
782 $site,
784 );
785
786 return $siteList;
787 }
788
789 protected function processShowInputNameInternal(State $state)
790 {
791 return '
792 <table width="100%" border="0" cellspacing="7" cellpadding="0">
793 <tbody>
794 <tr>
795 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_BASE_PRESET_ORDERAMOUNT_FIELD_NAME') . ':</strong></td>
796 <td class="adm-detail-content-cell-r" style="width:60%;">
797 <input type="text" name="discount_name" value="' . htmlspecialcharsbx($state->get('discount_name')) . '" size="39" maxlength="100" style="width: 300px;">
798 </td>
799 </tr>
800 <tr>
801 <td class="adm-detail-content-cell-l"><strong>' . Loc::getMessage('SALE_BASE_PRESET_ORDERAMOUNT_LID') . ':</strong></td>
802 <td class="adm-detail-content-cell-r">
803 ' . HtmlHelper::generateSelect('discount_lid', $this->getSiteList(), $state->get('discount_lid')) . '
804 </td>
805 </tr>
806 </tbody>
807 </table>
808 ';
809 }
810
811 protected function processSaveInputNameInternal(State $state, $nextStep)
812 {
813 if (!trim($state->get('discount_name')))
814 {
815 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_ERROR_EMPTY_NAME'));
816 }
817
818 if (!trim($state->get('discount_lid')))
819 {
820 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_ERROR_EMPTY_LID'));
821 }
822
823 if (!$this->errorCollection->isEmpty())
824 {
825 return array($state, 'InputName');
826 }
827
828 return array($state, $nextStep);
829 }
830
831 protected function addErrorEmptyActionValue(): void
832 {
833 $this->errorCollection[] = new Error(Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_VALUE_MSGVER_1'));
834 }
835
836 protected function processShowCommonSettingsInternal(State $state)
837 {
838 $groupList = $this->getAllowableUserGroups();
839
840 switch (LANGUAGE_ID)
841 {
842 case 'en':
843 case 'ru':
844 case 'de':
845 $hintLastDiscountImageName = 'hint_last_discount_' . LANGUAGE_ID . '.png';
846 break;
847 default:
848 $hintLastDiscountImageName = 'hint_last_discount_' . Main\Localization\Loc::getDefaultLang(LANGUAGE_ID) . '.png';
849 break;
850 }
851
852 $periodValue = '';
853 if ($state->get('discount_active_from') || $state->get('discount_active_to'))
854 {
855 $periodValue = \CAdminCalendar::PERIOD_INTERVAL;
856 }
857
858 return '
859 <table width="100%" border="0" cellspacing="7" cellpadding="0">
860 <tbody>
861 <tr>
862 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_BASE_PRESET_ORDERAMOUNT_USER_GROUPS') . ':</strong></td>
863 <td class="adm-detail-content-cell-r">
864 ' . HtmlHelper::generateMultipleSelect('discount_groups[]', $groupList, $state->get('discount_groups', array()), array('size=8')) . '
865 </td>
866 </tr>
867 <tr>
868 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_BASE_PRESET_ACTIVE_PERIOD') . ':</strong></td>
869 <td class="adm-detail-content-cell-r">' .
871 'discount_active_from',
872 'discount_active_to',
873 $state->get('discount_active_from'),
874 $state->get('discount_active_to'),
875 true,
876 19,
877 true,
878 array(
879 \CAdminCalendar::PERIOD_EMPTY => Loc::getMessage('SALE_BASE_PRESET_CALENDAR_PERIOD_EMPTY'),
880 \CAdminCalendar::PERIOD_INTERVAL => Loc::getMessage('SALE_BASE_PRESET_CALENDAR_PERIOD_INTERVAL')
881 ),
882 $periodValue
883 ) . '
884 </td>
885 </tr>
886 <tr>
887 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_BASE_PRESET_ORDERAMOUNT_FIELD_PRIORITY') . ':</strong></td>
888 <td class="adm-detail-content-cell-r" style="width:60%;">
889 <input type="text" name="discount_priority" value="' . (int)$state->get('discount_priority', 1) . '" size="39" maxlength="100" style="width: 100px;">
890 </td>
891 </tr>
892 <tr>
893 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_BASE_PRESET_ORDERAMOUNT_FIELD_SORT') . ':</strong></td>
894 <td class="adm-detail-content-cell-r" style="width:60%;">
895 <input type="text" name="discount_sort" value="' . (int)$state->get('discount_sort', 100) . '" size="39" maxlength="100" style="width: 100px;">
896 </td>
897 </tr>
898 <tr>
899 <td class="adm-detail-content-cell-l" style="width:40%;">
900 <script>BX.ready(function(){BX.hint_replace(BX("tr_HELP_notice"), \'<img style="padding-left: 16px;" width="545" height="353" src="/bitrix/images/sale/discount/' . $hintLastDiscountImageName . '" alt="">\');})</script>
901 <span id="tr_HELP_notice"></span>
902 <strong>' . Loc::getMessage('SALE_BASE_PRESET_LAST_LEVEL_DISCOUNT_LABEL') . ':</strong>
903 </td>
904 <td class="adm-detail-content-cell-r" style="width:60%;">
905 <input type="checkbox" name="discount_last_level_discount" value="Y" ' . ($state->get('discount_last_level_discount', 'N') == 'Y'? 'checked' : '') . '>
906 </td>
907 </tr>
908 <tr>
909 <td class="adm-detail-content-cell-l" style="width:40%;">
910 <script>BX.ready(function(){BX.hint_replace(BX("tr_HELP_notice2"), \'<img style="padding-left: 16px;" width="545" height="353" src="/bitrix/images/sale/discount/' . $hintLastDiscountImageName . '" alt="">\');})</script>
911 <span id="tr_HELP_notice2"></span>
912 <strong>' . Loc::getMessage('SALE_BASE_PRESET_LAST_DISCOUNT_LABEL') . ':</strong>
913 </td>
914 <td class="adm-detail-content-cell-r" style="width:60%;">
915 <input type="checkbox" name="discount_last_discount" value="Y" ' . ($state->get('discount_last_discount', 'Y') == 'Y'? 'checked' : '') . '>
916 </td>
917 </tr>
918 </tbody>
919 </table>
920 ';
921 }
922
923 protected function processSaveCommonSettingsInternal(State $state, $nextStep = self::FINAL_STEP)
924 {
925 if (!$state->get('discount_groups'))
926 {
927 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_ERROR_EMPTY_USER_GROUPS'));
928 }
929
930 $priority = (int)$state->get('discount_priority');
931 if ($priority <= 0)
932 {
933 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_ERROR_EMPTY_PRIORITY'));
934 }
935 else
936 {
937 $state['discount_priority'] = $priority;
938 }
939
940 if ($state['discount_last_discount'] !== 'Y' || !$this->request->getPost('discount_last_discount'))
941 {
942 $state['discount_last_discount'] = 'N';
943 }
944
945 if ($state['discount_last_level_discount'] !== 'Y' || !$this->request->getPost('discount_last_level_discount'))
946 {
947 $state['discount_last_level_discount'] = 'N';
948 }
949
950 if (!$this->errorCollection->isEmpty())
951 {
952 return array($state, 'CommonSettings');
953 }
954
955 return array($state, $nextStep);
956 }
957
958 protected function getLabelDiscountValue()
959 {
960 return Loc::getMessage('SALE_BASE_PRESET_DISCOUNT_VALUE_LABEL');
961 }
962
963 protected function renderDiscountValue(State $state, $currency)
964 {
965 return '
966 <tr>
967 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . $this->getLabelDiscountValue() . ':</strong></td>
968 <td class="adm-detail-content-cell-r" style="width:60%;">
969 <input type="text" name="discount_value" value="' . htmlspecialcharsbx($state->get('discount_value')) . '" maxlength="100" style="width: 100px;"> '
970 . HtmlHelper::generateSelect('discount_type', array(
971 'Perc' => Loc::getMessage('SHD_BT_SALE_ACT_GROUP_BASKET_SELECT_PERCENT'),
972 'CurEach' => $currency,
973 ), $state->get('discount_type')) . '
974 </td>
975 </tr>
976 ';
977 }
978
979 protected function getTypeOfDiscount()
980 {
981 return static::ACTION_TYPE_DISCOUNT;
982 }
983
987 protected function getAllowableUserGroups()
988 {
989 $groupList = [];
990
992 {
993 if (Main\Loader::includeModule('crm'))
994 {
995 foreach (BuyerGroup::getPublicList() as $group)
996 {
997 $groupList[$group['ID']] = $group['NAME'];
998 }
999 }
1000 }
1001 else
1002 {
1003 $groupIterator = Main\GroupTable::getList([
1004 'select' => [
1005 'ID',
1006 'NAME',
1007 'C_SORT',
1008 ],
1009 'order' => [
1010 'C_SORT' => 'ASC',
1011 'ID' => 'ASC',
1012 ],
1013 ]);
1014 while ($group = $groupIterator->fetch())
1015 {
1016 $groupList[$group['ID']] = $group['NAME'];
1017 }
1018 unset(
1019 $group,
1020 $groupIterator,
1021 );
1022 }
1023
1024 return $groupList;
1025 }
1026
1027 protected function prepareDiscountFields(array $discount): array
1028 {
1029 $dateFields = [
1030 'ACTIVE_FROM',
1031 'ACTIVE_TO',
1032 ];
1033
1034 foreach ($dateFields as $fieldName)
1035 {
1036 if (
1037 isset($discount[$fieldName])
1038 && $discount[$fieldName] instanceof Main\Type\DateTime
1039 )
1040 {
1041 $discount[$fieldName] = $discount[$fieldName]->toString();
1042 }
1043 }
1044
1045 return $discount;
1046 }
1047}
global $APPLICATION
Определения include.php:80
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения error.php:15
static getDefaultLang($lang)
Определения loc.php:463
static getList(array $parameters=array())
Определения datamanager.php:431
normalizeDiscountFields(array $discountFields)
Определения basepreset.php:608
generateState(array $discountFields)
Определения basepreset.php:592
processSaveCommonSettingsInternal(State $state, $nextStep=self::FINAL_STEP)
Определения basepreset.php:923
processSaveInputNameInternal(State $state, $nextStep)
Определения basepreset.php:811
processShowInputNameInternal(State $state)
Определения basepreset.php:789
generateDiscount(State $state)
Определения basepreset.php:566
endForm(State $state)
Определения basepreset.php:537
updateDiscount($id, array $discountFields)
Определения basepreset.php:653
filterUserGroups(array $discountGroups)
Определения basepreset.php:542
processAjaxActionGetProductDetails(array $params=[])
Определения basepreset.php:156
renderDiscountValue(State $state, $currency)
Определения basepreset.php:963
executeAjaxAction($actionName)
Определения basepreset.php:142
addDiscount(array $discountFields)
Определения basepreset.php:672
setStepDescription($stepDescription)
Определения basepreset.php:417
static classShortName(BasePreset $classObject)
Определения basepreset.php:70
enableRestrictedGroupsMode($state)
Определения basepreset.php:84
processShowCommonSettingsInternal(State $state)
Определения basepreset.php:836
processShowFinalStep(State $state)
Определения basepreset.php:693
prepareDiscountFields(array $discount)
Определения basepreset.php:1027
setStepTitle($stepTitle)
Определения basepreset.php:400
beginForm(State $state)
Определения basepreset.php:524
getUserGroupsByDiscount($discountId)
Определения basepreset.php:703
static generateMultipleSelect($id, array $selectData, array $values, array $params=[])
Определения htmlhelper.php:29
static generateSelect($id, array $selectData, $value, array $params=[])
Определения htmlhelper.php:7
const CATEGORY_OTHER
Определения manager.php:22
static createFromRequest(HttpRequest $request)
Определения state.php:119
static getSiteCurrency($siteId)
Определения sitecurrency.php:96
static CalendarPeriodCustom($sFromName, $sToName, $sFromVal="", $sToVal="", $bSelectShow=false, $size=10, $bTime=false, $arPeriod=false, $periodValue='')
Определения admin_calendar.php:125
const PERIOD_INTERVAL
Определения admin_calendar.php:20
const PERIOD_EMPTY
Определения admin_calendar.php:11
</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
global $USER
Определения csv_new_run.php:40
const BX_RESIZE_IMAGE_PROPORTIONAL
Определения constants.php:11
$groups
Определения options.php:30
$siteId
Определения ajax.php:8
bitrix_sessid_post($varname='sessid', $returnInvocations=false)
Определения tools.php:4700
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
Определения collection.php:2
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$currency
Определения template.php:266
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$siteIterator
Определения options.php:48
$siteList
Определения options.php:47
$site
Определения yandex_run.php:614