1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
connectedproduct.php
См. документацию.
1<?php
2
3namespace Sale\Handlers\DiscountPreset;
4
5use Bitrix\Main;
6use Bitrix\Main\Error;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Sale\Discount\Preset\ArrayHelper;
9use Bitrix\Sale\Discount\Preset\Manager;
10use Bitrix\Sale\Discount\Preset\SelectProductPreset;
11use Bitrix\Sale\Discount\Preset\State;
12
13class ConnectedProduct extends SelectProductPreset
14{
15 const TYPE_PRODUCT = 'p';
16 const TYPE_SECTION = 's';
17
18 const PREDICTION_TEXT_TYPE_ACTION = 'a';
19 const PREDICTION_TEXT_TYPE_CONDITION = 'c';
20
21 protected function init()
22 {
23 parent::init();
24
25 \CJSCore::RegisterExt(
26 'order_amount_preset',
27 [
28 'js' => '/bitrix/js/sale/admin/discountpreset/connected_product_preset.js',
29 ]
30 );
31
32 \Bitrix\Main\UI\Extension::load(['order_amount_preset']);
33 }
34
35 public function getSort()
36 {
37 return 100;
38 }
39
40 public function getTitle()
41 {
42 return Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_NAME');
43 }
44
45 public function getDescription()
46 {
47 return '';
48 }
49
53 public function getCategory()
54 {
55 return Manager::CATEGORY_PRODUCTS;
56 }
57
58 public function getFirstStepName()
59 {
60 return 'InputName';
61 }
62
63 public function processShowInputName(State $state)
64 {
65 $this->setStepDescription(Loc::getMessage("SALE_HANDLERS_DISCOUNTPRESET_CP_STEP_DESCR_INPUT_NAME"));
66
67 return $this->processShowInputNameInternal($state);
68 }
69
70 public function processSaveInputName(State $state)
71 {
72 return $this->processSaveInputNameInternal($state, 'ProductForDiscount');
73 }
74
75 public function processShowProductForDiscount(State $state)
76 {
77 $this->setStepTitle(Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_STEP_TITLE_DISCOUNT_FOR'));
78 $this->setStepDescription(Loc::getMessage("SALE_HANDLERS_DISCOUNTPRESET_CP_STEP_DESCR_FOR_DISCOUNT"));
79
80 $lid = $state->get('discount_lid');
81 $currency = \CSaleLang::getLangCurrency($lid);
82
83 $sectionCount = count($state->get('discount_section', array()));
84 $presetJsName = 'presetConnectedProduct';
85
86 $u = new \CAdminPopupEx(
87 "menu_prediction_text",
88 array(
89 array(
90 "TEXT" => Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PH_LINK'),
91 "TITLE" => "",
92 "ONCLICK" => $presetJsName .".insertVar('#LINK#', 'menu_prediction_text', 'discount_prediction_text_act')",
93 ),
94 array(
95 "TEXT" => Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PH_DISCOUNT_VALUE'),
96 "TITLE" => "",
97 "ONCLICK" => $presetJsName .".insertVar('#DISCOUNT_VALUE#', 'menu_prediction_text', 'discount_prediction_text_act')",
98 ),
99 array(
100 "TEXT" => Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PH_NAME'),
101 "TITLE" => "",
102 "ONCLICK" => $presetJsName .".insertVar('#NAME#', 'menu_prediction_text', 'discount_prediction_text_act')",
103 ),
104 ),
105 array("zIndex" => 2000)
106 );
107 $popupHtml = $u->Show(true);
108
109 return $popupHtml . '
110 <script>
111 var ' . $presetJsName . ' = new BX.Sale.Admin.DiscountPreset.ConnectedProduct();
112 </script>
113 <table width="100%" border="0" cellspacing="7" cellpadding="0">
114 <tbody>
115 ' . $this->renderDiscountValue($state, $currency) . '
116 </tbody>
117 </table>
118
119 <script type="application/javascript">
120 BX.ready(function(){
121 new BX.Sale.Admin.DiscountPreset.SelectProduct({
122 presetId: "' . \CUtil::JSEscape($this->className()) . '",
123 siteId: "' . \CUtil::JSEscape($lid) . '",
124 sectionCount: ' . $sectionCount . ',
125 products: ' . \CUtil::PhpToJSObject($this->generateProductsData($state->get('discount_product'), $lid)) . '
126 });
127 });
128 </script>
129
130 ' . $this->renderElementBlock($state) . '
131 ' . $this->renderSectionBlock($state) . '
132 <table width="100%" border="0" cellspacing="7" cellpadding="0">
133 <tbody>
134 <tr>
135 <td class="adm-detail-content-cell-l" style="width:20%;"><strong>' . Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PREDICTION_TEXT') . ':</strong></td>
136 <td class="adm-detail-content-cell-r" style="width:80%;">
137 <textarea name="discount_prediction_text_act" id="discount_prediction_text_act" cols="55" rows="1" style="width: 90%; margin-top: 0; margin-bottom: 0; height: 50px;">' . htmlspecialcharsbx($state->get('discount_prediction_text_act', Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PREDICTION_TEXT_DEFAULT_ACT'))) . '</textarea>
138 <input style="float:right" type="button" id="menu_prediction_text" value="...">
139 </td>
140 </tr>
141 </tbody>
142 </table>
143 ';
144 }
145
146 public function processSaveProductForDiscount(State $state)
147 {
148 if(!trim($state->get('discount_value')))
149 {
151 }
152
153 $this->validateSectionsAndProductsState($state, $this->errorCollection);
154
155 if(!$this->errorCollection->isEmpty())
156 {
157 return array($state, 'ProductForDiscount');
158 }
159
160 return array($state, 'ProductWhenDiscount');
161 }
162
163 public function processShowProductWhenDiscount(State $state)
164 {
165 $this->setStepTitle(Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_STEP_TITLE_DISCOUNT_WHEN'));
166 $this->setStepDescription(Loc::getMessage("SALE_HANDLERS_DISCOUNTPRESET_CP_STEP_DESCR_WHEN_DISCOUNT"));
167
168 $lid = $state->get('discount_lid');
169 $sectionCount = count($state->get('discount_cond_section', array()));
170
171 $presetJsName = 'presetConnectedProduct';
172
173 $u = new \CAdminPopupEx(
174 "menu_prediction_text",
175 array(
176 array(
177 "TEXT" => Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PH_LINK'),
178 "TITLE" => "",
179 "ONCLICK" => $presetJsName .".insertVar('#LINK#', 'menu_prediction_text', 'discount_prediction_text_cond')",
180 ),
181 array(
182 "TEXT" => Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PH_DISCOUNT_VALUE'),
183 "TITLE" => "",
184 "ONCLICK" => $presetJsName .".insertVar('#DISCOUNT_VALUE#', 'menu_prediction_text', 'discount_prediction_text_cond')",
185 ),
186 array(
187 "TEXT" => Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PH_NAME'),
188 "TITLE" => "",
189 "ONCLICK" => $presetJsName .".insertVar('#NAME#', 'menu_prediction_text', 'discount_prediction_text_cond')",
190 ),
191 ),
192 array("zIndex" => 2000)
193 );
194 $popupHtml = $u->Show(true);
195
196 return $popupHtml . '
197 <script>
198 var ' . $presetJsName . ' = new BX.Sale.Admin.DiscountPreset.ConnectedProduct();
199 </script>
200 <script type="application/javascript">
201 BX.ready(function(){
202 new BX.Sale.Admin.DiscountPreset.SelectProduct({
203 presetId: "' . \CUtil::JSEscape($this->className()) . '",
204 siteId: "' . \CUtil::JSEscape($lid) . '",
205 sectionCount: ' . $sectionCount . ',
206 inputNameProduct: "discount_cond_product[]",
207 inputNameSection: "discount_cond_section[]",
208 products: ' . \CUtil::PhpToJSObject($this->generateProductsData($state->get('discount_cond_product'), $lid)) . '
209 });
210 });
211 </script>
212
213 ' . $this->renderElementBlock($state, 'discount_cond_product', true) . '
214 ' . $this->renderSectionBlock($state, 'discount_cond_section', true) . '
215 <table width="100%" border="0" cellspacing="7" cellpadding="0">
216 <tbody>
217 <tr>
218 <td class="adm-detail-content-cell-l" style="width:20%;"><strong>' . Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PREDICTION_TEXT') . ':</strong></td>
219 <td class="adm-detail-content-cell-r" style="width:80%;">
220 <textarea name="discount_prediction_text_cond" id="discount_prediction_text_cond" cols="55" rows="1" style="width: 90%; margin-top: 0; margin-bottom: 0; height: 50px;">' . htmlspecialcharsbx($state->get('discount_prediction_text_cond', Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PREDICTION_TEXT_DEFAULT_COND'))) . '</textarea>
221 <input style="float:right" type="button" id="menu_prediction_text" value="...">
222 </td>
223 </tr>
224 </tbody>
225 </table>
226 ';
227 }
228
229 public function processSaveProductWhenDiscount(State $state)
230 {
231 if(!is_array($state->get('discount_cond_product', array())))
232 {
233 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_ERROR_SECTION_NON_ARRAY'));
234 }
235
236 if(!is_array($state->get('discount_cond_section', array())))
237 {
238 $this->errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_ERROR_PRODUCT_NON_ARRAY'));
239 }
240
241 if(!$this->errorCollection->isEmpty())
242 {
243 return array($state, 'ProductWhenDiscount');
244 }
245
246 return array($state, 'CommonSettings');
247 }
248
249 public function processShowCommonSettings(State $state)
250 {
251 return $this->processShowCommonSettingsInternal($state);
252 }
253
254 public function processSaveCommonSettings(State $state)
255 {
256 return $this->processSaveCommonSettingsInternal($state);
257 }
258
264 public function generateState(array $discountFields)
265 {
266 $discountFields = $this->normalizeDiscountFields($discountFields);
267
268 $stateFields = array(
269 'discount_value' => ArrayHelper::getByPath($discountFields, 'ACTIONS.CHILDREN.0.DATA.Value'),
270 'discount_type' => ArrayHelper::getByPath($discountFields, 'ACTIONS.CHILDREN.0.DATA.Unit'),
271 'discount_section' => $this->getSectionsFromConditions(ArrayHelper::getByPath($discountFields, 'ACTIONS.CHILDREN.0.CHILDREN.0.CHILDREN')),
272 'discount_product' => $this->getProductsFromConditions(ArrayHelper::getByPath($discountFields, 'ACTIONS.CHILDREN.0.CHILDREN.1.CHILDREN')),
273 'discount_cond_section' => $this->getSectionsFromConditions(ArrayHelper::getByPath($discountFields, 'CONDITIONS.CHILDREN.0.CHILDREN.0.CHILDREN.0.CHILDREN')),
274 'discount_cond_product' => $this->getProductsFromConditions(ArrayHelper::getByPath($discountFields, 'CONDITIONS.CHILDREN.0.CHILDREN.1.CHILDREN.0.CHILDREN')),
275 );
276
277 if(!empty($discountFields['PREDICTION_TEXT']) && is_string($discountFields['PREDICTION_TEXT']))
278 list(
279 $stateFields['discount_prediction_text_act'],
280 $stateFields['discount_prediction_text_cond']
281 ) = explode('|del|', $discountFields['PREDICTION_TEXT']);
282
283 return parent::generateState($discountFields)->append($stateFields);
284 }
285
286 private function generatePredictions(State $state)
287 {
288 $generateProductPredictions = $this->generateProductConditions(
289 array_unique(array_merge($state->get('discount_cond_product', array()), $state->get('discount_product', array())))
290 );
291 $generateSectionPredictions = $this->generateSectionConditions(
292 array_unique(array_merge($state->get('discount_cond_section', array()), $state->get('discount_section', array())))
293 );
294
295 $predictions = array(
296 'CLASS_ID' => 'CondGroup',
297 'DATA' => array(
298 'All' => 'AND',
299 'True' => 'True',
300 ),
301 'CHILDREN' => array(
302 array(
303 'CLASS_ID' => 'CondGroup',
304 'DATA' => array(
305 'All' => 'OR',
306 'True' => 'True',
307 ),
308 'CHILDREN' => array(
309 $generateSectionPredictions ? array(
310 'CLASS_ID' => 'CondGroup',
311 'DATA' => array(
312 'All' => 'AND',
313 'True' => 'True',
314 ),
315 'CHILDREN' => array(
316 array(
317 'CLASS_ID' => 'CondBsktProductGroup',
318 'DATA' => array(
319 'Found' => 'Found',
320 'All' => 'OR',
321 ),
322 'CHILDREN' => $generateSectionPredictions,
323 ),
324 ),
325 ) : array(),
326 $generateProductPredictions ? array(
327 'CLASS_ID' => 'CondGroup',
328 'DATA' => array(
329 'All' => 'AND',
330 'True' => 'True',
331 ),
332 'CHILDREN' => array(
333 array(
334 'CLASS_ID' => 'CondBsktProductGroup',
335 'DATA' => array(
336 'Found' => 'Found',
337 'All' => 'OR',
338 ),
339 'CHILDREN' => $generateProductPredictions,
340 ),
341 ),
342 ) : array(),
343 ),
344 ),
345 ),
346 );
347
348 return $predictions;
349 }
350
351 public function generateDiscount(State $state)
352 {
353 $generateProductConditions = $this->generateProductConditions($state->get('discount_cond_product'));
354 $generateSectionConditions = $this->generateSectionConditions($state->get('discount_cond_section'));
355
356 return array_merge(parent::generateDiscount($state), array(
357 'PREDICTION_TEXT' => implode('|del|', array(
358 $state->get('discount_prediction_text_act'),
359 $state->get('discount_prediction_text_cond'),
360 )),
361 'PREDICTIONS' => $this->generatePredictions($state),
362 'CONDITIONS' => array(
363 'CLASS_ID' => 'CondGroup',
364 'DATA' => array(
365 'All' => 'AND',
366 'True' => 'True',
367 ),
368 'CHILDREN' => array(
369 array(
370 'CLASS_ID' => 'CondGroup',
371 'DATA' => array(
372 'All' => 'OR',
373 'True' => 'True',
374 ),
375 'CHILDREN' => array(
376 $generateSectionConditions? array(
377 'CLASS_ID' => 'CondGroup',
378 'DATA' => array(
379 'All' => 'AND',
380 'True' => 'True',
381 ),
382 'CHILDREN' => array(
383 array(
384 'CLASS_ID' => 'CondBsktProductGroup',
385 'DATA' => array(
386 'Found' => 'Found',
387 'All' => 'OR',
388 ),
389 'CHILDREN' => $generateSectionConditions,
390 ),
391 ),
392 ) : array(),
393 $generateProductConditions? array(
394 'CLASS_ID' => 'CondGroup',
395 'DATA' => array(
396 'All' => 'AND',
397 'True' => 'True',
398 ),
399 'CHILDREN' => array(
400 array(
401 'CLASS_ID' => 'CondBsktProductGroup',
402 'DATA' => array(
403 'Found' => 'Found',
404 'All' => 'OR',
405 ),
406 'CHILDREN' => $generateProductConditions,
407 ),
408 ),
409 ) : array(),
410 ),
411 ),
412 ),
413 ),
414 'ACTIONS' => array(
415 'CLASS_ID' => 'CondGroup',
416 'DATA' => array(
417 'All' => 'AND',
418 ),
419 'CHILDREN' => array(
420 array(
421 'CLASS_ID' => 'ActSaleBsktGrp',
422 'DATA' => array(
423 'Type' => $this->getTypeOfDiscount(),
424 'Value' => $state->get('discount_value'),
425 'Unit' => $state->get('discount_type', 'CurAll'),
426 'Max' => 0,
427 'All' => 'OR',
428 'True' => 'True',
429 ),
430 'CHILDREN' => array(
431 $this->generateSectionActions($state->get('discount_section')),
432 $this->generateProductActions($state->get('discount_product')),
433 ),
434 ),
435 ),
436 ),
437 ));
438 }
439
440 public function getDescribedDataProductCondition(State $state)
441 {
442 $product = $state->get('discount_cond_product', array());
443 $section = $state->get('discount_cond_section', array());
444
445 if($product)
446 {
447 return array($this::TYPE_PRODUCT, $product);
448 }
449 elseif($section)
450 {
451 return array($this::TYPE_SECTION, $section);
452 }
453
454 return null;
455 }
456
457 public function getDescribedDataProductAction(State $state)
458 {
459 $product = $state->get('discount_product', array());
460 $section = $state->get('discount_section', array());
461
462 if($product)
463 {
464 return array($this::TYPE_PRODUCT, $product);
465 }
466 elseif($section)
467 {
468 return array($this::TYPE_SECTION, $section);
469 }
470
471 return null;
472 }
473
474 public function getPredictionText(State $state, $type)
475 {
476 if($type === static::PREDICTION_TEXT_TYPE_ACTION)
477 {
478 return $state['discount_prediction_text_act'];
479 }
480 elseif($type === static::PREDICTION_TEXT_TYPE_CONDITION)
481 {
482 return $state['discount_prediction_text_cond'];
483 }
484
485 return null;
486 }
487}
$type
Определения options.php:106
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
renderDiscountValue(State $state, $currency)
Определения basepreset.php:963
setStepDescription($stepDescription)
Определения basepreset.php:417
processShowCommonSettingsInternal(State $state)
Определения basepreset.php:836
setStepTitle($stepTitle)
Определения basepreset.php:400
getSectionsFromConditions(array $conditions=null)
Определения selectproductpreset.php:154
validateSectionsAndProductsState(State $state, ErrorCollection $errorCollection)
Определения selectproductpreset.php:315
generateSectionConditions($sectionIds, $logic='Equal')
Определения selectproductpreset.php:201
generateProductsData($productIds, $siteId)
Определения selectproductpreset.php:293
renderSectionBlock(State $state, $inputName='discount_section', $multi=true)
Определения selectproductpreset.php:79
renderElementBlock(State $state, $inputName='discount_product', $multi=true)
Определения selectproductpreset.php:35
getProductsFromConditions(array $conditions=null)
Определения selectproductpreset.php:174
generateProductConditions($productIds, $logic='Equal')
Определения selectproductpreset.php:230
</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
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$currency
Определения template.php:266