3namespace Sale\Handlers\DiscountPreset;
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;
15 const TYPE_PRODUCT =
'p';
16 const TYPE_SECTION =
's';
18 const PREDICTION_TEXT_TYPE_ACTION =
'a';
19 const PREDICTION_TEXT_TYPE_CONDITION =
'c';
21 protected function init()
25 \CJSCore::RegisterExt(
26 'order_amount_preset',
28 'js' =>
'/bitrix/js/sale/admin/discountpreset/connected_product_preset.js',
32 \Bitrix\Main\UI\Extension::load([
'order_amount_preset']);
42 return Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_CP_NAME');
55 return Manager::CATEGORY_PRODUCTS;
63 public function processShowInputName(State $state)
65 $this->
setStepDescription(Loc::getMessage(
"SALE_HANDLERS_DISCOUNTPRESET_CP_STEP_DESCR_INPUT_NAME"));
70 public function processSaveInputName(State $state)
75 public function processShowProductForDiscount(State $state)
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"));
80 $lid = $state->get(
'discount_lid');
81 $currency = \CSaleLang::getLangCurrency($lid);
83 $sectionCount =
count($state->get(
'discount_section',
array()));
84 $presetJsName =
'presetConnectedProduct';
86 $u = new \CAdminPopupEx(
87 "menu_prediction_text",
90 "TEXT" => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PH_LINK'),
92 "ONCLICK" => $presetJsName .
".insertVar('#LINK#', 'menu_prediction_text', 'discount_prediction_text_act')",
95 "TEXT" => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PH_DISCOUNT_VALUE'),
97 "ONCLICK" => $presetJsName .
".insertVar('#DISCOUNT_VALUE#', 'menu_prediction_text', 'discount_prediction_text_act')",
100 "TEXT" => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PH_NAME'),
102 "ONCLICK" => $presetJsName .
".insertVar('#NAME#', 'menu_prediction_text', 'discount_prediction_text_act')",
105 array(
"zIndex" => 2000)
107 $popupHtml = $u->Show(
true);
109 return $popupHtml .
'
111 var ' . $presetJsName .
' = new BX.Sale.Admin.DiscountPreset.ConnectedProduct();
113 <table width="100%" border="0" cellspacing="7" cellpadding="0">
119 <script type="application/javascript">
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)) .
'
132 <table width="100%" border="0" cellspacing="7" cellpadding="0">
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="...">
146 public function processSaveProductForDiscount(State $state)
148 if(!trim($state->get(
'discount_value')))
155 if(!$this->errorCollection->isEmpty())
157 return array($state,
'ProductForDiscount');
160 return array($state,
'ProductWhenDiscount');
163 public function processShowProductWhenDiscount(State $state)
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"));
168 $lid = $state->get(
'discount_lid');
169 $sectionCount =
count($state->get(
'discount_cond_section',
array()));
171 $presetJsName =
'presetConnectedProduct';
173 $u = new \CAdminPopupEx(
174 "menu_prediction_text",
177 "TEXT" => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PH_LINK'),
179 "ONCLICK" => $presetJsName .
".insertVar('#LINK#', 'menu_prediction_text', 'discount_prediction_text_cond')",
182 "TEXT" => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PH_DISCOUNT_VALUE'),
184 "ONCLICK" => $presetJsName .
".insertVar('#DISCOUNT_VALUE#', 'menu_prediction_text', 'discount_prediction_text_cond')",
187 "TEXT" => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_CP_DISCOUNT_PH_NAME'),
189 "ONCLICK" => $presetJsName .
".insertVar('#NAME#', 'menu_prediction_text', 'discount_prediction_text_cond')",
192 array(
"zIndex" => 2000)
194 $popupHtml = $u->Show(
true);
196 return $popupHtml .
'
198 var ' . $presetJsName .
' = new BX.Sale.Admin.DiscountPreset.ConnectedProduct();
200 <script type="application/javascript">
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)) .
'
215 <table width="100%" border="0" cellspacing="7" cellpadding="0">
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="...">
229 public function processSaveProductWhenDiscount(State $state)
231 if(!is_array($state->get(
'discount_cond_product',
array())))
233 $this->errorCollection[] =
new Error(Loc::getMessage(
'SALE_BASE_PRESET_ERROR_SECTION_NON_ARRAY'));
236 if(!is_array($state->get(
'discount_cond_section',
array())))
238 $this->errorCollection[] =
new Error(Loc::getMessage(
'SALE_BASE_PRESET_ERROR_PRODUCT_NON_ARRAY'));
241 if(!$this->errorCollection->isEmpty())
243 return array($state,
'ProductWhenDiscount');
246 return array($state,
'CommonSettings');
249 public function processShowCommonSettings(State $state)
254 public function processSaveCommonSettings(State $state)
264 public function generateState(
array $discountFields)
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')),
277 if(!empty($discountFields[
'PREDICTION_TEXT']) && is_string($discountFields[
'PREDICTION_TEXT']))
279 $stateFields[
'discount_prediction_text_act'],
280 $stateFields[
'discount_prediction_text_cond']
281 ) = explode(
'|del|', $discountFields[
'PREDICTION_TEXT']);
283 return parent::generateState($discountFields)->append($stateFields);
286 private function generatePredictions(State $state)
289 array_unique(array_merge($state->get(
'discount_cond_product',
array()), $state->get(
'discount_product',
array())))
292 array_unique(array_merge($state->get(
'discount_cond_section',
array()), $state->get(
'discount_section',
array())))
295 $predictions =
array(
296 'CLASS_ID' =>
'CondGroup',
303 'CLASS_ID' =>
'CondGroup',
309 $generateSectionPredictions ?
array(
310 'CLASS_ID' =>
'CondGroup',
317 'CLASS_ID' =>
'CondBsktProductGroup',
322 'CHILDREN' => $generateSectionPredictions,
326 $generateProductPredictions ?
array(
327 'CLASS_ID' =>
'CondGroup',
334 'CLASS_ID' =>
'CondBsktProductGroup',
339 'CHILDREN' => $generateProductPredictions,
351 public function generateDiscount(State $state)
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'),
361 'PREDICTIONS' => $this->generatePredictions($state),
362 'CONDITIONS' =>
array(
363 'CLASS_ID' =>
'CondGroup',
370 'CLASS_ID' =>
'CondGroup',
376 $generateSectionConditions?
array(
377 'CLASS_ID' =>
'CondGroup',
384 'CLASS_ID' =>
'CondBsktProductGroup',
389 'CHILDREN' => $generateSectionConditions,
393 $generateProductConditions?
array(
394 'CLASS_ID' =>
'CondGroup',
401 'CLASS_ID' =>
'CondBsktProductGroup',
406 'CHILDREN' => $generateProductConditions,
415 'CLASS_ID' =>
'CondGroup',
421 'CLASS_ID' =>
'ActSaleBsktGrp',
424 'Value' => $state->get(
'discount_value'),
425 'Unit' => $state->get(
'discount_type',
'CurAll'),
432 $this->generateProductActions($state->get(
'discount_product')),
440 public function getDescribedDataProductCondition(State $state)
442 $product = $state->get(
'discount_cond_product',
array());
443 $section = $state->get(
'discount_cond_section',
array());
447 return array($this::TYPE_PRODUCT, $product);
451 return array($this::TYPE_SECTION, $section);
457 public function getDescribedDataProductAction(State $state)
459 $product = $state->get(
'discount_product',
array());
460 $section = $state->get(
'discount_section',
array());
464 return array($this::TYPE_PRODUCT, $product);
468 return array($this::TYPE_SECTION, $section);
474 public function getPredictionText(State $state,
$type)
476 if(
$type === static::PREDICTION_TEXT_TYPE_ACTION)
478 return $state[
'discount_prediction_text_act'];
480 elseif(
$type === static::PREDICTION_TEXT_TYPE_CONDITION)
482 return $state[
'discount_prediction_text_cond'];
normalizeDiscountFields(array $discountFields)
processSaveCommonSettingsInternal(State $state, $nextStep=self::FINAL_STEP)
processSaveInputNameInternal(State $state, $nextStep)
processShowInputNameInternal(State $state)
renderDiscountValue(State $state, $currency)
setStepDescription($stepDescription)
processShowCommonSettingsInternal(State $state)
addErrorEmptyActionValue()
getSectionsFromConditions(array $conditions=null)
validateSectionsAndProductsState(State $state, ErrorCollection $errorCollection)
generateSectionActions($sectionIds)
generateSectionConditions($sectionIds, $logic='Equal')
generateProductsData($productIds, $siteId)
renderSectionBlock(State $state, $inputName='discount_section', $multi=true)
renderElementBlock(State $state, $inputName='discount_product', $multi=true)
getProductsFromConditions(array $conditions=null)
generateProductConditions($productIds, $logic='Equal')
</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)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
</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."%"