Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
selectproductpreset.php
1<?php
2
4
5
12
13Loc::loadMessages(__FILE__);
14
15abstract class SelectProductPreset extends BasePreset
16{
17 protected function init()
18 {
19 parent::init();
20
21 if(!Loader::includeModule('iblock'))
22 {
23 throw new SystemException('Could not include iblock module');
24 }
25
26 \CJSCore::RegisterExt('select_product_preset', array(
27 'js' => '/bitrix/js/sale/admin/discountpreset/select_product_preset.js',
28 'lang' => '/bitrix/modules/sale/lang/' . LANGUAGE_ID . '/admin/js/discountpreset/select_product_preset.php',
29 'rel' => array('core'),
30 ));
31
32 \CUtil::InitJSCore(array('select_product_preset'));
33 }
34
35 protected function renderElementBlock(State $state, $inputName = 'discount_product', $multi = true)
36 {
37 if($multi)
38 {
39 $inputName .= '[]';
40 }
41
42 return '
43 <div class="sale-discount-container-box">
44 <div class="sale-discount-title-container">
45 <div class="sale-discount-title-text">' . Loc::getMessage('SALE_BASE_PRESET_SUB_TITLE_PRODUCTS') . '</div>
46 <div class="clb"></div>
47 </div>
48 <div class="adm-sl-content-container">
49 <div class="sale-discount-btn-container">
50 <a href="#" class="adm-btn adm-btn-save adm-btn-add" title="" id="sale_discount_preset_product_add">' . Loc::getMessage('SALE_BASE_PRESET_ADD_ELEMENTS') . '</a>
51 </div>
52 </div>
53 <div class="sale-discount-content-container">
54 <input type="hidden" name="' . $inputName . '" value="">
55 <div class="adm-s-order-table-ddi" style="margin-top:20px">
56 <table class="adm-s-order-table-ddi-table" style="width: 100%;" id="sale_discount_preset_product_table">
57 <thead style="text-align: left;">
58 <tr>
59 <td></td>
60 <td>' . Loc::getMessage('SALE_BASE_PRESET_HEAD_IMAGE') . '</td>
61 <td>' . Loc::getMessage('SALE_BASE_PRESET_HEAD_NAME') . '</td>
62 <td>' . Loc::getMessage('SALE_BASE_PRESET_HEAD_PROPS') . '</td>
63 </tr>
64 </thead>
65 <tbody style="border: 1px solid rgb(221, 221, 221);" id="sale_discount_preset_product_table_empty_row">
66 <tr>
67 <td colspan="4" style="padding: 20px;">
68 ' . Loc::getMessage('SALE_BASE_PRESET_EMPTY_PRODUCT_NOTICE') . '
69 </td>
70 </tr>
71 </tbody>
72 </table>
73 </div>
74 </div>
75 </div>
76 ';
77 }
78
79 protected function renderSectionBlock(State $state, $inputName = 'discount_section', $multi = true)
80 {
81 $fromInputName = $inputName;
82 if($multi)
83 {
84 $fromInputName .= '[]';
85 }
86
87 return '
88 <div class="sale-discount-container-box">
89 <div class="sale-discount-title-container">
90 <div class="sale-discount-title-text">' . Loc::getMessage('SALE_BASE_PRESET_SUB_TITLE_SECTION') . '</div>
91 <div class="clb"></div>
92 </div>
93 <div class="adm-sl-content-container">
94 <div class="sale-discount-btn-container">
95 <a href="#" class="adm-btn adm-btn-save adm-btn-add" title="" id="sale_discount_preset_section_add">' . Loc::getMessage('SALE_BASE_PRESET_ADD_ELEMENTS') . '</a>
96 </div>
97 </div>
98 <div class="sale-discount-content-container" style="margin-top:20px;">
99 <table class="sale-discount-detail-content-sale-table bdrb" style="margin: 0 auto;" border="0" cellspacing="7" cellpadding="0">
100 <tbody id="sale_discount_preset_section_tbody">
101 <input type="hidden" name="' . $fromInputName . '" value="">
102 ' . $this->renderSections($state, $inputName) . '
103 </tbody>
104 </table>
105 </div>
106 </div>
107 ';
108 }
109
110 protected function renderSections(State $state, $inputName, $multi = true)
111 {
112 global $APPLICATION;
113
114 $currentValue = array();
115
116 $sectionIds = $state->get($inputName);
117 if($sectionIds)
118 {
119 $sectionsIterator = SectionTable::getList(array(
120 'select' => array('ID', 'NAME'),
121 'filter' => array('@ID' => $sectionIds),
122 ));
123
124 while($row = $sectionsIterator->fetch())
125 {
126 $currentValue[] = "{$row['NAME']} [{$row['ID']}]";
127 }
128 }
129
130 ob_start();
131 $APPLICATION->IncludeComponent(
132 'bitrix:main.lookup.input',
133 'iblockedit',
134 array(
135 'CONTROL_ID' => 'select_section',
136 'INPUT_NAME' => $inputName .'[]',
137 'INPUT_NAME_STRING' => 'inp_'. $inputName,
138 'INPUT_VALUE_STRING' => implode("\n", $currentValue),
139 'START_TEXT' => Loc::getMessage('SALE_BASE_PRESET_TRY_TO_TEXT'),
140 'MULTIPLE' => $multi? 'Y' : 'N',
141 'MAX_WIDTH' => '200',
142 'MIN_HEIGHT' => '100',
143 'WITHOUT_IBLOCK' => 'Y',
144 'FILTER' => 'Y',
145 'TYPE' => 'SECTION',
146 ), null, array('HIDE_ICONS' => 'Y')
147 );
148 $htmlResult = ob_get_contents();
149 ob_end_clean();
150
151 return $htmlResult;
152 }
153
154 protected function getSectionsFromConditions(array $conditions = null)
155 {
156 if(!$conditions)
157 {
158 return array();
159 }
160
161 $sectionIds = array();
162 foreach($conditions as $condition)
163 {
164 if($condition['CLASS_ID'] !== 'CondIBSection')
165 {
166 continue;
167 }
168 $sectionIds[] = $condition['DATA']['value'];
169 }
170
171 return array_unique($sectionIds);
172 }
173
174 protected function getProductsFromConditions(array $conditions = null)
175 {
176 if(!$conditions)
177 {
178 return array();
179 }
180
181 $productIds = array();
182 foreach($conditions as $condition)
183 {
184 if($condition['CLASS_ID'] !== 'CondIBElement')
185 {
186 continue;
187 }
188
189 $value = $condition['DATA']['value'];
190 if(!is_array($value))
191 {
192 $value = array($value);
193 }
194
195 $productIds = array_merge($productIds, $value);
196 }
197
198 return array_unique($productIds);
199 }
200
201 protected function generateSectionConditions($sectionIds, $logic = 'Equal')
202 {
203 $sectionIds = $this->cleanIds($sectionIds);
204 if(empty($sectionIds))
205 {
206 return array();
207 }
208
209 $data = array();
210 foreach($sectionIds as $sectionId)
211 {
212 if(empty($sectionId))
213 {
214 continue;
215 }
216
217 $data[] = array(
218 'CLASS_ID' => 'CondIBSection',
219 'DATA' => array(
220 'logic' => $logic,
221 'value' => (int)$sectionId,
222 ),
223 );
224 }
225 unset($sectionId);
226
227 return $data;
228 }
229
230 protected function generateProductConditions($productIds, $logic = 'Equal')
231 {
232 $productIds = $this->cleanIds($productIds);
233 if(empty($productIds))
234 {
235 return array();
236 }
237
238 return array(
239 array(
240 'CLASS_ID' => 'CondIBElement',
241 'DATA' => array(
242 'logic' => $logic,
243 'value' => array_filter(array_map('intval', $productIds)),
244 )
245 )
246 );
247 }
248
249 protected function generateSectionActions($sectionIds)
250 {
251 $sectionIds = $this->cleanIds($sectionIds);
252 if(empty($sectionIds))
253 {
254 return array();
255 }
256
257 return array(
258 'CLASS_ID' => 'ActSaleSubGrp',
259 'DATA' => array(
260 'All' => 'OR',
261 'True' => 'True',
262 ),
263 'CHILDREN' => $this->generateSectionConditions($sectionIds),
264 );
265 }
266
267 protected function generateProductActions($productIds)
268 {
269 $productIds = $this->cleanIds($productIds);
270 if(empty($productIds))
271 {
272 return array();
273 }
274
275 return array(
276 'CLASS_ID' => 'ActSaleSubGrp',
277 'DATA' => array(
278 'All' => 'AND',
279 'True' => 'True',
280 ),
281 'CHILDREN' => array(
282 array(
283 'CLASS_ID' => 'CondIBElement',
284 'DATA' => array(
285 'logic' => 'Equal',
286 'value' => array_map('intval', $productIds),
287 )
288 ),
289 ),
290 );
291 }
292
293 protected function generateProductsData($productIds, $siteId)
294 {
295 $productData = array();
296
297 $productIds = $this->cleanIds($productIds);
298 if(empty($productIds))
299 {
300 return array();
301 }
302
303 foreach($productIds as $productId)
304 {
305 $productData[] = $this->processAjaxActionGetProductDetails(array(
306 'productId' => $productId,
307 'quantity' => 1,
308 'siteId' => $siteId,
309 ));
310 }
311
312 return $productData;
313 }
314
316 {
317 if(!is_array($state->get('discount_section', array())))
318 {
319 $errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_ERROR_SECTION_NON_ARRAY'));
320 }
321
322 if(!is_array($state->get('discount_product', array())))
323 {
324 $errorCollection[] = new Error(Loc::getMessage('SALE_BASE_PRESET_ERROR_PRODUCT_NON_ARRAY'));
325 }
326 }
327
328 private function cleanIds($ids)
329 {
330 if(empty($ids))
331 {
332 return array();
333 }
334
335 if (!is_array($ids))
336 {
337 return array();
338 }
339
340 return array_filter($ids);
341 }
342}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
processAjaxActionGetProductDetails(array $params=array())
renderSections(State $state, $inputName, $multi=true)
validateSectionsAndProductsState(State $state, ErrorCollection $errorCollection)
renderSectionBlock(State $state, $inputName='discount_section', $multi=true)
renderElementBlock(State $state, $inputName='discount_product', $multi=true)