Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
settings.php
1<?php
3
4use \Bitrix\Landing\Manager;
5use \Bitrix\Landing\Hook;
6use \Bitrix\Landing\Field;
7use \Bitrix\Main\Localization\Loc;
8use \Bitrix\Main\ModuleManager;
9use \Bitrix\Main\Loader;
10use \Bitrix\Currency\CurrencyManager;
11
12Loc::loadMessages(__FILE__);
13
15{
19 const SOURCE_BLOCK = 'store.catalog.list';
20
24 const SOURCE_COMPONENT = 'bitrix:catalog.section';
25
30 protected static $defValues = array(
31 'SECTION_ID' => '',
32 'HIDE_NOT_AVAILABLE' => 'L',
33 'HIDE_NOT_AVAILABLE_OFFERS' => 'N',
34 'PRODUCT_SUBSCRIPTION' => 'Y',
35 'USE_PRODUCT_QUANTITY' => 'Y',
36 'DISPLAY_COMPARE' => 'Y',
37 'PRICE_CODE' => [
38 'BASE'
39 ],
40 'CURRENCY_ID' => '',
41 'PRICE_VAT_INCLUDE' => 'Y',
42 'SHOW_OLD_PRICE' => 'Y',
43 'SHOW_DISCOUNT_PERCENT' => 'Y',
44 'USE_PRICE_COUNT' => 'N',
45 'SHOW_PRICE_COUNT' => 1,
46 'USE_ENHANCED_ECOMMERCE' => 'Y',
47 'DATA_LAYER_NAME' => 'dataLayer',
48 'BRAND_PROPERTY' => 'BRAND_REF',
49 'CART_POSITION' => 'BL',
50 'AGREEMENT_ID' => 0,
51 );
52
57 protected static function getDefaultValues(): array
58 {
59 static $defValues = [];
60
61 if (!$defValues)
62 {
64 if (
65 !$defValues['CURRENCY_ID']
66 && Loader::includeModule('currency')
67 )
68 {
69 $defValues['CURRENCY_ID'] = CurrencyManager::getBaseCurrency();
70 }
71 }
72
73 return $defValues;
74 }
75
80 protected static function getCodesValues()
81 {
82 static $codes = array();
83
84 if (!empty($codes))
85 {
86 return $codes;
87 }
88
89 if (ModuleManager::isModuleInstalled('catalog'))
90 {
91 $codes = array(
92 '' => array(
93 'IBLOCK_ID', 'SECTION_ID'
94 ),
95 'VIEW' => array(
96 'HIDE_NOT_AVAILABLE', 'HIDE_NOT_AVAILABLE_OFFERS', 'PRODUCT_SUBSCRIPTION',
97 'USE_PRODUCT_QUANTITY', 'DISPLAY_COMPARE', 'CART_POSITION'
98 ),
99 'PRICE' => array(
100 'PRICE_CODE', 'USE_PRICE_COUNT', 'SHOW_PRICE_COUNT', 'CURRENCY_ID',
101 'PRICE_VAT_INCLUDE', 'SHOW_OLD_PRICE', 'SHOW_DISCOUNT_PERCENT'
102 ),
103 'ANAL' => array(
104 'USE_ENHANCED_ECOMMERCE', 'DATA_LAYER_NAME', 'BRAND_PROPERTY'
105 )
106 );
107 }
108 else
109 {
110 $codes = array(
111 '' => array(
112 'IBLOCK_ID', 'SECTION_ID'
113 )
114 );
115 }
116
117 return $codes;
118 }
119
127 protected static function getFieldByType($type, $code, $params = array())
128 {
129 $field = null;
130
131 switch ($type)
132 {
133 case 'LIST':
134 {
135 $field = new Field\Select($code, array(
136 'title' => isset($params['NAME'])
137 ? $params['NAME']
138 : '',
139 'options' => isset($params['VALUES'])
140 ? (array) $params['VALUES']
141 : array(),
142 'multiple' => isset($params['MULTIPLE'])
143 && $params['MULTIPLE'] == 'Y'
144 ));
145 break;
146 }
147 case 'CHECKBOX':
148 {
149 $field = new Field\Checkbox($code, array(
150 'title' => isset($params['NAME'])
151 ? $params['NAME']
152 : ''
153 ));
154 break;
155 }
156 default:
157 {
158 $field = new Field\Text($code, array(
159 'title' => isset($params['NAME'])
160 ? $params['NAME']
161 : ''
162 ));
163 break;
164 }
165 }
166
167 if ($field && isset(self::getDefaultValues()[$code]))
168 {
169 $field->setValue(self::getDefaultValues()[$code]);
170 }
171
172 return $field;
173 }
174
179 protected static function getComponentsParams()
180 {
181 static $params = array();
182
183 if (empty($params))
184 {
185 // get real manifest
186 $block = new \Bitrix\Landing\Block(0, array(
187 'CODE' => self::SOURCE_BLOCK
188 ));
189 $manifest = $block->getManifest(
190 true,
191 true,
192 array(
193 'miss_subtype' => true
194 )
195 );
196 $codes = self::getCodesValues();
197 foreach (array_keys($codes) as $k)
198 {
199 foreach ($codes[$k] as $code)
200 {
201 if (isset($manifest['nodes'][self::SOURCE_COMPONENT]['extra'][$code]))
202 {
203 $params[$code] = $manifest['nodes'][self::SOURCE_COMPONENT]['extra'][$code];
204 }
205 }
206 }
207 }
208
209 return $params;
210 }
211
217 public static function getCodes($linear = false)
218 {
219 $codes = array();
220
221 if ($linear)
222 {
223 foreach (self::getCodesValues() as $item)
224 {
225 $codes = array_merge($codes, $item);
226 }
227 }
228 else
229 {
230 $codes = self::getCodesValues();
231 }
232
233 return $codes;
234 }
235
240 protected function getMap()
241 {
242 $fields = array();
243
244 // set iblock_id to the map
246 {
247 $catalogs = array(
248 '' => ''
249 );
250 $allowedCatalogs = array();
251 $catalogIncluded = Loader::includeModule('catalog');
252
253 if ($catalogIncluded)
254 {
255 $iterator = \Bitrix\Catalog\CatalogIblockTable::getList(array(
256 'select' => array(
257 'IBLOCK_ID', 'PRODUCT_IBLOCK_ID'
258 )
259 ));
260 while ($row = $iterator->fetch())
261 {
262 $row['IBLOCK_ID'] = (int)$row['IBLOCK_ID'];
263 $row['PRODUCT_IBLOCK_ID'] = (int)$row['PRODUCT_IBLOCK_ID'];
264 if ($row['PRODUCT_IBLOCK_ID'] > 0)
265 {
266 $allowedCatalogs[$row['PRODUCT_IBLOCK_ID']] = true;
267 }
268 else
269 {
270 $allowedCatalogs[$row['IBLOCK_ID']] = true;
271 }
272 }
273 unset($row, $iterator);
274 }
275 if (Loader::includeModule('iblock'))
276 {
277 $res = \CIblock::getList(
278 [],
279 [
280 'SITE_ID' => Manager::getMainSiteId()
281 ]
282 );
283 }
284 if (isset($res))
285 {
286 while ($row = $res->fetch())
287 {
288 $row['ID'] = (int)$row['ID'];
289 if ($catalogIncluded && !isset($allowedCatalogs[$row['ID']]))
290 {
291 continue;
292 }
293 $catalogs[$row['ID']] = '[' . $row['ID'] . '] ' . $row['NAME'];
294 }
295 }
296 $fields['IBLOCK_ID'] = self::getFieldByType(
297 'LIST',
298 'IBLOCK_ID',
299 array(
300 'NAME' => Loc::getMessage('LANDING_HOOK_SETTINGS_IBLOCK_ID'),
301 'VALUES' => $catalogs
302 )
303 );
304 unset($allowedCatalogs);
305 }
306
307 foreach (self::getComponentsParams() as $code => $params)
308 {
309 if (!isset($fields[$code]))
310 {
312 $params['TYPE'],
313 $code,
314 $params
315 );
316 }
317 }
318
319 $fields['AGREEMENT_USE'] = self::getFieldByType(
320 'CHECKBOX', 'AGREEMENT_USE'
321 );
322 $fields['AGREEMENT_ID'] = self::getFieldByType(
323 null, 'AGREEMENT_ID'
324 );
325
326 // cart position
327 $positions = array_fill_keys(
328 ['TC', 'TR', 'CR', 'BR', 'BC', 'BL', 'CL', 'TL'],
329 ''
330 );
331 foreach ($positions as $key => $val)
332 {
333 $positions[$key] = Loc::getMessage('LANDING_HOOK_SETTINGS_CART_POSITION_' . $key);
334 }
335 $fields['CART_POSITION'] = self::getFieldByType(
336 'LIST',
337 'CART_POSITION',
338 array(
339 'NAME' => Loc::getMessage('LANDING_HOOK_SETTINGS_CART_POSITION'),
340 'VALUES' => $positions
341 )
342 );
343 unset($positions, $key, $val);
344
345 return $fields;
346 }
347
352 public function enabled()
353 {
354 return false;
355 }
356
361 public function exec()
362 {
363 // do nothing
364 }
365
371 public static function getDataForSite($id = null)
372 {
373 static $settings = array();
374
375 if (isset($settings[$id]))
376 {
377 return $settings[$id];
378 }
379
380 $settings[$id] = array();
381
382 if ($id)
383 {
384 $hooks = Hook::getData(
385 $id,
387 );
388 }
389
390 foreach (self::getDefaultValues() as $key => $defValue)
391 {
392 if (isset($hooks['SETTINGS'][$key]))
393 {
394 $settings[$id][$key] = $hooks['SETTINGS'][$key];
395 }
396 else
397 {
398 $settings[$id][$key] = $defValue;
399 }
400 }
401
402 // additional
403 if (!Manager::isB24())
404 {
405 $settings[$id]['IBLOCK_ID'] = $hooks['SETTINGS']['IBLOCK_ID'] ?? 0;
406 }
407 else
408 {
409 $settings[$id]['IBLOCK_ID'] = 0;
410 if (
411 Loader::includeModule('crm')
412 && Loader::includeModule('catalog')
413 )
414 {
415 $settings[$id]['IBLOCK_ID'] = (int)\Bitrix\Crm\Product\Catalog::getDefaultId();
416 }
417 }
418
419 // agreement
420 if(isset($hooks['SETTINGS']['AGREEMENT_USE']))
421 {
422 $settings[$id]['AGREEMENT_USE'] = $hooks['SETTINGS']['AGREEMENT_USE'];
423 if($hooks['SETTINGS']['AGREEMENT_USE'] === 'N')
424 {
425 $settings[$id]['AGREEMENT_ID'] = 0;
426 }
427 }
428 else
429 {
430 $settings[$id]['AGREEMENT_USE'] = $settings[$id]['AGREEMENT_ID'] ? 'Y' : 'N';
431 }
432
433 if (isset($hooks['SETTINGS']['CART_POSITION']))
434 {
435 $settings[$id]['CART_POSITION'] = $hooks['SETTINGS']['CART_POSITION'];
436 }
437
438 return $settings[$id];
439 }
440}
static getCodes($linear=false)
Definition settings.php:217
static getFieldByType($type, $code, $params=array())
Definition settings.php:127
static getData($id, $type, $asIs=false)
Definition hook.php:104
const ENTITY_TYPE_SITE
Definition hook.php:20
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29