1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
orderamount.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\DiscountPreset;
4
5use Bitrix\Main\Error;
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;
11
12class OrderAmount extends BasePreset
13{
14 protected function init()
15 {
16 parent::init();
17
18 \CJSCore::RegisterExt(
19 'order_amount_preset',
20 [
21 'js' => '/bitrix/js/sale/admin/discountpreset/order_amount_preset.js',
22 ]
23 );
24
25 \Bitrix\Main\UI\Extension::load(['order_amount_preset']);
26 }
27
28 public function getTitle()
29 {
30 return Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_NAME');
31 }
32
33 public function getDescription()
34 {
35 return Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_DESCRIPTION');
36 }
37
41 public function getCategory()
42 {
43 return Manager::CATEGORY_PRODUCTS;
44 }
45
46 public function getFirstStepName()
47 {
48 return 'InputName';
49 }
50
51 public function processShowInputName(State $state)
52 {
53 return $this->processShowInputNameInternal($state);
54 }
55
56 public function processSaveInputName(State $state)
57 {
58 return $this->processSaveInputNameInternal($state, 'InputAmount');
59 }
60
61 public function processShowInputAmount(State $state)
62 {
63 $lid = $state->get('discount_lid');
64 $currency = \Bitrix\Sale\Internals\SiteCurrencyTable::getSiteCurrency($lid);
65
66 $presetJsName = 'presetOrderAmount';
67
68 $u = new \CAdminPopupEx(
69 "menu_prediction_text",
70 array(
71 array(
72 "TEXT" => Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_ORDER_DISCOUNT_PH_SHORTAGE'),
73 "TITLE" => "",
74 "ONCLICK" => $presetJsName .".insertVar('#SHORTAGE#', 'menu_prediction_text', 'prediction_text')",
75 ),
76 array(
77 "TEXT" => Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ORDERAMOUNT_ORDER_DISCOUNT_PH_DISCOUNT_VALUE'),
78 "TITLE" => "",
79 "ONCLICK" => $presetJsName .".insertVar('#DISCOUNT_VALUE#', 'menu_prediction_text', 'prediction_text')",
80 ),
81 ),
82 array("zIndex" => 2000)
83 );
84 $popupHtml = $u->Show(true);
85
86 return $popupHtml . '
87 <script>
88 var ' . $presetJsName . ' = new BX.Sale.Admin.DiscountPreset.OrderAmount();
89 </script>
90 <table width="100%" border="0" cellspacing="7" cellpadding="0">
91 <tbody>
92 <tr>
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>
96 </td>
97 </tr>
98 <tr>
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>
102 </td>
103 </tr>
104 <tr>
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>
108 </td>
109 </tr>
110 <tr>
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="...">
115 </td>
116 </tr>
117 </tbody>
118 </table>
119 ';
120 }
121
122 public function processSaveInputAmount(State $state)
123 {
124 if(!trim($state->get('discount_order_amount')))
125 {
126 $this->errorCollection[] = new Error(Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_ORDER_AMOUNT'));
127 }
128
129 if(!trim($state->get('discount_value')))
130 {
132 }
133
134 if(!$this->errorCollection->isEmpty())
135 {
136 return array($state, 'InputAmount');
137 }
138
139 return array($state, 'CommonSettings');
140 }
141
142 public function processShowCommonSettings(State $state)
143 {
144 return $this->processShowCommonSettingsInternal($state);
145 }
146
147 public function processSaveCommonSettings(State $state)
148 {
149 return $this->processSaveCommonSettingsInternal($state);
150 }
151
152 public function generateState(array $discountFields)
153 {
154 $discountFields = $this->normalizeDiscountFields($discountFields);
155
156 $stateFields = [
157 'discount_lid' => $discountFields['LID'],
158 'discount_name' => $discountFields['NAME'],
159 'discount_prediction_text' => $discountFields['PREDICTION_TEXT'],
160 'discount_groups' => $this->getUserGroupsByDiscount($discountFields['ID']),
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'),
165 ];
166
167 return parent::generateState($discountFields)->append($stateFields);
168 }
169
170 public function generateDiscount(State $state)
171 {
172 $predictions = null;
173 if($state->get('discount_prediction_value'))
174 {
175 $predictions = array(
176 'CLASS_ID' => 'CondGroup',
177 'DATA' => array(
178 'All' => 'AND',
179 'True' => 'True',
180 ),
181 'CHILDREN' => array(
182 array(
183 'CLASS_ID' => 'CondBsktAmtGroup',
184 'DATA' => array(
185 'logic' => 'EqGr',
186 'Value' => $state->get('discount_prediction_value'),
187 'All' => 'AND',
188 ),
189 'CHILDREN' => array(),
190 ),
191 ),
192 );
193 }
194
195 return array_merge(parent::generateDiscount($state), array(
196 'CONDITIONS' => array(
197 'CLASS_ID' => 'CondGroup',
198 'DATA' => array(
199 'All' => 'AND',
200 'True' => 'True',
201 ),
202 'CHILDREN' => array(
203 array(
204 'CLASS_ID' => 'CondBsktAmtGroup',
205 'DATA' => array(
206 'logic' => 'EqGr',
207 'Value' => $state->get('discount_order_amount'),
208 'All' => 'AND',
209 ),
210 'CHILDREN' => array(),
211 ),
212 ),
213 ),
214 'ACTIONS' => array(
215 'CLASS_ID' => 'CondGroup',
216 'DATA' => array(
217 'All' => 'AND',
218 ),
219 'CHILDREN' => array(
220 array(
221 'CLASS_ID' => 'ActSaleBsktGrp',
222 'DATA' => array(
223 'Type' => 'Discount',
224 'Value' => $state->get('discount_value'),
225 'Unit' => $state->get('discount_type', 'CurAll'),
226 'Max' => 0,
227 'All' => 'AND',
228 'True' => 'True',
229 ),
230 'CHILDREN' => array(),
231 ),
232 ),
233 ),
234 'PREDICTIONS' => $predictions,
235 'PREDICTION_TEXT' => $state->get('discount_prediction_text'),
236 ));
237 }
238}
normalizeDiscountFields(array $discountFields)
Определения basepreset.php:608
processSaveCommonSettingsInternal(State $state, $nextStep=self::FINAL_STEP)
Определения basepreset.php:923
processSaveInputNameInternal(State $state, $nextStep)
Определения basepreset.php:811
processShowInputNameInternal(State $state)
Определения basepreset.php:789
processShowCommonSettingsInternal(State $state)
Определения basepreset.php:836
getUserGroupsByDiscount($discountId)
Определения basepreset.php:703
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
trait Error
Определения error.php:11
$currency
Определения template.php:266