3namespace Sale\Handlers\DiscountPreset;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Sale\Discount\Preset\ArrayHelper;
8use Bitrix\Sale\Discount\Preset\BasePreset;
9use Bitrix\Sale\Discount\Preset\Manager;
10use Bitrix\Sale\Discount\Preset\State;
14 protected function init()
18 \CJSCore::RegisterExt(
19 'order_amount_preset',
21 'js' =>
'/bitrix/js/sale/admin/discountpreset/order_amount_preset.js',
25 \Bitrix\Main\UI\Extension::load([
'order_amount_preset']);
30 return Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_NAME');
35 return Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_DESCRIPTION');
43 return Manager::CATEGORY_PRODUCTS;
51 public function processShowInputName(State $state)
56 public function processSaveInputName(State $state)
61 public function processShowInputAmount(State $state)
63 $lid = $state->get(
'discount_lid');
64 $currency = \Bitrix\Sale\Internals\SiteCurrencyTable::getSiteCurrency($lid);
66 $presetJsName =
'presetOrderAmount';
68 $u = new \CAdminPopupEx(
69 "menu_prediction_text",
72 "TEXT" => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_ORDER_DISCOUNT_PH_SHORTAGE'),
74 "ONCLICK" => $presetJsName .
".insertVar('#SHORTAGE#', 'menu_prediction_text', 'prediction_text')",
77 "TEXT" => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_ORDER_DISCOUNT_PH_DISCOUNT_VALUE'),
79 "ONCLICK" => $presetJsName .
".insertVar('#DISCOUNT_VALUE#', 'menu_prediction_text', 'prediction_text')",
82 array(
"zIndex" => 2000)
84 $popupHtml = $u->Show(
true);
88 var ' . $presetJsName .
' = new BX.Sale.Admin.DiscountPreset.OrderAmount();
90 <table width="100%" border="0" cellspacing="7" cellpadding="0">
93 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_ORDER_AMOUNT') .
':</strong></td>
94 <td class="adm-detail-content-cell-r" style="width:60%;">
95 <input type="text" name="discount_order_amount" value="' .
htmlspecialcharsbx($state->get(
'discount_order_amount')) .
'" size="39" maxlength="100" style="width: 100px;"> <span>' .
$currency .
'</span>
99 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_ORDER_DISCOUNT_VALUE') .
':</strong></td>
100 <td class="adm-detail-content-cell-r" style="width:60%;">
101 <input type="text" name="discount_value" value="' .
htmlspecialcharsbx($state->get(
'discount_value')) .
'" maxlength="100" style="width: 100px;"> <span>' .
$currency .
'</span>
105 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_ORDER_DISCOUNT_PREDICTION_VALUE') .
':</strong></td>
106 <td class="adm-detail-content-cell-r" style="width:60%;">
107 <input type="text" name="discount_prediction_value" value="' .
htmlspecialcharsbx($state->get(
'discount_prediction_value')) .
'" maxlength="100" style="width: 100px;"> <span>' .
$currency .
'</span>
111 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_ORDER_DISCOUNT_PREDICTION_TEXT') .
':</strong></td>
112 <td class="adm-detail-content-cell-r" style="width:60%;">
113 <textarea name="discount_prediction_text" id="prediction_text" cols="55" rows="1" style="width: 90%; margin-top: 0; margin-bottom: 0; height: 50px;">' .
htmlspecialcharsbx($state->get(
'discount_prediction_text', Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_ORDER_DISCOUNT_PREDICTION_TEXT_DEFAULT'))) .
'</textarea>
114 <input style="float:right" type="button" id="menu_prediction_text" value="...">
122 public function processSaveInputAmount(State $state)
124 if(!trim($state->get(
'discount_order_amount')))
126 $this->errorCollection[] =
new Error(Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_ORDER_AMOUNT'));
129 if(!trim($state->get(
'discount_value')))
134 if(!$this->errorCollection->isEmpty())
136 return array($state,
'InputAmount');
139 return array($state,
'CommonSettings');
142 public function processShowCommonSettings(State $state)
147 public function processSaveCommonSettings(State $state)
152 public function generateState(
array $discountFields)
157 'discount_lid' => $discountFields[
'LID'],
158 'discount_name' => $discountFields[
'NAME'],
159 'discount_prediction_text' => $discountFields[
'PREDICTION_TEXT'],
161 'discount_order_amount' => ArrayHelper::getByPath($discountFields,
'CONDITIONS.CHILDREN.0.DATA.Value'),
162 'discount_value' => ArrayHelper::getByPath($discountFields,
'ACTIONS.CHILDREN.0.DATA.Value'),
163 'discount_type' => ArrayHelper::getByPath($discountFields,
'ACTIONS.CHILDREN.0.DATA.Unit'),
164 'discount_prediction_value' => ArrayHelper::getByPath($discountFields,
'PREDICTIONS.CHILDREN.0.DATA.Value'),
167 return parent::generateState($discountFields)->append($stateFields);
170 public function generateDiscount(State $state)
173 if($state->get(
'discount_prediction_value'))
175 $predictions =
array(
176 'CLASS_ID' =>
'CondGroup',
183 'CLASS_ID' =>
'CondBsktAmtGroup',
186 'Value' => $state->get(
'discount_prediction_value'),
189 'CHILDREN' =>
array(),
195 return array_merge(parent::generateDiscount($state),
array(
196 'CONDITIONS' =>
array(
197 'CLASS_ID' =>
'CondGroup',
204 'CLASS_ID' =>
'CondBsktAmtGroup',
207 'Value' => $state->get(
'discount_order_amount'),
210 'CHILDREN' =>
array(),
215 'CLASS_ID' =>
'CondGroup',
221 'CLASS_ID' =>
'ActSaleBsktGrp',
223 'Type' =>
'Discount',
224 'Value' => $state->get(
'discount_value'),
225 'Unit' => $state->get(
'discount_type',
'CurAll'),
230 'CHILDREN' =>
array(),
234 'PREDICTIONS' => $predictions,
235 'PREDICTION_TEXT' => $state->get(
'discount_prediction_text'),
normalizeDiscountFields(array $discountFields)
processSaveCommonSettingsInternal(State $state, $nextStep=self::FINAL_STEP)
processSaveInputNameInternal(State $state, $nextStep)
processShowInputNameInternal(State $state)
processShowCommonSettingsInternal(State $state)
addErrorEmptyActionValue()
getUserGroupsByDiscount($discountId)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)