1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
productperday.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\HtmlHelper;
10use Bitrix\Sale\Discount\Preset\Manager;
11use Bitrix\Sale\Discount\Preset\SelectProductPreset;
12use Bitrix\Sale\Discount\Preset\State;
13use Bitrix\Sale\Internals;
14
15class ProductPerDay extends SelectProductPreset
16{
17 public function getSort()
18 {
19 return 200;
20 }
21
22 protected function init()
23 {
24 parent::init();
25
26 if (!Main\Loader::includeModule('iblock'))
27 {
28 throw new Main\SystemException('Could not include iblock module');
29 }
30
31 \CJSCore::RegisterExt(
32 'perday_preset',
33 [
34 'js' => '/bitrix/js/sale/admin/discountpreset/perday_preset.js',
35 'rel' => ['select_product_preset']
36 ]
37 );
38
39 \CJSCore::Init(['perday_preset']);
40 }
41
42 public function getTitle()
43 {
44 return Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_PERDAY_NAME');
45 }
46
47 public function getDescription()
48 {
49 return '';
50 }
51
55 public function getCategory()
56 {
57 return Manager::CATEGORY_PRODUCTS;
58 }
59
60 public function getFirstStepName()
61 {
62 return 'InputName';
63 }
64
65 public function processShowInputName(State $state)
66 {
67 return $this->processShowInputNameInternal($state);
68 }
69
70 public function processSaveInputName(State $state)
71 {
72 return $this->processSaveInputNameInternal($state, 'InputAmount');
73 }
74
75 public function processShowInputAmount(State $state)
76 {
77 $lid = $state->get('discount_lid');
78 $currency = Internals\SiteCurrencyTable::getSiteCurrency($lid);
79
80 $days = [
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'),
88 ];
89
90 $sectionCount = count($state->get('discount_section', array()));
91
92 return '
93 <table width="100%" border="0" cellspacing="7" cellpadding="0">
94 <tbody>
95 <tr>
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>
99 </td>
100 </tr>
101 <tr>
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')) . '
105 </td>
106 </tr>
107 </tbody>
108 </table>
109
110 <script type="application/javascript">
111 BX.ready(function(){
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)) . '
117 });
118 });
119 </script>
120
121 ' . $this->renderElementBlock($state) . '
122 ' . $this->renderSectionBlock($state) . '
123 ';
124 }
125
126 public function processSaveInputAmount(State $state)
127 {
128 if(!trim($state->get('discount_value')))
129 {
131 }
132
133 if(!$state->get('discount_days'))
134 {
135 $this->errorCollection[] = new Error(Loc::getMessage('SALE_HANDLERS_DISCOUNTPRESET_ERROR_EMPTY_VALUE_DAYS'));
136 }
137
138 $this->validateSectionsAndProductsState($state, $this->errorCollection);
139
140 if(!$this->errorCollection->isEmpty())
141 {
142 return array($state, 'InputAmount');
143 }
144
145 return array($state, 'CommonSettings');
146 }
147
148 public function processShowCommonSettings(State $state)
149 {
150 return $this->processShowCommonSettingsInternal($state);
151 }
152
153 public function processSaveCommonSettings(State $state)
154 {
155 return $this->processSaveCommonSettingsInternal($state);
156 }
157
158 public function generateState(array $discountFields)
159 {
160 $discountFields = $this->normalizeDiscountFields($discountFields);
161
162 $stateFields = [
163 'discount_lid' => $discountFields['LID'],
164 'discount_name' => $discountFields['NAME'],
165 'discount_groups' => $this->getUserGroupsByDiscount($discountFields['ID']),
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')),
171 ];
172
173 return parent::generateState($discountFields)->append($stateFields);
174 }
175
176 public function generateDiscount(State $state)
177 {
178 $generateProductConditions = $this->generateProductConditions($state->get('discount_product'));
179 $generateSectionConditions = $this->generateSectionConditions($state->get('discount_section'));
180
181 return array_merge(
182 parent::generateDiscount($state),
183 [
184 'CONDITIONS' => [
185 'CLASS_ID' => 'CondGroup',
186 'DATA' => [
187 'All' => 'AND',
188 'True' => 'True',
189 ],
190 'CHILDREN' => [
191 [
192 'CLASS_ID' => 'CondSaleCmnDayOfWeek',
193 'DATA' => [
194 'logic' => 'Equal',
195 'value' => $state->get('discount_days'),
196 ],
197 ],
198 [
199 'CLASS_ID' => 'CondGroup',
200 'DATA' => [
201 'All' => 'OR',
202 'True' => 'True',
203 ],
204 'CHILDREN' => [
205 $generateSectionConditions? [
206 'CLASS_ID' => 'CondGroup',
207 'DATA' => [
208 'All' => 'AND',
209 'True' => 'True',
210 ],
211 'CHILDREN' => [
212 [
213 'CLASS_ID' => 'CondBsktProductGroup',
214 'DATA' => [
215 'Found' => 'Found',
216 'All' => 'OR',
217 ],
218 'CHILDREN' => $generateSectionConditions,
219 ],
220 ],
221 ] : [],
222 $generateProductConditions? [
223 'CLASS_ID' => 'CondGroup',
224 'DATA' => [
225 'All' => 'AND',
226 'True' => 'True',
227 ],
228 'CHILDREN' => [
229 [
230 'CLASS_ID' => 'CondBsktProductGroup',
231 'DATA' => [
232 'Found' => 'Found',
233 'All' => 'OR',
234 ],
235 'CHILDREN' => $generateProductConditions,
236 ],
237 ],
238 ] : [],
239 ],
240 ],
241 ],
242 ],
243 'ACTIONS' => [
244 'CLASS_ID' => 'CondGroup',
245 'DATA' => [
246 'All' => 'AND',
247 ],
248 'CHILDREN' => [
249 [
250 'CLASS_ID' => 'ActSaleBsktGrp',
251 'DATA' => [
252 'Type' => 'Discount',
253 'Value' => $state->get('discount_value'),
254 'Unit' => $state->get('discount_type', 'CurAll'),
255 'Max' => 0,
256 'All' => 'OR',
257 'True' => 'True',
258 ],
259 'CHILDREN' => [
260 $this->generateSectionActions($state->get('discount_section')),
261 $this->generateProductActions($state->get('discount_product')),
262 ],
263 ],
264 ],
265 ],
266 ]
267 );
268 }
269}
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
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
</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