3namespace Sale\Handlers\DiscountPreset;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Sale\Discount\Preset\ArrayHelper;
9use Bitrix\Sale\Discount\Preset\HtmlHelper;
10use Bitrix\Sale\Discount\Preset\Manager;
11use Bitrix\Sale\Discount\Preset\SelectProductPreset;
12use Bitrix\Sale\Discount\Preset\State;
13use Bitrix\Sale\Internals;
22 protected function init()
26 if (!Main\Loader::includeModule(
'iblock'))
28 throw new Main\SystemException(
'Could not include iblock module');
31 \CJSCore::RegisterExt(
34 'js' =>
'/bitrix/js/sale/admin/discountpreset/perday_preset.js',
35 'rel' => [
'select_product_preset']
39 \CJSCore::Init([
'perday_preset']);
44 return Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_PERDAY_NAME');
57 return Manager::CATEGORY_PRODUCTS;
65 public function processShowInputName(State $state)
70 public function processSaveInputName(State $state)
75 public function processShowInputAmount(State $state)
77 $lid = $state->get(
'discount_lid');
78 $currency = Internals\SiteCurrencyTable::getSiteCurrency($lid);
81 1 => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_PERDAY_DAY_OF_WEEK_1'),
82 2 => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_PERDAY_DAY_OF_WEEK_2'),
83 3 => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_PERDAY_DAY_OF_WEEK_3'),
84 4 => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_PERDAY_DAY_OF_WEEK_4'),
85 5 => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_PERDAY_DAY_OF_WEEK_5'),
86 6 => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_PERDAY_DAY_OF_WEEK_6'),
87 7 => Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_PERDAY_DAY_OF_WEEK_7'),
90 $sectionCount =
count($state->get(
'discount_section',
array()));
93 <table width="100%" border="0" cellspacing="7" cellpadding="0">
96 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_PERDAY_DISCOUNT_VALUE') .
':</strong></td>
97 <td class="adm-detail-content-cell-r" style="width:60%;">
98 <input type="text" name="discount_value" value="' .
htmlspecialcharsbx($state->get(
'discount_value')) .
'" maxlength="100" style="width: 100px;"> <span>' .
$currency .
'</span>
102 <td class="adm-detail-content-cell-l" style="width:40%;"><strong>' . Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_PERDAY_DAY_LABEL') .
':</strong></td>
103 <td class="adm-detail-content-cell-r">
104 ' . HtmlHelper::generateMultipleSelect(
'discount_days[]', $days, $state->get(
'discount_days',
array()),
array(
'size=7')) .
'
110 <script type="application/javascript">
112 new BX.Sale.Admin.DiscountPreset.PerDay({
113 presetId: "' . \CUtil::JSEscape($this->
className()) .
'",
114 siteId: "' . \CUtil::JSEscape($lid) .
'",
115 sectionCount: ' . $sectionCount .
',
116 products: ' . \CUtil::PhpToJSObject($this->
generateProductsData($state->get(
'discount_product'), $lid)) .
'
126 public function processSaveInputAmount(State $state)
128 if(!trim($state->get(
'discount_value')))
133 if(!$state->get(
'discount_days'))
135 $this->errorCollection[] =
new Error(Loc::getMessage(
'SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_VALUE_DAYS'));
140 if(!$this->errorCollection->isEmpty())
142 return array($state,
'InputAmount');
145 return array($state,
'CommonSettings');
148 public function processShowCommonSettings(State $state)
153 public function processSaveCommonSettings(State $state)
158 public function generateState(
array $discountFields)
163 'discount_lid' => $discountFields[
'LID'],
164 'discount_name' => $discountFields[
'NAME'],
166 'discount_value' => ArrayHelper::getByPath($discountFields,
'ACTIONS.CHILDREN.0.DATA.Value'),
167 'discount_type' => ArrayHelper::getByPath($discountFields,
'ACTIONS.CHILDREN.0.DATA.Unit'),
168 'discount_days' => ArrayHelper::getByPath($discountFields,
'CONDITIONS.CHILDREN.0.DATA.value'),
169 'discount_section' => $this->
getSectionsFromConditions(ArrayHelper::getByPath($discountFields,
'CONDITIONS.CHILDREN.1.CHILDREN.0.CHILDREN.0.CHILDREN')),
170 'discount_product' => $this->
getProductsFromConditions(ArrayHelper::getByPath($discountFields,
'CONDITIONS.CHILDREN.1.CHILDREN.1.CHILDREN.0.CHILDREN')),
173 return parent::generateState($discountFields)->append($stateFields);
176 public function generateDiscount(State $state)
182 parent::generateDiscount($state),
185 'CLASS_ID' =>
'CondGroup',
192 'CLASS_ID' =>
'CondSaleCmnDayOfWeek',
195 'value' => $state->get(
'discount_days'),
199 'CLASS_ID' =>
'CondGroup',
205 $generateSectionConditions? [
206 'CLASS_ID' =>
'CondGroup',
213 'CLASS_ID' =>
'CondBsktProductGroup',
218 'CHILDREN' => $generateSectionConditions,
222 $generateProductConditions? [
223 'CLASS_ID' =>
'CondGroup',
230 'CLASS_ID' =>
'CondBsktProductGroup',
235 'CHILDREN' => $generateProductConditions,
244 'CLASS_ID' =>
'CondGroup',
250 'CLASS_ID' =>
'ActSaleBsktGrp',
252 'Type' =>
'Discount',
253 'Value' => $state->get(
'discount_value'),
254 'Unit' => $state->get(
'discount_type',
'CurAll'),
260 $this->generateSectionActions($state->get(
'discount_section')),
261 $this->generateProductActions($state->get(
'discount_product')),
normalizeDiscountFields(array $discountFields)
processSaveCommonSettingsInternal(State $state, $nextStep=self::FINAL_STEP)
processSaveInputNameInternal(State $state, $nextStep)
processShowInputNameInternal(State $state)
processShowCommonSettingsInternal(State $state)
addErrorEmptyActionValue()
getUserGroupsByDiscount($discountId)
getSectionsFromConditions(array $conditions=null)
validateSectionsAndProductsState(State $state, ErrorCollection $errorCollection)
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)
</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."%"