Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basepreset.php
1<?php
2
4
5use Bitrix\Crm\Order\BuyerGroup;
19
20Loc::loadMessages(__FILE__);
21
22abstract class BasePreset
23{
24 public const FINAL_STEP = 'FINALSTEP';
25 public const STEP_NAME_VAR = '__next_step';
26
27 public const RUN_PREV_STEP_NAME_VAR = '__run_prev_step';
28
29 public const MODE_SHOW = 2;
30 public const MODE_SAVE = 3;
31
32 public const ACTION_TYPE_DISCOUNT = 'Discount';
33 public const ACTION_TYPE_EXTRA = 'Extra';
34
35 public const AVAILABLE_STATE_ALLOW = 0x01;
36 public const AVAILABLE_STATE_DISALLOW = 0x02;
37 public const AVAILABLE_STATE_TARIFF = 0x04;
38
42 protected $request;
44 protected $nextStep;
46 protected $stepTitle;
50 private $stepResult;
52 private $stepResultState;
54 private $discount;
56 private $restrictedGroupsMode = false;
57
60
64 public static function className()
65 {
66 return get_called_class();
67 }
68
73 public static function classShortName(BasePreset $classObject)
74 {
75 return (new \ReflectionClass($classObject))->getShortName();
76 }
77
78 public function __construct()
79 {
80 $this->errorCollection = new ErrorCollection;
81 $this->request = Context::getCurrent()->getRequest();
82 $this->bitrix24Included = Loader::includeModule('bitrix24');
83
84 $this->init();
85 }
86
87 public function enableRestrictedGroupsMode($state)
88 {
89 $this->restrictedGroupsMode = $state === true;
90 }
91
93 {
94 return $this->restrictedGroupsMode;
95 }
96
97 protected function init()
98 {}
99
100 public function hasErrors()
101 {
102 return !$this->errorCollection->isEmpty();
103 }
104
108 public function getErrors()
109 {
110 return $this->errorCollection->toArray();
111 }
112
113 public function getStepNumber()
114 {
115 if($this->stepResultState)
116 {
117 return $this->stepResultState->getStepNumber();
118 }
119
120 return 1;
121 }
122
126 protected function getState()
127 {
128 return State::createFromRequest($this->request);
129 }
130
131 public function getView()
132 {
133 return
134 $this->beginForm($this->stepResultState) .
135 $this->stepResult .
136 $this->endForm($this->stepResultState)
137 ;
138 }
139
140 protected function isRunningPrevStep()
141 {
142 return (bool)$this->request->getPost(static::RUN_PREV_STEP_NAME_VAR);
143 }
144
145 public function executeAjaxAction($actionName)
146 {
147 \CUtil::jSPostUnescape();
148 $this->request->addFilter(new PostDecodeFilter);
149
150 $methodName = 'processAjaxAction' . $actionName;
151 if(!method_exists($this, $methodName))
152 {
153 throw new SystemException("Could not find method {$methodName}");
154 }
155
156 $result = call_user_func_array(array($this, $methodName), array(
157
158 ));
159
160 header('Content-Type:application/json; charset=UTF-8');
161 \CMain::FinalActions(Json::encode($result));
162 }
163
164 public function processAjaxActionGetProductDetails(array $params = array())
165 {
166 $productId = !empty($params['productId']) ? $params['productId'] : $this->request->get('productId');
167 if (is_array($productId))
168 {
169 $productId = array_pop($productId);
170 }
171
172 $quantity = !empty($params['quantity']) ? $params['quantity'] : $this->request->get('quantity');
173 $quantity = (float)$quantity;
174
175 $siteId = !empty($params['siteId']) ? $params['siteId'] : $this->request->get('siteId');
176 $siteId = (string)$siteId;
177
178 global $USER;
179 $userId = $USER->getId();
180
181 if(empty($productId))
182 {
183 throw new SystemException("Could not find product id");
184 }
185 if (empty($quantity))
186 {
187 $quantity = 1;
188 }
189
190 $productDetails = OrderBasket::getProductDetails($productId, $quantity, $userId, $siteId);
191 if(!$productDetails || empty($productDetails['PRODUCT_ID']))
192 {
193 return $this->getProductInfo($productId);
194 }
195
196 return $productDetails;
197 }
198
199 private function getProductInfo($elementId)
200 {
201 $elementId = intval($elementId);
202 $dbProduct = \CIBlockElement::getList(array(), array("ID" => $elementId), false, false, array(
203 'ID',
204 'IBLOCK_ID',
205 'IBLOCK_SECTION_ID',
206 'DETAIL_PICTURE',
207 'PREVIEW_PICTURE',
208 'NAME',
209 'XML_ID',
210 ));
211 while($product = $dbProduct->fetch())
212 {
213 $imgCode = 0;
214 if($product["IBLOCK_ID"] > 0)
215 {
216 $product["EDIT_PAGE_URL"] = \CIBlock::getAdminElementEditLink($product["IBLOCK_ID"], $elementId, array("find_section_section" => $product["IBLOCK_SECTION_ID"]));
217 }
218
219 if($product["DETAIL_PICTURE"] > 0)
220 {
221 $imgCode = $product["DETAIL_PICTURE"];
222 }
223 elseif($product["PREVIEW_PICTURE"] > 0)
224 {
225 $imgCode = $product["PREVIEW_PICTURE"];
226 }
227
228 if($imgCode > 0)
229 {
230 $imgProduct = \CFile::resizeImageGet(\CFile::getFileArray($imgCode), array(
231 'width' => 80,
232 'height' => 80,
233 ), BX_RESIZE_IMAGE_PROPORTIONAL, false, false);
234 $product["PICTURE_URL"] = $imgProduct['src'];
235 }
236 $product['PRODUCT_ID'] = $product['ID'];
237
238 return $product;
239 }
240
241 return array();
242 }
243
244 public function exec()
245 {
246 $isPost = $this->request->isPost();
247
248 $stepName = $this->getStepName();
249 $state = $this->getState();
250
251 //edit existing discount
252 if($stepName === $this->getFirstStepName() && !$isPost && $this->isDiscountEditing())
253 {
254 $state = $this->generateState($this->discount);
255 }
256
257 if($this->isRunningPrevStep())
258 {
259 $stepName = $state->getPrevStep();
260 }
261
262 if($isPost && !$this->isRunningPrevStep())
263 {
265 list($state, $nextStep) = $this->runStep($stepName, $state, self::MODE_SAVE);
266
267 if($stepName != $nextStep)
268 {
269 $state->addStepChain($stepName);
270 }
271
272 $this->setNextStep($nextStep);
273 if($nextStep === static::FINAL_STEP)
274 {
275 $discountFields = $this->generateDiscount($state);
276
277 if($this->isDiscountEditing())
278 {
279 $this->updateDiscount($this->discount['ID'], $discountFields);
280 }
281 else
282 {
283 $this->addDiscount($discountFields);
284 }
285
286 if($this->hasErrors())
287 {
288 $stepName = $step = $state->popStepChain();
289
290 $this->setNextStep($step);
291 }
292 }
293
294 if(!$this->hasErrors())
295 {
296 $stepName = $nextStep;
297 }
298 }
299 elseif($this->isRunningPrevStep())
300 {
301 $step = $state->popStepChain();
302
303 $this->setNextStep($step);
304 }
305
306 $this->stepResult = $this->runStep($stepName, $state, self::MODE_SHOW);
307 $this->stepResultState = $state;
308
309 return $this;
310 }
311
312 private function runStep($actionName, State $state, $mode = self::MODE_SHOW)
313 {
314 $methodName = '';
315 if($mode === self::MODE_SHOW)
316 {
317 $methodName = 'processShow' . $actionName;
318 }
319 elseif($mode === self::MODE_SAVE)
320 {
321 $methodName = 'processSave' . $actionName;
322 }
323
324 if(!$methodName)
325 {
326 throw new SystemException("Unknown mode {$mode}");
327 }
328
329 if(!method_exists($this, $methodName))
330 {
331 throw new SystemException("Method {$methodName} is not exist");
332 }
333
334 return call_user_func_array(array($this, $methodName), array($state));
335 }
336
337 private function getStepName()
338 {
339 return $this->request->getPost(static::STEP_NAME_VAR)?: static::getFirstStepName();
340 }
341
345 public function getDiscount()
346 {
347 return $this->discount;
348 }
349
350 protected function isDiscountEditing()
351 {
352 return !empty($this->discount);
353 }
354
359 public function setDiscount($discount)
360 {
361 $this->discount = $discount;
362
363 return $this;
364 }
365
369 public function getStepTitle()
370 {
371 return $this->stepTitle;
372 }
373
377 public function setStepTitle($stepTitle)
378 {
379 $this->stepTitle = $stepTitle;
380 }
381
385 public function getStepDescription()
386 {
388 }
389
395 {
396 $this->stepDescription = $stepDescription;
397
398 return $this;
399 }
400
405 public function getSort()
406 {
407 return 100;
408 }
409
413 abstract public function getTitle();
414
422 public function isAvailable()
423 {
425 }
426
427 public function getPossible(): bool
428 {
430 }
431
432 public function getAvailableState(): int
433 {
435 }
436
437 public function getAvailableHelpLink(): ?array
438 {
439 return null;
440 }
441
445 abstract public function getDescription();
446
447 public function getExtendedDescription()
448 {
449 return array(
450 'DISCOUNT_TYPE' => '',
451 'DISCOUNT_VALUE' => '',
452 'DISCOUNT_CONDITION' => '',
453 );
454 }
455
459 abstract public function getFirstStepName();
460
464 public function getCategory()
465 {
467 }
468
472 public function getNextStep()
473 {
474 return $this->nextStep;
475 }
476
477 public function hasPrevStep()
478 {
479 $prevStep = $this->stepResultState->getPrevStep();
480
481 return $prevStep && $prevStep != $this->getNextStep() && !$this->isLastStep();
482 }
483
484 public function isLastStep()
485 {
486 return $this->getNextStep() == static::FINAL_STEP;
487 }
488
493 public function setNextStep($nextStep)
494 {
495 $this->nextStep = $nextStep;
496
497 return $this;
498 }
499
500 public function beginForm(State $state)
501 {
502 return '
503 <form action="' . htmlspecialcharsbx($this->request->getRequestUri()) . '" enctype="multipart/form-data" method="post" name="__preset_form" id="__preset_form">
504 ' . $state->toString() . '
505 <input type="hidden" name="' . static::STEP_NAME_VAR . '" id="' . static::STEP_NAME_VAR . '" value="' . htmlspecialcharsbx($this->getNextStep()) . '">
506 <input type="hidden" name="' . static::RUN_PREV_STEP_NAME_VAR . '" id="' . static::RUN_PREV_STEP_NAME_VAR . '" value="">
507 ' . bitrix_sessid_post() . '
508 <input type="hidden" name="lang" value="' . LANGUAGE_ID . '">
509 ';
510 }
511
512 public function endForm(State $state)
513 {
514 return '</form>';
515 }
516
517 protected function filterUserGroups(array $discountGroups)
518 {
520 {
521 if (Main\Loader::includeModule('crm'))
522 {
523 $existingGroups = [];
524
525 if ($this->isDiscountEditing())
526 {
527 $existingGroups = $this->getUserGroupsByDiscount($this->discount['ID']);
528 }
529
530 $discountGroups = BuyerGroup::prepareGroupIds($existingGroups, $discountGroups);
531 }
532 }
533
534 return $discountGroups;
535 }
536
541 public function generateDiscount(State $state)
542 {
543 $siteId = $state->get('discount_lid');
544
545 $discountGroups = $state->get('discount_groups') ?: [];
546 $userGroups = $this->filterUserGroups($discountGroups);
547
548 return array(
549 'LID' => $siteId,
550 'NAME' => $state->get('discount_name'),
551 'CURRENCY' => \Bitrix\Sale\Internals\SiteCurrencyTable::getSiteCurrency($siteId),
552 'ACTIVE_FROM' => $state->get('discount_active_from'),
553 'ACTIVE_TO' => $state->get('discount_active_to'),
554 'ACTIVE' => 'Y',
555 'SORT' => $state->get('discount_sort'),
556 'PRIORITY' => $state->get('discount_priority'),
557 'LAST_DISCOUNT' => $state->get('discount_last_discount'),
558 'LAST_LEVEL_DISCOUNT' => $state->get('discount_last_level_discount'),
559 'USER_GROUPS' => $userGroups,
560 );
561 }
562
567 public function generateState(array $discountFields)
568 {
569 return new State(array(
570 'discount_id' => $discountFields['ID'],
571 'discount_lid' => $discountFields['LID'],
572 'discount_name' => $discountFields['NAME'],
573 'discount_active_from' => $discountFields['ACTIVE_FROM'],
574 'discount_active_to' => $discountFields['ACTIVE_TO'],
575 'discount_last_discount' => $discountFields['LAST_DISCOUNT'],
576 'discount_last_level_discount' => $discountFields['LAST_LEVEL_DISCOUNT'],
577 'discount_priority' => $discountFields['PRIORITY'],
578 'discount_sort' => $discountFields['SORT'],
579 'discount_groups' => $this->getUserGroupsByDiscount($discountFields['ID']),
580 ));
581 }
582
583 final protected function normalizeDiscountFields(array $discountFields)
584 {
585 if(isset($discountFields['CONDITIONS']) && is_array($discountFields['CONDITIONS']))
586 {
587 $discountFields['CONDITIONS_LIST'] = $discountFields['CONDITIONS'];
588 }
589
590 if(isset($discountFields['CONDITIONS_LIST']) && is_string($discountFields['CONDITIONS_LIST']))
591 {
592 $discountFields['CONDITIONS_LIST'] = unserialize($discountFields['CONDITIONS_LIST'], ['allowed_classes' => false]);
593 }
594
595 if(isset($discountFields['CONDITIONS_LIST']) && is_array($discountFields['CONDITIONS_LIST']))
596 {
597 $discountFields['CONDITIONS'] = $discountFields['CONDITIONS_LIST'];
598 }
599
600
601 if(isset($discountFields['ACTIONS']) && is_array($discountFields['ACTIONS']))
602 {
603 $discountFields['ACTIONS_LIST'] = $discountFields['ACTIONS'];
604 }
605
606 if(isset($discountFields['ACTIONS_LIST']) && is_string($discountFields['ACTIONS_LIST']))
607 {
608 $discountFields['ACTIONS_LIST'] = unserialize($discountFields['ACTIONS_LIST'], ['allowed_classes' => false]);
609 }
610
611 if(isset($discountFields['ACTIONS_LIST']) && is_array($discountFields['ACTIONS_LIST']))
612 {
613 $discountFields['ACTIONS'] = $discountFields['ACTIONS_LIST'];
614 }
615
616 if(isset($discountFields['PREDICTIONS_LIST']) && is_string($discountFields['PREDICTIONS_LIST']))
617 {
618 $discountFields['PREDICTIONS_LIST'] = unserialize($discountFields['PREDICTIONS_LIST'], ['allowed_classes' => false]);
619 }
620
621 if(isset($discountFields['PREDICTIONS_LIST']) && is_array($discountFields['PREDICTIONS_LIST']))
622 {
623 $discountFields['PREDICTIONS'] = $discountFields['PREDICTIONS_LIST'];
624 }
625
626 return $discountFields;
627 }
628
629 protected function updateDiscount($id, array $discountFields)
630 {
631 $discountFields['PRESET_ID'] = $this->className();
632
633 if(!\CSaleDiscount::update($id, $discountFields))
634 {
635 global $APPLICATION;
636 if($ex = $APPLICATION->getException())
637 {
638 $this->errorCollection[] = new Error($ex->getString());
639 }
640 else
641 {
642 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_DISCOUNT_EDIT_ERR_UPDATE'));
643 }
644 }
645 }
646
647 protected function addDiscount(array $discountFields)
648 {
649 $discountFields['PRESET_ID'] = $this->className();
650
651 $discountId = \CSaleDiscount::add($discountFields);
652
653 if($discountId <= 0)
654 {
655 global $APPLICATION;
656 if($ex = $APPLICATION->getException())
657 {
658 $this->errorCollection[] = new Error($ex->getString());
659 }
660 else
661 {
662 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_DISCOUNT_EDIT_ERR_ADD'));
663 }
664 }
665 }
666
667 public function processShowFinalStep(State $state)
668 {
669 return Loc::getMessage('SALE_BASE_PRESET_FINAL_OK', array(
670 '#NAME#' => htmlspecialcharsbx($state->get('discount_name'))
671 ));
672 }
673
674 protected function getUserGroupsByDiscount($discountId)
675 {
676 $groups = array();
677 $groupDiscountIterator = DiscountGroupTable::getList(array(
678 'select' => array('GROUP_ID'),
679 'filter' => array('DISCOUNT_ID' => $discountId, '=ACTIVE' => 'Y')
680 ));
681 while($groupDiscount = $groupDiscountIterator->fetch())
682 {
683 $groups[] = $groupDiscount['GROUP_ID'];
684 }
685
686 return $groups;
687 }
688
689 protected function getSiteList()
690 {
691 return $this->getSaleSiteList()?: $this->getFullSiteList();
692 }
693
694 private function getSaleSiteList()
695 {
696 $siteList = array();
697 $siteIterator = SiteTable::getList(array(
698 'select' => array('LID', 'NAME',),
699 'filter' => array('=ACTIVE' => 'Y'),
700 'order' => array('SORT' => 'ASC'),
701 ));
702 while($site = $siteIterator->fetch())
703 {
704 $saleSite = Option::get('sale', 'SHOP_SITE_' . $site['LID']);
705 if($site['LID'] == $saleSite)
706 {
707 $siteList[$site['LID']] = '(' . $site['LID'] . ') ' . $site['NAME'];
708 }
709 }
710
711 return $siteList;
712 }
713
714 private function getFullSiteList()
715 {
716 $siteList = array();
717 $siteIterator = SiteTable::getList(array(
718 'select' => array('LID', 'NAME',),
719 'order' => array('SORT' => 'ASC'),
720 ));
721 while($site = $siteIterator->fetch())
722 {
723 $siteList[$site['LID']] = '(' . $site['LID'] . ') ' . $site['NAME'];
724 }
725
726 return $siteList;
727 }
728
729 protected function processShowInputNameInternal(State $state)
730 {
731 return '
732 <table width="100%" border="0" cellspacing="7" cellpadding="0">
733 <tbody>
734 <tr>
735 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_BASE_PRESET_ORDERAMOUNT_FIELD_NAME') . ':</strong></td>
736 <td class="adm-detail-content-cell-r" style="width:60%;">
737 <input type="text" name="discount_name" value="' . htmlspecialcharsbx($state->get('discount_name')) . '" size="39" maxlength="100" style="width: 300px;">
738 </td>
739 </tr>
740 <tr>
741 <td class="adm-detail-content-cell-l"><strong>' . Loc::getMessage('SALE_BASE_PRESET_ORDERAMOUNT_LID') . ':</strong></td>
742 <td class="adm-detail-content-cell-r">
743 ' . HtmlHelper::generateSelect('discount_lid', $this->getSiteList(), $state->get('discount_lid')) . '
744 </td>
745 </tr>
746 </tbody>
747 </table>
748 ';
749 }
750
751 protected function processSaveInputNameInternal(State $state, $nextStep)
752 {
753 if(!trim($state->get('discount_name')))
754 {
755 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_ERROR_EMPTY_NAME'));
756 }
757
758 if(!trim($state->get('discount_lid')))
759 {
760 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_ERROR_EMPTY_LID'));
761 }
762
763 if(!$this->errorCollection->isEmpty())
764 {
765 return array($state, 'InputName');
766 }
767
768 return array($state, $nextStep);
769 }
770
771 protected function processShowCommonSettingsInternal(State $state)
772 {
773 $groupList = $this->getAllowableUserGroups();
774
775 switch(LANGUAGE_ID)
776 {
777 case 'en':
778 case 'ru':
779 case 'de':
780 $hintLastDiscountImageName = 'hint_last_discount_' . LANGUAGE_ID . '.png';
781 break;
782 default:
783 $hintLastDiscountImageName = 'hint_last_discount_' . Main\Localization\Loc::getDefaultLang(LANGUAGE_ID) . '.png';
784 break;
785 }
786
787 $periodValue = '';
788 if ($state->get('discount_active_from') || $state->get('discount_active_to'))
789 {
790 $periodValue = \CAdminCalendar::PERIOD_INTERVAL;
791 }
792
793 return '
794 <table width="100%" border="0" cellspacing="7" cellpadding="0">
795 <tbody>
796 <tr>
797 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_BASE_PRESET_ORDERAMOUNT_USER_GROUPS') . ':</strong></td>
798 <td class="adm-detail-content-cell-r">
799 ' . HtmlHelper::generateMultipleSelect('discount_groups[]', $groupList, $state->get('discount_groups', array()), array('size=8')) . '
800 </td>
801 </tr>
802 <tr>
803 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_BASE_PRESET_ACTIVE_PERIOD') . ':</strong></td>
804 <td class="adm-detail-content-cell-r">' .
805 \CAdminCalendar::CalendarPeriodCustom(
806 'discount_active_from',
807 'discount_active_to',
808 $state->get('discount_active_from'),
809 $state->get('discount_active_to'),
810 true,
811 19,
812 true,
813 array(
814 \CAdminCalendar::PERIOD_EMPTY => Loc::getMessage('SALE_BASE_PRESET_CALENDAR_PERIOD_EMPTY'),
815 \CAdminCalendar::PERIOD_INTERVAL => Loc::getMessage('SALE_BASE_PRESET_CALENDAR_PERIOD_INTERVAL')
816 ),
817 $periodValue
818 ) . '
819 </td>
820 </tr>
821 <tr>
822 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_BASE_PRESET_ORDERAMOUNT_FIELD_PRIORITY') . ':</strong></td>
823 <td class="adm-detail-content-cell-r" style="width:60%;">
824 <input type="text" name="discount_priority" value="' . (int)$state->get('discount_priority', 1) . '" size="39" maxlength="100" style="width: 100px;">
825 </td>
826 </tr>
827 <tr>
828 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage('SALE_BASE_PRESET_ORDERAMOUNT_FIELD_SORT') . ':</strong></td>
829 <td class="adm-detail-content-cell-r" style="width:60%;">
830 <input type="text" name="discount_sort" value="' . (int)$state->get('discount_sort', 100) . '" size="39" maxlength="100" style="width: 100px;">
831 </td>
832 </tr>
833 <tr>
834 <td class="adm-detail-content-cell-l" style="width:40%;">
835 <script type="text/javascript">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>
836 <span id="tr_HELP_notice"></span>
837 <strong>' . Loc::getMessage('SALE_BASE_PRESET_LAST_LEVEL_DISCOUNT_LABEL') . ':</strong>
838 </td>
839 <td class="adm-detail-content-cell-r" style="width:60%;">
840 <input type="checkbox" name="discount_last_level_discount" value="Y" ' . ($state->get('discount_last_level_discount', 'N') == 'Y'? 'checked' : '') . '>
841 </td>
842 </tr>
843 <tr>
844 <td class="adm-detail-content-cell-l" style="width:40%;">
845 <script type="text/javascript">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>
846 <span id="tr_HELP_notice2"></span>
847 <strong>' . Loc::getMessage('SALE_BASE_PRESET_LAST_DISCOUNT_LABEL') . ':</strong>
848 </td>
849 <td class="adm-detail-content-cell-r" style="width:60%;">
850 <input type="checkbox" name="discount_last_discount" value="Y" ' . ($state->get('discount_last_discount', 'Y') == 'Y'? 'checked' : '') . '>
851 </td>
852 </tr>
853 </tbody>
854 </table>
855 ';
856 }
857
858 protected function processSaveCommonSettingsInternal(State $state, $nextStep = self::FINAL_STEP)
859 {
860 if(!$state->get('discount_groups'))
861 {
862 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_ERROR_EMPTY_USER_GROUPS'));
863 }
864
865 $priority = (int)$state->get('discount_priority');
866 if($priority <= 0)
867 {
868 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_ERROR_EMPTY_PRIORITY'));
869 }
870 else
871 {
872 $state['discount_priority'] = $priority;
873 }
874
875 if($state['discount_last_discount'] !== 'Y' || !$this->request->getPost('discount_last_discount'))
876 {
877 $state['discount_last_discount'] = 'N';
878 }
879
880 if($state['discount_last_level_discount'] !== 'Y' || !$this->request->getPost('discount_last_level_discount'))
881 {
882 $state['discount_last_level_discount'] = 'N';
883 }
884
885 if(!$this->errorCollection->isEmpty())
886 {
887 return array($state, 'CommonSettings');
888 }
889
890 return array($state, $nextStep);
891 }
892
893 protected function getLabelDiscountValue()
894 {
895 return Loc::getMessage('SALE_BASE_PRESET_DISCOUNT_VALUE_LABEL');
896 }
897
898 protected function renderDiscountValue(State $state, $currency)
899 {
900 return '
901 <tr>
902 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . $this->getLabelDiscountValue() . ':</strong></td>
903 <td class="adm-detail-content-cell-r" style="width:60%;">
904 <input type="text" name="discount_value" value="' . htmlspecialcharsbx($state->get('discount_value')) . '" maxlength="100" style="width: 100px;"> '
905 . HtmlHelper::generateSelect('discount_type', array(
906 'Perc' => Loc::getMessage('SHD_BT_SALE_ACT_GROUP_BASKET_SELECT_PERCENT'),
907 'CurEach' => $currency,
908 ), $state->get('discount_type')) . '
909 </td>
910 </tr>
911 ';
912 }
913
914 protected function getTypeOfDiscount()
915 {
916 return static::ACTION_TYPE_DISCOUNT;
917 }
918
922 protected function getAllowableUserGroups()
923 {
924 $groupList = [];
925
927 {
928 if (Main\Loader::includeModule('crm'))
929 {
930 foreach (BuyerGroup::getPublicList() as $group)
931 {
932 $groupList[$group['ID']] = $group['NAME'];
933 }
934 }
935 }
936 else
937 {
938 $groupIterator = Main\GroupTable::getList([
939 'select' => ['ID', 'NAME'],
940 'order' => ['C_SORT' => 'ASC', 'ID' => 'ASC'],
941 ]);
942 while ($group = $groupIterator->fetch())
943 {
944 $groupList[$group['ID']] = $group['NAME'];
945 }
946 }
947
948 return $groupList;
949 }
950}
static getCurrent()
Definition context.php:241
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
normalizeDiscountFields(array $discountFields)
generateState(array $discountFields)
processSaveCommonSettingsInternal(State $state, $nextStep=self::FINAL_STEP)
processSaveInputNameInternal(State $state, $nextStep)
updateDiscount($id, array $discountFields)
filterUserGroups(array $discountGroups)
renderDiscountValue(State $state, $currency)
static classShortName(BasePreset $classObject)
processAjaxActionGetProductDetails(array $params=array())
static generateSelect($id, array $selectData, $value, array $params=array())
Definition htmlhelper.php:8
static generateMultipleSelect($id, array $selectData, array $values, array $params=array())
static createFromRequest(HttpRequest $request)
Definition state.php:119
static getProductDetails($productId, $quantity, $userId, $siteId, array $columns=array())