52 private $stepResultState;
56 private $restrictedGroupsMode =
false;
66 return get_called_class();
75 return (
new \ReflectionClass($classObject))->getShortName();
82 $this->bitrix24Included = Loader::includeModule(
'bitrix24');
89 $this->restrictedGroupsMode = $state ===
true;
94 return $this->restrictedGroupsMode;
102 return !$this->errorCollection->isEmpty();
110 return $this->errorCollection->toArray();
115 if($this->stepResultState)
117 return $this->stepResultState->getStepNumber();
134 $this->
beginForm($this->stepResultState) .
136 $this->
endForm($this->stepResultState)
142 return (
bool)$this->request->getPost(static::RUN_PREV_STEP_NAME_VAR);
147 \CUtil::jSPostUnescape();
150 $methodName =
'processAjaxAction' . $actionName;
151 if(!method_exists($this, $methodName))
156 $result = call_user_func_array(array($this, $methodName), array(
160 header(
'Content-Type:application/json; charset=UTF-8');
161 \CMain::FinalActions(Json::encode($result));
166 $productId = !empty($params[
'productId']) ? $params[
'productId'] : $this->request->get(
'productId');
167 if (is_array($productId))
169 $productId = array_pop($productId);
172 $quantity = !empty($params[
'quantity']) ? $params[
'quantity'] : $this->request->get(
'quantity');
173 $quantity = (float)$quantity;
175 $siteId = !empty($params[
'siteId']) ? $params[
'siteId'] : $this->request->get(
'siteId');
176 $siteId = (string)$siteId;
179 $userId = $USER->getId();
181 if(empty($productId))
185 if (empty($quantity))
191 if(!$productDetails || empty($productDetails[
'PRODUCT_ID']))
193 return $this->getProductInfo($productId);
196 return $productDetails;
199 private function getProductInfo($elementId)
201 $elementId = intval($elementId);
202 $dbProduct = \CIBlockElement::getList(array(), array(
"ID" => $elementId),
false,
false, array(
211 while($product = $dbProduct->fetch())
214 if($product[
"IBLOCK_ID"] > 0)
216 $product[
"EDIT_PAGE_URL"] = \CIBlock::getAdminElementEditLink($product[
"IBLOCK_ID"], $elementId, array(
"find_section_section" => $product[
"IBLOCK_SECTION_ID"]));
219 if($product[
"DETAIL_PICTURE"] > 0)
221 $imgCode = $product[
"DETAIL_PICTURE"];
223 elseif($product[
"PREVIEW_PICTURE"] > 0)
225 $imgCode = $product[
"PREVIEW_PICTURE"];
230 $imgProduct = \CFile::resizeImageGet(\CFile::getFileArray($imgCode), array(
233 ), BX_RESIZE_IMAGE_PROPORTIONAL,
false,
false);
234 $product[
"PICTURE_URL"] = $imgProduct[
'src'];
236 $product[
'PRODUCT_ID'] = $product[
'ID'];
244 public function exec()
246 $isPost = $this->request->isPost();
248 $stepName = $this->getStepName();
259 $stepName = $state->getPrevStep();
265 list($state,
$nextStep) = $this->runStep($stepName, $state, self::MODE_SAVE);
269 $state->addStepChain($stepName);
288 $stepName = $step = $state->popStepChain();
301 $step = $state->popStepChain();
306 $this->stepResult = $this->runStep($stepName, $state, self::MODE_SHOW);
307 $this->stepResultState = $state;
312 private function runStep($actionName, State $state, $mode = self::MODE_SHOW)
315 if($mode === self::MODE_SHOW)
317 $methodName =
'processShow' . $actionName;
319 elseif($mode === self::MODE_SAVE)
321 $methodName =
'processSave' . $actionName;
326 throw new SystemException(
"Unknown mode {$mode}");
329 if(!method_exists($this, $methodName))
331 throw new SystemException(
"Method {$methodName} is not exist");
334 return call_user_func_array(array($this, $methodName), array($state));
337 private function getStepName()
339 return $this->request->getPost(static::STEP_NAME_VAR)?: static::getFirstStepName();
347 return $this->discount;
352 return !empty($this->discount);
361 $this->discount = $discount;
450 'DISCOUNT_TYPE' =>
'',
451 'DISCOUNT_VALUE' =>
'',
452 'DISCOUNT_CONDITION' =>
'',
479 $prevStep = $this->stepResultState->getPrevStep();
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 .
'">
521 if (Main\Loader::includeModule(
'crm'))
523 $existingGroups = [];
530 $discountGroups = BuyerGroup::prepareGroupIds($existingGroups, $discountGroups);
534 return $discountGroups;
543 $siteId = $state->get(
'discount_lid');
545 $discountGroups = $state->get(
'discount_groups') ?: [];
550 'NAME' => $state->get(
'discount_name'),
552 'ACTIVE_FROM' => $state->get(
'discount_active_from'),
553 'ACTIVE_TO' => $state->get(
'discount_active_to'),
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,
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'],
585 if(isset($discountFields[
'CONDITIONS']) && is_array($discountFields[
'CONDITIONS']))
587 $discountFields[
'CONDITIONS_LIST'] = $discountFields[
'CONDITIONS'];
590 if(isset($discountFields[
'CONDITIONS_LIST']) && is_string($discountFields[
'CONDITIONS_LIST']))
592 $discountFields[
'CONDITIONS_LIST'] = unserialize($discountFields[
'CONDITIONS_LIST'], [
'allowed_classes' =>
false]);
595 if(isset($discountFields[
'CONDITIONS_LIST']) && is_array($discountFields[
'CONDITIONS_LIST']))
597 $discountFields[
'CONDITIONS'] = $discountFields[
'CONDITIONS_LIST'];
601 if(isset($discountFields[
'ACTIONS']) && is_array($discountFields[
'ACTIONS']))
603 $discountFields[
'ACTIONS_LIST'] = $discountFields[
'ACTIONS'];
606 if(isset($discountFields[
'ACTIONS_LIST']) && is_string($discountFields[
'ACTIONS_LIST']))
608 $discountFields[
'ACTIONS_LIST'] = unserialize($discountFields[
'ACTIONS_LIST'], [
'allowed_classes' =>
false]);
611 if(isset($discountFields[
'ACTIONS_LIST']) && is_array($discountFields[
'ACTIONS_LIST']))
613 $discountFields[
'ACTIONS'] = $discountFields[
'ACTIONS_LIST'];
616 if(isset($discountFields[
'PREDICTIONS_LIST']) && is_string($discountFields[
'PREDICTIONS_LIST']))
618 $discountFields[
'PREDICTIONS_LIST'] = unserialize($discountFields[
'PREDICTIONS_LIST'], [
'allowed_classes' =>
false]);
621 if(isset($discountFields[
'PREDICTIONS_LIST']) && is_array($discountFields[
'PREDICTIONS_LIST']))
623 $discountFields[
'PREDICTIONS'] = $discountFields[
'PREDICTIONS_LIST'];
626 return $discountFields;
631 $discountFields[
'PRESET_ID'] = $this->
className();
633 if(!\CSaleDiscount::update($id, $discountFields))
636 if($ex = $APPLICATION->getException())
638 $this->errorCollection[] =
new Error($ex->getString());
642 $this->errorCollection[] =
new Error(
Loc::getMessage(
'SALE_BASE_PRESET_DISCOUNT_EDIT_ERR_UPDATE'));
649 $discountFields[
'PRESET_ID'] = $this->
className();
651 $discountId = \CSaleDiscount::add($discountFields);
656 if($ex = $APPLICATION->getException())
658 $this->errorCollection[] =
new Error($ex->getString());
662 $this->errorCollection[] =
new Error(
Loc::getMessage(
'SALE_BASE_PRESET_DISCOUNT_EDIT_ERR_ADD'));
670 '#NAME#' => htmlspecialcharsbx($state->get(
'discount_name'))
677 $groupDiscountIterator = DiscountGroupTable::getList(array(
678 'select' => array(
'GROUP_ID'),
679 'filter' => array(
'DISCOUNT_ID' => $discountId,
'=ACTIVE' =>
'Y')
681 while($groupDiscount = $groupDiscountIterator->fetch())
683 $groups[] = $groupDiscount[
'GROUP_ID'];
691 return $this->getSaleSiteList()?: $this->getFullSiteList();
694 private function getSaleSiteList()
697 $siteIterator = SiteTable::getList(array(
698 'select' => array(
'LID',
'NAME',),
699 'filter' => array(
'=ACTIVE' =>
'Y'),
700 'order' => array(
'SORT' =>
'ASC'),
702 while($site = $siteIterator->fetch())
704 $saleSite = Option::get(
'sale',
'SHOP_SITE_' . $site[
'LID']);
705 if($site[
'LID'] == $saleSite)
707 $siteList[$site[
'LID']] =
'(' . $site[
'LID'] .
') ' . $site[
'NAME'];
714 private function getFullSiteList()
717 $siteIterator = SiteTable::getList(array(
718 'select' => array(
'LID',
'NAME',),
719 'order' => array(
'SORT' =>
'ASC'),
721 while($site = $siteIterator->fetch())
723 $siteList[$site[
'LID']] =
'(' . $site[
'LID'] .
') ' . $site[
'NAME'];
732 <table width="100%" border="0" cellspacing="7" cellpadding="0">
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;">
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">
753 if(!trim($state->get(
'discount_name')))
758 if(!trim($state->get(
'discount_lid')))
763 if(!$this->errorCollection->isEmpty())
765 return array($state,
'InputName');
780 $hintLastDiscountImageName =
'hint_last_discount_' . LANGUAGE_ID .
'.png';
783 $hintLastDiscountImageName =
'hint_last_discount_' . Main\Localization\Loc::getDefaultLang(LANGUAGE_ID) .
'.png';
788 if ($state->get(
'discount_active_from') || $state->get(
'discount_active_to'))
790 $periodValue = \CAdminCalendar::PERIOD_INTERVAL;
794 <table width="100%" border="0" cellspacing="7" cellpadding="0">
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">
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'),
814 \CAdminCalendar::PERIOD_EMPTY =>
Loc::getMessage(
'SALE_BASE_PRESET_CALENDAR_PERIOD_EMPTY'),
815 \CAdminCalendar::PERIOD_INTERVAL =>
Loc::getMessage(
'SALE_BASE_PRESET_CALENDAR_PERIOD_INTERVAL')
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;">
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;">
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>
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' :
'') .
'>
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>
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' :
'') .
'>
860 if(!$state->get(
'discount_groups'))
862 $this->errorCollection[] =
new Error(
Loc::getMessage(
'SALE_BASE_PRESET_ERROR_EMPTY_USER_GROUPS'));
865 $priority = (int)$state->get(
'discount_priority');
872 $state[
'discount_priority'] = $priority;
875 if($state[
'discount_last_discount'] !==
'Y' || !$this->request->getPost(
'discount_last_discount'))
877 $state[
'discount_last_discount'] =
'N';
880 if($state[
'discount_last_level_discount'] !==
'Y' || !$this->request->getPost(
'discount_last_level_discount'))
882 $state[
'discount_last_level_discount'] =
'N';
885 if(!$this->errorCollection->isEmpty())
887 return array($state,
'CommonSettings');
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;"> '
906 'Perc' =>
Loc::getMessage(
'SHD_BT_SALE_ACT_GROUP_BASKET_SELECT_PERCENT'),
907 'CurEach' => $currency,
908 ), $state->get(
'discount_type')) .
'
916 return static::ACTION_TYPE_DISCOUNT;
928 if (Main\Loader::includeModule(
'crm'))
930 foreach (BuyerGroup::getPublicList() as $group)
932 $groupList[$group[
'ID']] = $group[
'NAME'];
938 $groupIterator = Main\GroupTable::getList([
939 'select' => [
'ID',
'NAME'],
940 'order' => [
'C_SORT' =>
'ASC',
'ID' =>
'ASC'],
942 while ($group = $groupIterator->fetch())
944 $groupList[$group[
'ID']] = $group[
'NAME'];
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)