1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
element.php
См. документацию.
1<?php
2
3namespace Bitrix\Iblock\Component;
4
5use Bitrix\Iblock;
6use Bitrix\Catalog;
7use Bitrix\Main;
8use Bitrix\Main\Loader;
9use Bitrix\Main\Error;
10use Bitrix\Main\Type\Collection;
11use Bitrix\Main\Type\DateTime;
12use Bitrix\Main\Localization\Loc;
13use Bitrix\Sale\Internals\FacebookConversion;
14
19
20abstract class Element extends Base
21{
23 {
24 if (!is_array($params))
25 {
26 $params = [];
27 }
28 $params['ADD_SECTIONS_CHAIN'] = (isset($params['ADD_SECTIONS_CHAIN']) && $params['ADD_SECTIONS_CHAIN'] === 'N' ? 'N' : 'Y');
29 $params['PRODUCT_DISPLAY_MODE'] = 'Y';
30 $params = parent::onPrepareComponentParams($params);
31 $params['IBLOCK_TYPE'] = trim((string)($params['IBLOCK_TYPE'] ?? ''));
32
33 if (isset($params['ELEMENT_ID']))
34 {
35 if ((int)$params['ELEMENT_ID'] > 0 && (int)$params['ELEMENT_ID'] != $params['ELEMENT_ID'] && Loader::includeModule('iblock'))
36 {
37 $this->errorCollection->setError(new Error(Loc::getMessage('CATALOG_ELEMENT_NOT_FOUND'), self::ERROR_404));
38
39 return $params;
40 }
41 }
42
43 $params['ELEMENT_ID'] = (int)($params['ELEMENT_ID'] ?? 0);
44 $params['ELEMENT_CODE'] = trim((string)($params['ELEMENT_CODE'] ?? ''));
45
46 $params['CHECK_SECTION_ID_VARIABLE'] = isset($params['CHECK_SECTION_ID_VARIABLE']) && $params['CHECK_SECTION_ID_VARIABLE'] === 'Y' ? 'Y' : 'N';
47 $params['SECTION_ID_VARIABLE'] = trim((string)($params['SECTION_ID_VARIABLE'] ?? ''));
48 if (
49 $params['SECTION_ID_VARIABLE'] === ''
50 || !preg_match(self::PARAM_TITLE_MASK, $params['SECTION_ID_VARIABLE'])
51 )
52 {
53 $params['SECTION_ID_VARIABLE'] = 'SECTION_ID';
54 }
55
56 $params['FROM_SECTION'] = '';
57 if ($params['CHECK_SECTION_ID_VARIABLE'] === 'Y')
58 {
59 $params['FROM_SECTION'] = trim($this->request->get($params['SECTION_ID_VARIABLE']));
60 }
61
62 $params['SECTIONS_CHAIN_START_FROM'] = (int)($params['SECTIONS_CHAIN_START_FROM'] ?? 0);
63 $params['META_KEYWORDS'] = trim((string)($params['META_KEYWORDS'] ?? ''));
64 $params['META_DESCRIPTION'] = trim((string)($params['META_DESCRIPTION'] ?? ''));
65 $params['BROWSER_TITLE'] = trim((string)($params['BROWSER_TITLE'] ?? ''));
66
67 $params['BACKGROUND_IMAGE'] = trim((string)($params['BACKGROUND_IMAGE'] ?? ''));
68 if ($params['BACKGROUND_IMAGE'] === '-')
69 {
70 $params['BACKGROUND_IMAGE'] = '';
71 }
72
73 $params['USE_MAIN_ELEMENT_SECTION'] = isset($params['USE_MAIN_ELEMENT_SECTION']) && $params['USE_MAIN_ELEMENT_SECTION'] === 'Y';
74 $params['ADD_ELEMENT_CHAIN'] = isset($params['ADD_ELEMENT_CHAIN']) && $params['ADD_ELEMENT_CHAIN'] === 'Y';
75 $params['LINK_IBLOCK_TYPE'] = trim((string)($params['LINK_IBLOCK_TYPE'] ?? ''));
76 $params['LINK_IBLOCK_ID'] = (int)($params['LINK_IBLOCK_ID'] ?? 0);
77 $params['LINK_PROPERTY_SID'] = trim((string)($params['LINK_PROPERTY_SID'] ?? ''));
78 $params['LINK_ELEMENTS_URL'] = trim((string)($params['LINK_ELEMENTS_URL'] ?? ''));
79 if ($params['LINK_ELEMENTS_URL'] === '')
80 {
81 $params['LINK_ELEMENTS_URL'] = 'link.php?PARENT_ELEMENT_ID=#ELEMENT_ID#';
82 }
83
84 $params['SHOW_WORKFLOW'] = $this->request->get('show_workflow') === 'Y';
85 if ($params['SHOW_WORKFLOW'])
86 {
87 $params['CACHE_TIME'] = 0;
88 }
89
90 $params['PRICE_VAT_SHOW_VALUE'] = isset($params['PRICE_VAT_SHOW_VALUE']) && $params['PRICE_VAT_SHOW_VALUE'] === 'Y';
91
92 // compatibility to old HIDE_NOT_AVAILABLE parameter
93 if (!isset($params['HIDE_NOT_AVAILABLE_OFFERS']) && isset($params['HIDE_NOT_AVAILABLE']))
94 {
95 $params['HIDE_NOT_AVAILABLE_OFFERS'] = $params['HIDE_NOT_AVAILABLE'];
96 }
97
98 if (
99 !isset($params['HIDE_NOT_AVAILABLE_OFFERS'])
100 || ($params['HIDE_NOT_AVAILABLE_OFFERS'] !== 'Y' && $params['HIDE_NOT_AVAILABLE_OFFERS'] !== 'L')
101 )
102 {
103 $params['HIDE_NOT_AVAILABLE_OFFERS'] = 'N';
104 }
105
106 $params['HIDE_NOT_AVAILABLE'] = 'N';
107 $params['USE_ELEMENT_COUNTER'] = isset($params['USE_ELEMENT_COUNTER']) && $params['USE_ELEMENT_COUNTER'] === 'N' ? 'N' : 'Y';
108 $params['SHOW_DEACTIVATED'] = isset($params['SHOW_DEACTIVATED']) && $params['SHOW_DEACTIVATED'] === 'Y' ? 'Y' : 'N';
109
110 // default gifts
111 if (empty($params['USE_GIFTS_DETAIL']))
112 {
113 $params['USE_GIFTS_DETAIL'] = 'Y';
114 }
115
116 if (empty($params['USE_GIFTS_MAIN_PR_SECTION_LIST']))
117 {
118 $params['USE_GIFTS_MAIN_PR_SECTION_LIST'] = 'Y';
119 }
120
121 if (empty($params['GIFTS_DETAIL_PAGE_ELEMENT_COUNT']))
122 {
123 $params['GIFTS_DETAIL_PAGE_ELEMENT_COUNT'] = 4;
124 }
125
126 if (empty($params['GIFTS_MAIN_PRODUCT_DETAIL_PAGE_ELEMENT_COUNT']))
127 {
128 $params['GIFTS_MAIN_PRODUCT_DETAIL_PAGE_ELEMENT_COUNT'] = 4;
129 }
130
131 $this->storage['IBLOCK_PARAMS'] = $this->getIblockParams($params);
132
133 return $params;
134 }
135
136 protected function getIblockParams(&$params)
137 {
139
140 if (!isset($params['PROPERTY_CODE']) || !is_array($params['PROPERTY_CODE']))
141 {
142 $params['PROPERTY_CODE'] = array();
143 }
144
145 foreach ($params['PROPERTY_CODE'] as $k => $v)
146 {
147 if ($v == '')
148 {
149 unset($params['PROPERTY_CODE'][$k]);
150 }
151 }
152
153 if (!isset($params['OFFERS_FIELD_CODE']))
154 {
155 $params['OFFERS_FIELD_CODE'] = array();
156 }
157 elseif (!is_array($params['OFFERS_FIELD_CODE']))
158 {
159 $params['OFFERS_FIELD_CODE'] = array($params['OFFERS_FIELD_CODE']);
160 }
161
162 foreach ($params['OFFERS_FIELD_CODE'] as $key => $value)
163 {
164 if ($value == '')
165 {
166 unset($params['OFFERS_FIELD_CODE'][$key]);
167 }
168 }
169
170 if (!isset($params['OFFERS_PROPERTY_CODE']))
171 {
172 $params['OFFERS_PROPERTY_CODE'] = array();
173 }
174 elseif (!is_array($params['OFFERS_PROPERTY_CODE']))
175 {
176 $params['OFFERS_PROPERTY_CODE'] = array($params['OFFERS_PROPERTY_CODE']);
177 }
178
179 foreach ($params['OFFERS_PROPERTY_CODE'] as $key => $value)
180 {
181 if ($value == '')
182 {
183 unset($params['OFFERS_PROPERTY_CODE'][$key]);
184 }
185 }
186
187 if (!in_array('PREVIEW_PICTURE', $params['OFFERS_PROPERTY_CODE']))
188 {
189 $params['OFFERS_PROPERTY_CODE'][] = 'PREVIEW_PICTURE';
190 }
191
192 if (!in_array('DETAIL_PICTURE', $params['OFFERS_PROPERTY_CODE']))
193 {
194 $params['OFFERS_PROPERTY_CODE'][] = 'DETAIL_PICTURE';
195 }
196
197 $cartProperties = [];
198 $offersCartProperties = [];
199 $offerTreeProperties = [];
200 if (!$usePropertyFeatures)
201 {
202 if (!isset($params['PRODUCT_PROPERTIES']) || !is_array($params['PRODUCT_PROPERTIES']))
203 {
204 $params['PRODUCT_PROPERTIES'] = array();
205 }
206
207 foreach ($params['PRODUCT_PROPERTIES'] as $k => $v)
208 {
209 if ($v == '')
210 {
211 unset($params['PRODUCT_PROPERTIES'][$k]);
212 }
213 }
214 $cartProperties = $params['PRODUCT_PROPERTIES'];
215
216 if (!isset($params['OFFERS_CART_PROPERTIES']) || !is_array($params['OFFERS_CART_PROPERTIES']))
217 {
218 $params['OFFERS_CART_PROPERTIES'] = array();
219 }
220
221 foreach ($params['OFFERS_CART_PROPERTIES'] as $i => $pid)
222 {
223 if ($pid == '')
224 {
225 unset($params['OFFERS_CART_PROPERTIES'][$i]);
226 }
227 }
228 $offersCartProperties = $params['OFFERS_CART_PROPERTIES'];
229
230 if (!isset($params['OFFER_TREE_PROPS']))
231 {
232 $params['OFFER_TREE_PROPS'] = array();
233 }
234 elseif (!is_array($params['OFFER_TREE_PROPS']))
235 {
236 $params['OFFER_TREE_PROPS'] = array($params['OFFER_TREE_PROPS']);
237 }
238
239 foreach ($params['OFFER_TREE_PROPS'] as $key => $value)
240 {
241 $value = (string)$value;
242 if ($value == '' || $value === '-')
243 {
244 unset($params['OFFER_TREE_PROPS'][$key]);
245 }
246 }
247
248 if (empty($params['OFFER_TREE_PROPS']) && !empty($params['OFFERS_CART_PROPERTIES']))
249 {
250 $params['OFFER_TREE_PROPS'] = $params['OFFERS_CART_PROPERTIES'];
251 foreach ($params['OFFER_TREE_PROPS'] as $key => $value)
252 {
253 if ($value === '-')
254 {
255 unset($params['OFFER_TREE_PROPS'][$key]);
256 }
257 }
258 }
259 $offerTreeProperties = $params['OFFER_TREE_PROPS'];
260 }
261
262 return array(
263 $params['IBLOCK_ID'] => array(
264 'PROPERTY_CODE' => $params['PROPERTY_CODE'],
265 'CART_PROPERTIES' => $cartProperties,
266 'OFFERS_FIELD_CODE' => $params['OFFERS_FIELD_CODE'],
267 'OFFERS_PROPERTY_CODE' => $params['OFFERS_PROPERTY_CODE'],
268 'OFFERS_CART_PROPERTIES' => $offersCartProperties,
269 'OFFERS_TREE_PROPS' => $offerTreeProperties
270 )
271 );
272 }
273
274 protected function checkModules()
275 {
276 if ($success = parent::checkModules())
277 {
278 $this->storage['MODULES']['workflow'] = false;
279 }
280
281 return $success;
282 }
283
284 protected function initialLoadAction()
285 {
286 parent::initialLoadAction();
287
288 if (!$this->hasErrors() && isset($this->arResult['ID']))
289 {
290 $this->initAdminIconsPanel();
291 $this->sendCounters();
292 $this->saveViewedProduct();
293 $this->initMetaData();
294 }
295 }
296
297 protected function processResultData()
298 {
299 if ($this->checkElementId())
300 {
301 parent::processResultData();
302 $this->arResult['IS_FACEBOOK_CONVERSION_CUSTOMIZE_PRODUCT_EVENT_ENABLED'] = false;
303 if (Loader::includeModule('sale'))
304 {
305 $this->arResult['IS_FACEBOOK_CONVERSION_CUSTOMIZE_PRODUCT_EVENT_ENABLED'] = FacebookConversion::isEventEnabled(
306 'CustomizeProduct'
307 );
308 }
309
310 }
311 else
312 {
313 $this->abortResultCache();
314 $this->errorCollection->setError(new Error(Loc::getMessage('CATALOG_ELEMENT_NOT_FOUND'), self::ERROR_404));
315 }
316 }
317
323 protected function checkElementId()
324 {
325 if ($this->arParams['ELEMENT_ID'] <= 0)
326 {
327 $findFilter = array(
328 'IBLOCK_ID' => $this->arParams['IBLOCK_ID'],
329 'IBLOCK_LID' => $this->getSiteId(),
330 'ACTIVE_DATE' => 'Y',
331 'CHECK_PERMISSIONS' => 'Y',
332 'MIN_PERMISSION' => 'R',
333 );
334
335 if ($this->arParams['SHOW_DEACTIVATED'] !== 'Y')
336 {
337 $findFilter['ACTIVE'] = 'Y';
338 }
339
340 $this->arParams['ELEMENT_ID'] = \CIBlockFindTools::GetElementID(
341 $this->arParams['ELEMENT_ID'],
342 $this->arParams['~ELEMENT_CODE'],
343 $this->arParams['STRICT_SECTION_CHECK']? $this->arParams['SECTION_ID']: 0,
344 $this->arParams['STRICT_SECTION_CHECK']? $this->arParams['~SECTION_CODE']: '',
345 $findFilter
346 );
347 }
348
349 return $this->arParams['ELEMENT_ID'] > 0;
350 }
351
352 protected function initCatalogInfo()
353 {
354 parent::initCatalogInfo();
355 $useCatalogButtons = array();
356
357 if (
358 !empty($this->storage['CATALOGS'][$this->arParams['IBLOCK_ID']])
359 && is_array($this->storage['CATALOGS'][$this->arParams['IBLOCK_ID']])
360 )
361 {
362 $catalogType = $this->storage['CATALOGS'][$this->arParams['IBLOCK_ID']]['CATALOG_TYPE'];
363 if ($catalogType == \CCatalogSku::TYPE_CATALOG || $catalogType == \CCatalogSku::TYPE_FULL)
364 {
365 $useCatalogButtons['add_product'] = true;
366 }
367
368 if ($catalogType == \CCatalogSku::TYPE_PRODUCT || $catalogType == \CCatalogSku::TYPE_FULL)
369 {
370 $useCatalogButtons['add_sku'] = true;
371 }
372 unset($catalogType);
373 }
374
375 $this->arResult['USE_CATALOG_BUTTONS'] = $useCatalogButtons;
376 }
377
381 protected function initIblockPropertyFeatures()
382 {
383 if (!Iblock\Model\PropertyFeature::isEnabledFeatures())
384 return;
385
386 $this->loadDisplayPropertyCodes($this->arParams['IBLOCK_ID']);
387 $this->loadBasketPropertyCodes($this->arParams['IBLOCK_ID']);
388 $this->loadOfferTreePropertyCodes($this->arParams['IBLOCK_ID']);
389 }
390
391 protected function checkProductIblock(array $product): bool
392 {
393 return ($product['PRODUCT_IBLOCK_ID'] == $this->arParams['IBLOCK_ID']);
394 }
395
401 {
403 $iblockId,
404 ['CODE' => 'Y']
405 );
406 if ($list === null)
407 $list = [];
408 $this->storage['IBLOCK_PARAMS'][$iblockId]['PROPERTY_CODE'] = $list;
409 if ($this->useCatalog)
410 {
412 $this->getOffersIblockId($iblockId),
413 ['CODE' => 'Y']
414 );
415 if ($list === null)
416 $list = [];
417 $this->storage['IBLOCK_PARAMS'][$iblockId]['OFFERS_PROPERTY_CODE'] = $list;
418 }
419 unset($list);
420 }
421
422 protected function getSelect()
423 {
424 $selectFields = parent::getSelect();
425 $selectFields[] = 'LIST_PAGE_URL';
426 $selectFields[] = 'PROPERTY_*';
427
428 if ($this->arParams['SET_CANONICAL_URL'] === 'Y')
429 {
430 $selectFields[] = 'CANONICAL_PAGE_URL';
431 }
432
433 return $selectFields;
434 }
435
436 protected function getFilter()
437 {
438 $filterFields = parent::getFilter();
439 $filterFields['SHOW_HISTORY'] = $this->showWorkflowHistory();
440
441 if ($this->arParams['SHOW_DEACTIVATED'] !== 'Y')
442 {
443 $filterFields['ACTIVE'] = 'Y';
444 }
445
446 return $filterFields;
447 }
448
449 protected function showWorkflowHistory()
450 {
451 $wfShowHistory = 'N';
452
453 if ($this->arParams['SHOW_WORKFLOW'] && Loader::includeModule('workflow'))
454 {
455 $this->storage['modules']['workflow'] = true;
456
457 $wfElementId = \CIBlockElement::WF_GetLast($this->arParams['ELEMENT_ID']);
458 $wfStatusId = \CIBlockElement::WF_GetCurrentStatus($wfElementId, $wfStatusTitle);
459 $wfStatusPermission = \CIBlockElement::WF_GetStatusPermission($wfStatusId);
460
461 if ($wfStatusId == 1 || $wfStatusPermission < 1)
462 {
463 $wfElementId = $this->arParams['ELEMENT_ID'];
464 }
465 else
466 {
467 $wfShowHistory = 'Y';
468 }
469
470 $this->arParams['ELEMENT_ID'] = $wfElementId;
471 }
472
473 return $wfShowHistory;
474 }
475
476 protected function getElementList($iblockId, $products)
477 {
478 $section = $this->getSection();
479
480 if ($this->arParams['STRICT_SECTION_CHECK'])
481 {
482 $sectionId = !empty($section) ? $section['ID'] : 0;
483
484 if ($this->arParams['USE_MAIN_ELEMENT_SECTION'])
485 {
486 $this->filterFields['IBLOCK_SECTION_ID'] = $sectionId;
487 }
488 else
489 {
490 $this->filterFields['SECTION_ID'] = $sectionId;
491 $this->filterFields['INCLUDE_SUBSECTIONS'] = 'N';
492 }
493 }
494
495 $elementIterator = parent::getElementList($iblockId, $products);
496
497 if (!empty($elementIterator) && !$this->arParams['USE_MAIN_ELEMENT_SECTION'])
498 {
499 $elementIterator->SetSectionContext($section);
500 }
501
502 $this->storage['SECTION'] = $section;
503
504 return $elementIterator;
505 }
506
507 protected function getSection()
508 {
509 $section = false;
510 $sectionFilter = array(
511 'IBLOCK_ID' => $this->arParams['IBLOCK_ID'],
512 'ACTIVE' => 'Y',
513 );
514
515 if ($this->arParams['SECTION_ID'] > 0 || $this->arParams['SECTION_CODE'] !== '')
516 {
517 if ($this->arParams['SECTION_ID'] > 0)
518 {
519 $sectionFilter['ID'] = $this->arParams['SECTION_ID'];
520 }
521 else
522 {
523 $sectionFilter['HAS_ELEMENT'] = $this->arParams['ELEMENT_ID'];
524 $sectionFilter['=CODE'] = $this->arParams['SECTION_CODE'];
525 }
526
527 $sectionIterator = \CIBlockSection::GetList(array(), $sectionFilter);
528 $sectionIterator->SetUrlTemplates('', $this->arParams['SECTION_URL']);
529 $section = $sectionIterator->GetNext();
530 }
531 elseif ($this->arParams['CHECK_SECTION_ID_VARIABLE'] === 'Y' && $this->arParams['FROM_SECTION'] !== '')
532 {
533 if ((int)$this->arParams['FROM_SECTION'].'|' == $this->arParams['FROM_SECTION'].'|')
534 {
535 $sectionFilter['ID'] = $this->arParams['FROM_SECTION'];
536 }
537 else
538 {
539 $sectionFilter['HAS_ELEMENT'] = $this->arParams['ELEMENT_ID'];
540 $sectionFilter['=CODE'] = $this->arParams['FROM_SECTION'];
541 }
542
543 $sectionIterator = \CIBlockSection::GetList(array(), $sectionFilter);
544 $sectionIterator->SetUrlTemplates('', $this->arParams['SECTION_URL']);
545 $section = $sectionIterator->GetNext();
546 }
547
548 return $section;
549 }
550
551 protected function getIblockElements($elementIterator)
552 {
553 $iblockElements = array();
554
556 if (!empty($elementIterator) && ($elementObject = $elementIterator->GetNextElement()))
557 {
558 $element = $elementObject->GetFields();
559 $this->processElement($element);
560 $iblockElements[$element['ID']] = $element;
561 }
562 else
563 {
564 $this->abortResultCache();
565 $this->errorCollection->setError(new Error(Loc::getMessage('CATALOG_ELEMENT_NOT_FOUND'), self::ERROR_404));
566 }
567
568 return $iblockElements;
569 }
570
571 protected function modifyDisplayProperties($iblock, &$iblockElements)
572 {
573 if (!empty($iblockElements))
574 {
575 reset($iblockElements);
576 $elementKey = key($iblockElements);
577 $element =& $iblockElements[$elementKey];
578
579 $iblockParams = $this->storage['IBLOCK_PARAMS'][$iblock];
580 $propFilter = array(
581 'ID' => array_keys($iblockElements),
582 'IBLOCK_ID' => $iblock
583 );
584 \CIBlockElement::GetPropertyValuesArray($iblockElements, $iblock, $propFilter);
585
586 if (!empty($iblockParams['PROPERTY_CODE']))
587 {
588 $propertyList = $this->getPropertyList($iblock, $iblockParams['PROPERTY_CODE']);
589 }
590
591 if ($this->useCatalog && $this->useDiscountCache)
592 {
593 if ($this->storage['USE_SALE_DISCOUNTS'])
594 Catalog\Discount\DiscountManager::setProductPropertiesCache($element['ID'], $element["PROPERTIES"]);
595 else
596 \CCatalogDiscount::SetProductPropertiesCache($element['ID'], $element['PROPERTIES']);
597 }
598
599 if (!empty($propertyList))
600 {
601 foreach ($propertyList as $pid)
602 {
603 if (!isset($element['PROPERTIES'][$pid]))
604 continue;
605
606 $prop =& $element['PROPERTIES'][$pid];
607 $isArr = is_array($prop['VALUE']);
608 if (
609 ($isArr && !empty($prop['VALUE']))
610 || (!$isArr && (string)$prop['VALUE'] !== '')
612 )
613 {
614 $element['DISPLAY_PROPERTIES'][$pid] = \CIBlockFormatProperties::GetDisplayValue($element, $prop);
615 }
616 unset($prop);
617 }
618 unset($pid);
619
622 }
623
624 if ($this->arParams['ADD_PROPERTIES_TO_BASKET'] === 'Y' && !empty($iblockParams['CART_PROPERTIES']))
625 {
626 $element['PRODUCT_PROPERTIES'] = \CIBlockPriceTools::GetProductProperties(
627 $iblock,
628 $element['ID'],
629 $iblockParams['CART_PROPERTIES'],
630 $element['PROPERTIES']
631 );
632
633 if (!empty($element['PRODUCT_PROPERTIES']))
634 {
635 $element['PRODUCT_PROPERTIES_FILL'] = \CIBlockPriceTools::getFillProductProperties($element['PRODUCT_PROPERTIES']);
636 }
637 }
638
639 $element['BACKGROUND_IMAGE'] = false;
640
641 if ($this->arParams['BACKGROUND_IMAGE'] != '' && isset($element['PROPERTIES'][$this->arParams['BACKGROUND_IMAGE']]))
642 {
643 if (!empty($element['PROPERTIES'][$this->arParams['BACKGROUND_IMAGE']]['VALUE']))
644 {
645 $element['BACKGROUND_IMAGE'] = \CFile::GetFileArray($element['PROPERTIES'][$this->arParams['BACKGROUND_IMAGE']]['VALUE']);
646 }
647 }
648
649 $element['MORE_PHOTO'] = array();
650
651 if (!empty($element['PROPERTIES']['MORE_PHOTO']['VALUE']) && is_array($element['PROPERTIES']['MORE_PHOTO']['VALUE']))
652 {
653 foreach ($element['PROPERTIES']['MORE_PHOTO']['VALUE'] as $file)
654 {
655 $file = \CFile::GetFileArray($file);
656 if (is_array($file))
657 {
658 $element['MORE_PHOTO'][] = $file;
659 }
660 }
661 }
662
663 $element['LINKED_ELEMENTS'] = array();
664
665 if (
666 $this->arParams['LINK_PROPERTY_SID'] <> ''
667 && $this->arParams['LINK_IBLOCK_TYPE'] <> ''
668 && $this->arParams['LINK_IBLOCK_ID'] > 0
669 )
670 {
671 $linkElementIterator = \CIBlockElement::GetList(
672 array('SORT' => 'ASC'),
673 array(
674 'IBLOCK_ID' => $this->arParams['LINK_IBLOCK_ID'],
675 'IBLOCK_ACTIVE' => 'Y',
676 'ACTIVE_DATE' => 'Y',
677 'ACTIVE' => 'Y',
678 'CHECK_PERMISSIONS' => 'Y',
679 'IBLOCK_TYPE' => $this->arParams['LINK_IBLOCK_TYPE'],
680 'PROPERTY_'.$this->arParams['LINK_PROPERTY_SID'] => $element['ID'],
681 ),
682 false,
683 false,
684 array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL', 'IBLOCK_NAME')
685 );
686 while ($linkElement = $linkElementIterator->GetNext())
687 {
688 $element['LINKED_ELEMENTS'][] = $linkElement;
689 }
690 }
691
692 if (!$this->storage['SECTION'] && $element['IBLOCK_SECTION_ID'] > 0)
693 {
694 $sectionFilter = array(
695 'ID' => $element['IBLOCK_SECTION_ID'],
696 'IBLOCK_ID' => $element['IBLOCK_ID'],
697 'ACTIVE' => 'Y',
698 );
699 $sectionIterator = \CIBlockSection::GetList(array(), $sectionFilter);
700 $sectionIterator->SetUrlTemplates('', $this->arParams['SECTION_URL']);
701 $this->storage['SECTION'] = $sectionIterator->GetNext();
702 unset($sectionIterator);
703 }
704
705 if (!empty($this->storage['SECTION']))
706 {
707 $blackList = array(
708 'SEARCHABLE_CONTENT', '~SEARCHABLE_CONTENT',
709 'TIMESTAMP_X', '~TIMESTAMP_X',
710 'DATE_CREATE', '~DATE_CREATE',
711 );
712 foreach ($blackList as $fieldName)
713 {
714 if (array_key_exists($fieldName, $this->storage['SECTION']))
715 {
716 unset($this->storage['SECTION'][$fieldName]);
717 }
718 }
719 unset($fieldName, $blackList);
720
721 $this->storage['SECTION']['PATH'] = array();
722 $pathIterator = \CIBlockSection::GetNavChain(
723 $element['IBLOCK_ID'],
724 $this->storage['SECTION']['ID'],
725 array(
726 'ID', 'CODE', 'XML_ID', 'EXTERNAL_ID', 'IBLOCK_ID',
727 'IBLOCK_SECTION_ID', 'SORT', 'NAME', 'ACTIVE',
728 'DEPTH_LEVEL', 'SECTION_PAGE_URL'
729 )
730 );
731 $pathIterator->SetUrlTemplates('', $this->arParams['SECTION_URL']);
732 while ($path = $pathIterator->GetNext())
733 {
734 if ($this->arParams["ADD_SECTIONS_CHAIN"])
735 {
736 $ipropValues = new Iblock\InheritedProperty\SectionValues($element['IBLOCK_ID'], $path['ID']);
737 $path['IPROPERTY_VALUES'] = $ipropValues->getValues();
738 }
739
740 $this->storage['SECTION']['PATH'][] = $path;
741 }
742 unset($path, $pathIterator);
743
744 if ($this->arParams['SECTIONS_CHAIN_START_FROM'] > 0)
745 {
746 $this->storage['SECTION']['PATH'] = array_slice($this->storage['SECTION']['PATH'], $this->arParams['SECTIONS_CHAIN_START_FROM']);
747 }
748
749 $element['SECTION'] = $this->storage['SECTION'];
750 }
751
752 unset($element);
753 }
754 }
755
756 protected function chooseOffer($offers, $iblockId)
757 {
758 $uniqueSortHash = array();
759
760 foreach ($offers as $offer)
761 {
762 $elementId = $offer['LINK_ELEMENT_ID'];
763
764 if (!isset($this->elementLinks[$elementId]))
765 continue;
766
767 if (!isset($uniqueSortHash[$elementId]))
768 {
769 $uniqueSortHash[$elementId] = array();
770 }
771
772 $uniqueSortHash[$elementId][$offer['SORT_HASH']] = true;
773
774 if ($this->elementLinks[$elementId]['OFFER_ID_SELECTED'] == 0 && $offer['CAN_BUY'])
775 {
776 $this->elementLinks[$elementId]['OFFER_ID_SELECTED'] = $offer['ID'];
777 }
778 }
779 unset($elementId, $offer);
780
781 foreach ($this->elementLinks as &$element)
782 {
783 if ($element['OFFER_ID_SELECTED'] == 0)
784 continue;
785
786 if (count($uniqueSortHash[$element['ID']]) < 2)
787 {
788 $element['OFFER_ID_SELECTED'] = 0;
789 }
790 }
791 }
792
793 protected function getCacheKeys()
794 {
795 $resultCacheKeys = array(
796 'IBLOCK_ID',
797 'ID',
798 'IBLOCK_SECTION_ID',
799 'NAME',
800 'LIST_PAGE_URL',
801 'CANONICAL_PAGE_URL',
802 'SECTION',
803 'IPROPERTY_VALUES',
804 'TIMESTAMP_X',
805 'BACKGROUND_IMAGE',
806 'USE_CATALOG_BUTTONS'
807 );
808
809 $this->initAdditionalCacheKeys($resultCacheKeys);
810
811 if (
812 $this->arParams['SET_TITLE']
813 || $this->arParams['ADD_ELEMENT_CHAIN']
814 || $this->arParams['SET_BROWSER_TITLE'] === 'Y'
815 || $this->arParams['SET_META_KEYWORDS'] === 'Y'
816 || $this->arParams['SET_META_DESCRIPTION'] === 'Y'
817 )
818 {
819 $this->arResult['META_TAGS'] = array();
820 $resultCacheKeys[] = 'META_TAGS';
821
822 $elementTitle = $this->arResult['NAME'];
823 if (
824 isset($this->arResult['IPROPERTY_VALUES']['ELEMENT_PAGE_TITLE'])
825 && $this->arResult['IPROPERTY_VALUES']['ELEMENT_PAGE_TITLE'] !== ''
826 )
827 {
828 $elementTitle = $this->arResult['IPROPERTY_VALUES']['ELEMENT_PAGE_TITLE'];
829 }
830 if ($this->arParams['SET_TITLE'])
831 {
832 $this->arResult['META_TAGS']['TITLE'] = $elementTitle;
833 }
834
835 if ($this->arParams['ADD_ELEMENT_CHAIN'])
836 {
837 $this->arResult['META_TAGS']['ELEMENT_CHAIN'] = $elementTitle;
838 }
839
840 if ($this->arParams['SET_BROWSER_TITLE'] === 'Y')
841 {
842 $browserTitle = Collection::firstNotEmpty(
843 $this->arResult['PROPERTIES'], array($this->arParams['BROWSER_TITLE'], 'VALUE'),
844 $this->arResult, $this->arParams['BROWSER_TITLE'],
845 $this->arResult['IPROPERTY_VALUES'], 'ELEMENT_META_TITLE'
846 );
847 $this->arResult['META_TAGS']['BROWSER_TITLE'] = is_array($browserTitle)
848 ? implode(' ', $browserTitle)
849 : $browserTitle;
850 unset($browserTitle);
851 }
852
853 if ($this->arParams['SET_META_KEYWORDS'] === 'Y')
854 {
855 $metaKeywords = Collection::firstNotEmpty(
856 $this->arResult['PROPERTIES'], array($this->arParams['META_KEYWORDS'], 'VALUE'),
857 $this->arResult['IPROPERTY_VALUES'], 'ELEMENT_META_KEYWORDS'
858 );
859 $this->arResult['META_TAGS']['KEYWORDS'] = is_array($metaKeywords)
860 ? implode(' ', $metaKeywords)
861 : $metaKeywords;
862 unset($metaKeywords);
863 }
864
865 if ($this->arParams['SET_META_DESCRIPTION'] === 'Y')
866 {
867 $metaDescription = Collection::firstNotEmpty(
868 $this->arResult['PROPERTIES'], array($this->arParams['META_DESCRIPTION'], 'VALUE'),
869 $this->arResult['IPROPERTY_VALUES'], 'ELEMENT_META_DESCRIPTION'
870 );
871 $this->arResult['META_TAGS']['DESCRIPTION'] = is_array($metaDescription)
872 ? implode(' ', $metaDescription)
873 : $metaDescription;
874 unset($metaDescription);
875 }
876 }
877
878 return $resultCacheKeys;
879 }
880
887 protected function initAdditionalCacheKeys(&$resultCacheKeys)
888 {
889 }
890
891 protected function initAdminIconsPanel()
892 {
893 global $APPLICATION, $USER;
894
895 if (!$USER->IsAuthorized())
896 return;
897
899
900 if (
901 $APPLICATION->GetShowIncludeAreas()
902 || $this->arParams['SET_TITLE']
903 || isset($arResult[$this->arParams['BROWSER_TITLE']])
904 )
905 {
906 if (Loader::includeModule('iblock'))
907 {
908 $returnUrl = array(
909 'add_element' => \CIBlock::GetArrayByID($this->arParams['IBLOCK_ID'], 'DETAIL_PAGE_URL'),
910 'delete_element' =>
911 isset($arResult['SECTION'])
912 ? $arResult['SECTION']['SECTION_PAGE_URL']
913 : $arResult['LIST_PAGE_URL'],
914 );
915 $buttonParams = array(
916 'RETURN_URL' => $returnUrl,
917 'CATALOG' => true
918 );
919
920 if (isset($arResult['USE_CATALOG_BUTTONS']))
921 {
922 $buttonParams['USE_CATALOG_BUTTONS'] = $arResult['USE_CATALOG_BUTTONS'];
923 if (!empty($buttonParams['USE_CATALOG_BUTTONS']))
924 {
925 $buttonParams['SHOW_CATALOG_BUTTONS'] = true;
926 }
927 }
928
929 $buttons = \CIBlock::GetPanelButtons(
930 $arResult['IBLOCK_ID'],
931 $arResult['ID'],
932 $arResult['IBLOCK_SECTION_ID'],
933 $buttonParams
934 );
935 unset($buttonParams);
936
937 if ($APPLICATION->GetShowIncludeAreas())
938 {
939 $this->addIncludeAreaIcons(\CIBlock::GetComponentMenu($APPLICATION->GetPublicShowMode(), $buttons));
940 }
941
942 if ($this->arParams['SET_TITLE'] || isset($arResult[$this->arParams['BROWSER_TITLE']]))
943 {
944 $this->storage['TITLE_OPTIONS'] = null;
945 if (isset($buttons['submenu']['edit_element']))
946 {
947 $this->storage['TITLE_OPTIONS'] = [
948 'ADMIN_EDIT_LINK' => $buttons['submenu']['edit_element']['ACTION'],
949 'PUBLIC_EDIT_LINK' => $buttons['edit']['edit_element']['ACTION'],
950 'COMPONENT_NAME' => $this->getName(),
951 ];
952 }
953 }
954 }
955 }
956 }
957
958 protected function sendCounters()
959 {
960 if ($this->arParams['USE_ELEMENT_COUNTER'] !== 'N' && Loader::includeModule('iblock'))
961 {
962 \CIBlockElement::CounterInc($this->arResult['ID']);
963 }
964 }
965
966 protected function saveViewedProduct()
967 {
968 }
969
970 protected function initMetaData()
971 {
972 global $APPLICATION;
974
975 if ($this->arParams['SET_CANONICAL_URL'] === 'Y' && $arResult["CANONICAL_PAGE_URL"])
976 $APPLICATION->SetPageProperty('canonical', $arResult["CANONICAL_PAGE_URL"]);
977
978 if ($this->arParams['SET_TITLE'])
979 {
980 $APPLICATION->SetTitle($arResult["META_TAGS"]["TITLE"], $this->storage['TITLE_OPTIONS'] ?? null);
981 }
982
983 if ($this->arParams['SET_BROWSER_TITLE'] === 'Y')
984 {
985 if ($arResult["META_TAGS"]["BROWSER_TITLE"] !== '')
986 {
987 $APPLICATION->SetPageProperty("title", $arResult["META_TAGS"]["BROWSER_TITLE"], $this->storage['TITLE_OPTIONS']);
988 }
989 }
990
991 if ($this->arParams['SET_META_KEYWORDS'] === 'Y')
992 {
993 if ($arResult["META_TAGS"]["KEYWORDS"] !== '')
994 {
995 $APPLICATION->SetPageProperty("keywords", $arResult["META_TAGS"]["KEYWORDS"], $this->storage['TITLE_OPTIONS']);
996 }
997 }
998
999 if ($this->arParams['SET_META_DESCRIPTION'] === 'Y')
1000 {
1001 if ($arResult["META_TAGS"]["DESCRIPTION"] !== '')
1002 {
1003 $APPLICATION->SetPageProperty("description", $arResult["META_TAGS"]["DESCRIPTION"], $this->storage['TITLE_OPTIONS']);
1004 }
1005 }
1006
1007 if (!empty($arResult['BACKGROUND_IMAGE']) && is_array($arResult['BACKGROUND_IMAGE']))
1008 {
1009 $APPLICATION->SetPageProperty(
1010 'backgroundImage',
1011 'style="background-image: url(\''.\CHTTP::urnEncode($arResult['BACKGROUND_IMAGE']['SRC'], 'UTF-8').'\')"'
1012 );
1013 }
1014
1015 if ($this->arParams['ADD_SECTIONS_CHAIN'] && !empty($arResult['SECTION']['PATH']) && is_array($arResult['SECTION']['PATH']))
1016 {
1017 foreach ($arResult['SECTION']['PATH'] as $path)
1018 {
1019 if (isset($path['IPROPERTY_VALUES']['SECTION_PAGE_TITLE']) && $path['IPROPERTY_VALUES']['SECTION_PAGE_TITLE'] !== '')
1020 {
1021 $APPLICATION->AddChainItem($path['IPROPERTY_VALUES']['SECTION_PAGE_TITLE'], $path['~SECTION_PAGE_URL']);
1022 }
1023 else
1024 {
1025 $APPLICATION->AddChainItem($path['NAME'], $path['~SECTION_PAGE_URL']);
1026 }
1027 }
1028 }
1029
1030 if ($this->arParams['ADD_ELEMENT_CHAIN'])
1031 {
1032 $APPLICATION->AddChainItem($arResult["META_TAGS"]["ELEMENT_CHAIN"]);
1033 }
1034
1035 if ($this->arParams['SET_LAST_MODIFIED'] && $arResult['TIMESTAMP_X'])
1036 {
1037 Main\Context::getCurrent()->getResponse()->setLastModified(DateTime::createFromUserTime($arResult["TIMESTAMP_X"]));
1038 }
1039 }
1040
1041 protected function getAdditionalCacheId()
1042 {
1043 return array(
1044 $this->productIdMap,
1045 $this->arParams['CACHE_GROUPS'] === 'N' ? false : $this->getUserGroupsCacheId()
1046 );
1047 }
1048
1049 protected function getComponentCachePath()
1050 {
1051 return false;
1052 }
1053
1054 protected function makeOutputResult()
1055 {
1056 parent::makeOutputResult();
1057 $this->arResult['CAT_PRICES'] = $this->storage['PRICES'];
1058 $this->arResult = array_merge($this->arResult, $this->elements[0]);
1059 }
1060
1061 protected function prepareTemplateParams()
1062 {
1063 parent::prepareTemplateParams();
1064 $params =& $this->arParams;
1065
1066 $params['DISPLAY_NAME'] = $params['DISPLAY_NAME'] === 'N' ? 'N' : 'Y';
1067 $params['USE_RATIO_IN_RANGES'] = $params['USE_RATIO_IN_RANGES'] === 'N' ? 'N' : 'Y';
1068
1069 if (!isset($params['IMAGE_RESOLUTION']))
1070 {
1071 $params['IMAGE_RESOLUTION'] = '16by9';
1072 }
1073
1074 if (!is_array($params['DETAIL_PICTURE_MODE']))
1075 {
1076 $params['DETAIL_PICTURE_MODE'] = array($params['DETAIL_PICTURE_MODE']);
1077 }
1078
1079 $params['ADD_DETAIL_TO_SLIDER'] = $params['ADD_DETAIL_TO_SLIDER'] === 'Y' ? 'Y' : 'N';
1080 $displayPreviewTextMode = array('H' => true, 'E' => true, 'S' => true);
1081 if (!isset($displayPreviewTextMode[$params['DISPLAY_PREVIEW_TEXT_MODE']]))
1082 {
1083 $params['DISPLAY_PREVIEW_TEXT_MODE'] = 'E';
1084 }
1085
1086 if (!is_array($params['ADD_TO_BASKET_ACTION']))
1087 {
1088 $params['ADD_TO_BASKET_ACTION'] = array($params['ADD_TO_BASKET_ACTION']);
1089 }
1090
1091 $params['ADD_TO_BASKET_ACTION'] = array_filter($params['ADD_TO_BASKET_ACTION'], 'CIBlockParameters::checkParamValues');
1092 if (empty($params['ADD_TO_BASKET_ACTION']) || (!in_array('ADD', $params['ADD_TO_BASKET_ACTION']) && !in_array('BUY', $params['ADD_TO_BASKET_ACTION'])))
1093 {
1094 $params['ADD_TO_BASKET_ACTION'] = array('BUY');
1095 }
1096
1097 if (!isset($params['ADD_TO_BASKET_ACTION_PRIMARY']) || !is_array($params['ADD_TO_BASKET_ACTION_PRIMARY']))
1098 {
1099 $params['ADD_TO_BASKET_ACTION_PRIMARY'] = array('BUY', 'ADD');
1100 }
1101
1102 $params['USE_VOTE_RATING'] = $params['USE_VOTE_RATING'] === 'Y' ? 'Y' : 'N';
1103
1104 if ($params['VOTE_DISPLAY_AS_RATING'] != 'vote_avg')
1105 {
1106 $params['VOTE_DISPLAY_AS_RATING'] = 'rating';
1107 }
1108
1109 $params['USE_COMMENTS'] = $params['USE_COMMENTS'] === 'Y' ? 'Y' : 'N';
1110 $params['BLOG_USE'] = $params['BLOG_USE'] === 'Y' ? 'Y' : 'N';
1111 $params['VK_USE'] = $params['VK_USE'] === 'Y' && !empty($params['VK_API_ID']) ? 'Y' : 'N';
1112 $params['FB_USE'] = $params['FB_USE'] === 'Y' && !empty($params['FB_APP_ID']) ? 'Y' : 'N';
1113
1114 if ($params['USE_COMMENTS'] === 'Y')
1115 {
1116 if ($params['BLOG_USE'] === 'N' && $params['VK_USE'] === 'N' && $params['FB_USE'] === 'N')
1117 {
1118 $params['USE_COMMENTS'] = 'N';
1119 }
1120 }
1121
1122 $params['BRAND_USE'] = $params['BRAND_USE'] === 'Y' ? 'Y' : 'N';
1123
1124 if ($params['BRAND_PROP_CODE'] == '')
1125 {
1126 $params['BRAND_PROP_CODE'] = array();
1127 }
1128
1129 if (!is_array($params['BRAND_PROP_CODE']))
1130 {
1131 $params['BRAND_PROP_CODE'] = array($params['BRAND_PROP_CODE']);
1132 }
1133
1134 if (empty($params['PRODUCT_INFO_BLOCK_ORDER']))
1135 {
1136 $params['PRODUCT_INFO_BLOCK_ORDER'] = 'sku,props,priceRanges';
1137 }
1138
1139 if (is_string($params['PRODUCT_INFO_BLOCK_ORDER']))
1140 {
1141 $params['PRODUCT_INFO_BLOCK_ORDER'] = explode(',', $params['PRODUCT_INFO_BLOCK_ORDER']);
1142 }
1143
1144 if (empty($params['PRODUCT_PAY_BLOCK_ORDER']))
1145 {
1146 $params['PRODUCT_PAY_BLOCK_ORDER'] = 'rating,price,quantityLimit,quantity,buttons';
1147 }
1148
1149 if (is_string($params['PRODUCT_PAY_BLOCK_ORDER']))
1150 {
1151 $params['PRODUCT_PAY_BLOCK_ORDER'] = explode(',', $params['PRODUCT_PAY_BLOCK_ORDER']);
1152 }
1153
1154 $this->getTemplateIblockParams($params);
1155 }
1156
1157 protected function getTemplateIblockParams(&$params)
1158 {
1159 $params['ADD_PICT_PROP'] = isset($params['ADD_PICT_PROP']) ? trim($params['ADD_PICT_PROP']) : '';
1160 if ($params['ADD_PICT_PROP'] === '-')
1161 {
1162 $params['ADD_PICT_PROP'] = '';
1163 }
1164
1165 if (!isset($params['LABEL_PROP']) || !is_array($params['LABEL_PROP']))
1166 {
1167 $params['LABEL_PROP'] = array();
1168 }
1169
1170 if (!isset($params['LABEL_PROP_MOBILE']) || !is_array($params['LABEL_PROP_MOBILE']))
1171 {
1172 $params['LABEL_PROP_MOBILE'] = array();
1173 }
1174
1175 if (!empty($params['LABEL_PROP_MOBILE']))
1176 {
1177 $params['LABEL_PROP_MOBILE'] = array_flip($params['LABEL_PROP_MOBILE']);
1178 }
1179 $params['ENLARGE_PROP'] = isset($params['ENLARGE_PROP']) ? trim($params['ENLARGE_PROP']) : '';
1180 if ($params['ENLARGE_PROP'] === '-')
1181 {
1182 $params['ENLARGE_PROP'] = '';
1183 }
1184
1185 $params['OFFER_ADD_PICT_PROP'] = isset($params['OFFER_ADD_PICT_PROP']) ? trim($params['OFFER_ADD_PICT_PROP']) : '';
1186 if ($params['OFFER_ADD_PICT_PROP'] === '-')
1187 {
1188 $params['OFFER_ADD_PICT_PROP'] = '';
1189 }
1190
1191 if (!isset($params['MAIN_BLOCK_PROPERTY_CODE']) || !is_array($params['MAIN_BLOCK_PROPERTY_CODE']))
1192 {
1193 $params['MAIN_BLOCK_PROPERTY_CODE'] = array();
1194 }
1195
1196 if (!empty($params['MAIN_BLOCK_PROPERTY_CODE']))
1197 {
1198 $params['MAIN_BLOCK_PROPERTY_CODE'] = array_flip($params['MAIN_BLOCK_PROPERTY_CODE']);
1199 }
1200
1201 if (!isset($params['MAIN_BLOCK_OFFERS_PROPERTY_CODE']) || !is_array($params['MAIN_BLOCK_OFFERS_PROPERTY_CODE']))
1202 {
1203 $params['MAIN_BLOCK_OFFERS_PROPERTY_CODE'] = array();
1204 }
1205
1206 if (!empty($params['MAIN_BLOCK_OFFERS_PROPERTY_CODE']))
1207 {
1208 $params['MAIN_BLOCK_OFFERS_PROPERTY_CODE'] = array_flip($params['MAIN_BLOCK_OFFERS_PROPERTY_CODE']);
1209 }
1210
1211 if (!isset($this->storage['IBLOCK_PARAMS'][$params['IBLOCK_ID']]) || !is_array($this->storage['IBLOCK_PARAMS'][$params['IBLOCK_ID']]))
1212 {
1213 $this->storage['IBLOCK_PARAMS'][$params['IBLOCK_ID']] = array();
1214 }
1215
1216 $this->storage['IBLOCK_PARAMS'][$params['IBLOCK_ID']]['ADD_PICT_PROP'] = $params['ADD_PICT_PROP'];
1217 $this->storage['IBLOCK_PARAMS'][$params['IBLOCK_ID']]['LABEL_PROP'] = $params['LABEL_PROP'];
1218 $this->storage['IBLOCK_PARAMS'][$params['IBLOCK_ID']]['LABEL_PROP_MOBILE'] = $params['LABEL_PROP_MOBILE'];
1219 $this->storage['IBLOCK_PARAMS'][$params['IBLOCK_ID']]['ENLARGE_PROP'] = $params['ENLARGE_PROP'];
1220 $this->storage['IBLOCK_PARAMS'][$params['IBLOCK_ID']]['OFFERS_ADD_PICT_PROP'] = $params['OFFER_ADD_PICT_PROP'];
1221 $this->storage['IBLOCK_PARAMS'][$params['IBLOCK_ID']]['MAIN_BLOCK_PROPERTY_CODE'] = $params['MAIN_BLOCK_PROPERTY_CODE'];
1222 $this->storage['IBLOCK_PARAMS'][$params['IBLOCK_ID']]['MAIN_BLOCK_OFFERS_PROPERTY_CODE'] = $params['MAIN_BLOCK_OFFERS_PROPERTY_CODE'];
1223
1224 unset($skuTreeProperties);
1225 }
1226
1227 protected function getTemplateDefaultParams()
1228 {
1229 $defaultParams = parent::getTemplateDefaultParams();
1230 $defaultParams['DISPLAY_NAME'] = 'Y';
1231 $defaultParams['USE_RATIO_IN_RANGES'] = 'Y';
1232 $defaultParams['IMAGE_RESOLUTION'] = '16by9';
1233 $defaultParams['DETAIL_PICTURE_MODE'] = array('POPUP', 'MAGNIFIER');
1234 $defaultParams['ADD_DETAIL_TO_SLIDER'] = 'N';
1235 $defaultParams['DISPLAY_PREVIEW_TEXT_MODE'] = 'E';
1236 $defaultParams['ADD_TO_BASKET_ACTION'] = array('BUY');
1237 $defaultParams['ADD_TO_BASKET_ACTION_PRIMARY'] = array('BUY', 'ADD');
1238 $defaultParams['USE_VOTE_RATING'] = 'N';
1239 $defaultParams['VOTE_DISPLAY_AS_RATING'] = 'rating';
1240 $defaultParams['USE_COMMENTS'] = 'N';
1241 $defaultParams['BLOG_USE'] = 'N';
1242 $defaultParams['BLOG_URL'] = 'catalog_comments';
1243 $defaultParams['BLOG_EMAIL_NOTIFY'] = 'N';
1244 $defaultParams['VK_USE'] = 'N';
1245 $defaultParams['VK_API_ID'] = '';
1246 $defaultParams['FB_USE'] = 'N';
1247 $defaultParams['FB_APP_ID'] = '';
1248 $defaultParams['BRAND_USE'] = 'N';
1249 $defaultParams['BRAND_PROP_CODE'] = '';
1250
1251 return $defaultParams;
1252 }
1253
1254 protected function editTemplateData()
1255 {
1256 $this->arResult['DEFAULT_PICTURE'] = $this->getTemplateEmptyPreview();
1257 $this->arResult['SKU_PROPS'] = $this->getTemplateSkuPropList();
1258 $this->arResult['CURRENCIES'] = $this->getTemplateCurrencies();
1259 $this->editTemplateItems($this->arResult);
1260 }
1261
1262 protected function editTemplateOfferProps(&$item)
1263 {
1264 $matrix = array();
1265 $newOffers = array();
1266 $double = array();
1267 $item['OFFER_GROUP'] = false;
1268 $item['OFFERS_PROP'] = false;
1269
1270 $iblockParams = $this->storage['IBLOCK_PARAMS'][$item['IBLOCK_ID']];
1271
1272 $boolSkuDisplayProps = false;
1273 $skuPropList = $this->arResult['SKU_PROPS'];
1274 $skuPropIds = array_keys($skuPropList);
1275 $matrixFields = array_fill_keys($skuPropIds, false);
1276
1277 foreach ($item['OFFERS'] as $keyOffer => $offer)
1278 {
1279 $offer['ID'] = (int)$offer['ID'];
1280
1281 if (isset($double[$offer['ID']]))
1282 continue;
1283
1284 $offer['OFFER_GROUP'] = false;
1285
1286 $row = array();
1287 foreach ($skuPropIds as $code)
1288 {
1289 $row[$code] = $this->getTemplatePropCell($code, $offer, $matrixFields, $skuPropList);
1290 }
1291
1292 $matrix[$keyOffer] = $row;
1293
1294 \CIBlockPriceTools::setRatioMinPrice($offer, false);
1295 $this->editTemplateOfferSlider($offer, $item['IBLOCK_ID'], 0, $this->arParams['ADD_DETAIL_TO_SLIDER'] === 'Y', $item['MORE_PHOTO']);
1296
1297 if (\CIBlockPriceTools::clearProperties($offer['DISPLAY_PROPERTIES'], $iblockParams['OFFERS_TREE_PROPS']))
1298 {
1299 $boolSkuDisplayProps = true;
1300 }
1301 $offer['TREE'] = [];
1302
1303 $double[$offer['ID']] = true;
1304 $newOffers[$keyOffer] = $offer;
1305 }
1306
1307 $item['OFFERS'] = $newOffers;
1308 $item['SHOW_OFFERS_PROPS'] = $boolSkuDisplayProps;
1309
1310 $usedFields = array();
1311 $sortFields = array();
1312
1313 foreach ($skuPropIds as $propCode)
1314 {
1315 $boolExist = $matrixFields[$propCode];
1316 foreach ($matrix as $keyOffer => $row)
1317 {
1318 if ($boolExist)
1319 {
1320 $item['OFFERS'][$keyOffer]['TREE']['PROP_'.$skuPropList[$propCode]['ID']] = $matrix[$keyOffer][$propCode]['VALUE'];
1321 $item['OFFERS'][$keyOffer]['SKU_SORT_'.$propCode] = $matrix[$keyOffer][$propCode]['SORT'];
1322 $usedFields[$propCode] = true;
1323 $sortFields['SKU_SORT_'.$propCode] = SORT_NUMERIC;
1324 }
1325 else
1326 {
1327 unset($matrix[$keyOffer][$propCode]);
1328 }
1329 }
1330 }
1331
1332 $item['OFFERS_PROP'] = $usedFields;
1333 $item['OFFERS_PROP_CODES'] = (!empty($usedFields) ? base64_encode(serialize(array_keys($usedFields))) : '');
1334
1335 Collection::sortByColumn($item['OFFERS'], $sortFields);
1336 }
1337
1338 protected function editTemplateProductSets(&$item)
1339 {
1340 $result = array();
1341 if (!Catalog\Config\Feature::isProductSetsEnabled())
1342 return $result;
1343 if (!isset($item['PRODUCT']['TYPE']))
1344 return $result;
1345
1346 $parentBundle = ($item['PRODUCT']['BUNDLE'] == 'Y');
1347 if ($parentBundle)
1348 $result[$item['ID']] = true;
1349 if ($item['PRODUCT']['TYPE'] == Catalog\ProductTable::TYPE_SKU)
1350 {
1351 foreach ($item['OFFERS'] as $offer)
1352 {
1353 if (
1354 $parentBundle
1355 || ($offer['PRODUCT']['BUNDLE'] == 'Y')
1356 )
1357 {
1358 $result[$offer['ID']] = true;
1359 }
1360 }
1361 unset($offer);
1362 }
1363 unset($parentBundle);
1364
1365 $item['OFFER_GROUP'] = !empty($result);
1366 if (!empty($result))
1367 $item['OFFER_GROUP_VALUES'] = array_keys($result);
1368
1369 return $result;
1370 }
1371
1372 protected function editTemplateJsOffers(&$item, $offerSet)
1373 {
1374 $matrix = [];
1375 $intSelected = -1;
1376
1377 $offerText = $this->arParams['SHOW_SKU_DESCRIPTION'] === 'Y';
1378
1379 foreach ($item['OFFERS'] as $keyOffer => $offer)
1380 {
1381 if ($item['OFFER_ID_SELECTED'] > 0)
1382 {
1383 $foundOffer = ($item['OFFER_ID_SELECTED'] == $offer['ID']);
1384 }
1385 else
1386 {
1387 $foundOffer = $offer['CAN_BUY'];
1388 }
1389
1390 if ($foundOffer && $intSelected == -1)
1391 {
1392 $intSelected = $keyOffer;
1393 }
1394 unset($foundOffer);
1395
1396 $skuProps = false;
1397 if (!empty($offer['DISPLAY_PROPERTIES']))
1398 {
1399 $skuProps = [];
1400 foreach ($offer['DISPLAY_PROPERTIES'] as $oneProp)
1401 {
1402 if ($oneProp['PROPERTY_TYPE'] === Iblock\PropertyTable::TYPE_FILE)
1403 {
1404 continue;
1405 }
1406
1407 $skuProps[] = [
1408 'CODE' => $oneProp['CODE'],
1409 'NAME' => $oneProp['NAME'],
1410 'VALUE' => $oneProp['DISPLAY_VALUE'],
1411 ];
1412 }
1413 unset($oneProp);
1414 }
1415
1416 if (isset($offerSet[$offer['ID']]))
1417 {
1418 $offer['OFFER_GROUP'] = true;
1419 $item['OFFERS'][$keyOffer]['OFFER_GROUP'] = true;
1420 }
1421
1422 $ratioSelectedIndex = $offer['ITEM_MEASURE_RATIO_SELECTED'];
1423 $firstPhoto = reset($offer['MORE_PHOTO']);
1424 $oneRow = [
1425 'ID' => $offer['ID'],
1426 'CODE' => $offer['CODE'],
1427 'NAME' => $offer['~NAME'] ?? $item['~NAME'],
1428 'TREE' => $offer['TREE'],
1429 'DISPLAY_PROPERTIES' => $skuProps,
1430 'PREVIEW_TEXT' => $offerText ? $offer['PREVIEW_TEXT'] : '',
1431 'PREVIEW_TEXT_TYPE' => $offerText ? $offer['PREVIEW_TEXT_TYPE'] : '',
1432 'DETAIL_TEXT' => $offerText ? $offer['DETAIL_TEXT'] : '',
1433 'DETAIL_TEXT_TYPE' => $offerText ? $offer['DETAIL_TEXT_TYPE'] : '',
1434 'ITEM_PRICE_MODE' => $offer['ITEM_PRICE_MODE'],
1435 'ITEM_PRICES' => $offer['ITEM_PRICES'],
1436 'ITEM_PRICE_SELECTED' => $offer['ITEM_PRICE_SELECTED'],
1437 'ITEM_QUANTITY_RANGES' => $offer['ITEM_QUANTITY_RANGES'],
1438 'ITEM_QUANTITY_RANGE_SELECTED' => $offer['ITEM_QUANTITY_RANGE_SELECTED'],
1439 'ITEM_MEASURE_RATIOS' => $offer['ITEM_MEASURE_RATIOS'],
1440 'ITEM_MEASURE_RATIO_SELECTED' => $ratioSelectedIndex,
1441 'PREVIEW_PICTURE' => $firstPhoto,
1442 'DETAIL_PICTURE' => $firstPhoto,
1443 'CHECK_QUANTITY' => $offer['CHECK_QUANTITY'],
1444 'MAX_QUANTITY' => $offer['PRODUCT']['QUANTITY'],
1445 'STEP_QUANTITY' => $offer['ITEM_MEASURE_RATIOS'][$ratioSelectedIndex]['RATIO'], // deprecated
1446 'QUANTITY_FLOAT' => is_float($offer['ITEM_MEASURE_RATIOS'][$ratioSelectedIndex]['RATIO']), // deprecated
1447 'MEASURE' => $offer['ITEM_MEASURE']['TITLE'],
1448 'OFFER_GROUP' => (isset($offerSet[$offer['ID']]) && $offerSet[$offer['ID']]),
1449 'CAN_BUY' => $offer['CAN_BUY'],
1450 'CATALOG_SUBSCRIBE' => $offer['PRODUCT']['SUBSCRIBE'],
1451 'SLIDER' => $offer['MORE_PHOTO'],
1452 'SLIDER_COUNT' => $offer['MORE_PHOTO_COUNT'],
1453 ];
1454 unset($ratioSelectedIndex);
1455
1456 $matrix[$keyOffer] = $oneRow;
1457 }
1458
1459 if ($intSelected == -1)
1460 {
1461 $intSelected = 0;
1462 }
1463
1464 $item['JS_OFFERS'] = $matrix;
1465 $item['OFFERS_SELECTED'] = $intSelected;
1466
1467 if ($matrix[$intSelected]['SLIDER_COUNT'] > 0)
1468 {
1469 $item['MORE_PHOTO'] = $matrix[$intSelected]['SLIDER'];
1470 $item['MORE_PHOTO_COUNT'] = $matrix[$intSelected]['SLIDER_COUNT'];
1471 }
1472
1473 $item['OFFERS_IBLOCK'] = $this->storage['SKU_IBLOCK_INFO']['IBLOCK_ID'];
1474 }
1475
1476 public function getTemplateSkuPropList()
1477 {
1478 $skuPropList = array();
1479
1480 if ($this->arResult['MODULES']['catalog'] && !empty($this->arParams['IBLOCK_ID']))
1481 {
1482 $sku = \CCatalogSku::GetInfoByProductIBlock($this->arParams['IBLOCK_ID']);
1483 $iblockParams = $this->storage['IBLOCK_PARAMS'][$this->arParams['IBLOCK_ID']];
1484 $boolSku = !empty($sku) && is_array($sku);
1485 if ($boolSku && !empty($iblockParams['OFFERS_TREE_PROPS']) && $this->arParams['PRODUCT_DISPLAY_MODE'] === 'Y')
1486 {
1487 $this->storage['SKU_IBLOCK_INFO'] = $sku;
1488
1489 $skuPropList = \CIBlockPriceTools::getTreeProperties(
1490 $sku,
1491 $iblockParams['OFFERS_TREE_PROPS'],
1492 array(
1493 'PICT' => $this->arResult['DEFAULT_PICTURE'],
1494 'NAME' => '-'
1495 )
1496 );
1497
1498 if (empty($skuPropList))
1499 {
1500 $this->arParams['PRODUCT_DISPLAY_MODE'] = 'N';
1501 }
1502 }
1503 }
1504
1505 return $skuPropList;
1506 }
1507
1508 protected function editTemplateItems(&$item)
1509 {
1510 $skuPropList =& $this->arResult['SKU_PROPS'];
1511
1512 if (!isset($item['CATALOG_QUANTITY']))
1513 {
1514 $item['CATALOG_QUANTITY'] = 0;
1515 }
1516
1517 $item['CATALOG_QUANTITY'] = $item['CATALOG_QUANTITY'] > 0 && is_float($item['ITEM_MEASURE_RATIOS'][$item['ITEM_MEASURE_RATIO_SELECTED']]['RATIO'])
1518 ? (float)$item['CATALOG_QUANTITY']
1519 : (int)$item['CATALOG_QUANTITY'];
1520
1521 $item['CATALOG'] = false;
1522 $item['CATALOG_SUBSCRIPTION'] = isset($item['CATALOG_SUBSCRIPTION']) && $item['CATALOG_SUBSCRIPTION'] === 'Y' ? 'Y' : 'N';
1523
1524 \CIBlockPriceTools::getLabel($item, $this->arParams['LABEL_PROP']);
1525 $this->editTemplateProductSlider($item, $item['IBLOCK_ID'], 0, $this->arParams['ADD_DETAIL_TO_SLIDER'] === 'Y', array($this->arResult['DEFAULT_PICTURE']));
1526 $this->editTemplateCatalogInfo($item);
1527
1528 $item['SHOW_OFFERS_PROPS'] = false;
1529 if ($item['CATALOG'] && !empty($item['OFFERS']))
1530 {
1531 $needValues = array();
1532
1533 foreach ($item['OFFERS'] as &$offer)
1534 {
1535 foreach (array_keys($skuPropList) as $strOneCode)
1536 {
1537 if (isset($offer['DISPLAY_PROPERTIES'][$strOneCode]))
1538 {
1539 if (!isset($needValues[$skuPropList[$strOneCode]['ID']]))
1540 {
1541 $needValues[$skuPropList[$strOneCode]['ID']] = array();
1542 }
1543
1544 $valueId = $skuPropList[$strOneCode]['PROPERTY_TYPE'] == Iblock\PropertyTable::TYPE_LIST
1545 ? $offer['DISPLAY_PROPERTIES'][$strOneCode]['VALUE_ENUM_ID']
1546 : $offer['DISPLAY_PROPERTIES'][$strOneCode]['VALUE'];
1547
1548 $needValues[$skuPropList[$strOneCode]['ID']][$valueId] = $valueId;
1549 unset($valueId);
1550 }
1551 }
1552 unset($strOneCode);
1553 }
1554 unset($offer);
1555
1556 if (!empty($needValues))
1557 \CIBlockPriceTools::getTreePropertyValues($skuPropList, $needValues);
1558 unset($needValues);
1559 $this->editTemplateOfferProps($item);
1560 $offerSet = $this->editTemplateProductSets($item);
1561 $this->editTemplateJsOffers($item, $offerSet);
1562 }
1563
1564 if ($item['MODULES']['catalog'] && $item['CATALOG'])
1565 {
1566 if (
1567 $item['CATALOG_TYPE'] == Catalog\ProductTable::TYPE_PRODUCT
1568 || $item['CATALOG_TYPE'] == Catalog\ProductTable::TYPE_SET
1569 )
1570 {
1571 if (isset($item['MIN_PRICE']))
1572 {
1573 \CIBlockPriceTools::setRatioMinPrice($item, false);
1574 $item['MIN_BASIS_PRICE'] = $item['MIN_PRICE'];
1575 }
1576 }
1577
1578 if (
1579 Catalog\Config\Feature::isProductSetsEnabled()
1580 && (
1581 $item['CATALOG_TYPE'] == Catalog\ProductTable::TYPE_PRODUCT
1582 || $item['CATALOG_TYPE'] == Catalog\ProductTable::TYPE_SET
1583 )
1584 )
1585 {
1586 $item['OFFER_GROUP'] = (isset($item['PRODUCT']['BUNDLE']) && $item['PRODUCT']['BUNDLE'] === 'Y');
1587 }
1588
1589 // fix warnings in templates for simple products
1590 $item['OFFERS_IBLOCK'] ??= ($this->storage['SKU_IBLOCK_INFO']['IBLOCK_ID'] ?? 0);
1591 $item['OFFERS_SELECTED'] ??= 0;
1592 // end fix
1593 }
1594
1595 if (!empty($item['DISPLAY_PROPERTIES']))
1596 {
1597 foreach ($item['DISPLAY_PROPERTIES'] as $propKey => $displayProperty)
1598 {
1599 if ($displayProperty['PROPERTY_TYPE'] === 'F')
1600 {
1601 unset($item['DISPLAY_PROPERTIES'][$propKey]);
1602 }
1603 }
1604 }
1605 }
1606}
$path
Определения access_edit.php:21
global $APPLICATION
Определения include.php:80
$arResult
Определения generate_coupon.php:16
static setProductPropertiesCache($productId, $props)
Определения discountmanager.php:517
onPrepareComponentParams($params)
Определения element.php:22
getElementList($iblockId, $products)
Определения element.php:476
showWorkflowHistory()
Определения element.php:449
initAdminIconsPanel()
Определения element.php:891
checkProductIblock(array $product)
Определения element.php:391
chooseOffer($offers, $iblockId)
Определения element.php:756
initAdditionalCacheKeys(&$resultCacheKeys)
Определения element.php:887
getIblockParams(&$params)
Определения element.php:136
initIblockPropertyFeatures()
Определения element.php:381
loadDisplayPropertyCodes($iblockId)
Определения element.php:400
modifyDisplayProperties($iblock, &$iblockElements)
Определения element.php:571
static isCheckboxProperty(array $property)
Определения tools.php:207
static clearCache()
Определения tools.php:253
static getDetailPageShowProperties($iblockId, array $parameters=[])
Определения propertyfeature.php:431
Определения error.php:15
static includeModule($moduleName)
Определения loader.php:67
static isEventEnabled(string $eventName)
Определения facebookconversion.php:575
static urnEncode($str, $charset=false)
Определения http.php:596
static GetElementID($element_id, $element_code, $section_id, $section_code, $arFilter)
Определения comp_findtools.php:5
static clearCache()
Определения comp_formatprops.php:304
static GetProductProperties( $IBLOCK_ID, $ELEMENT_ID, $arPropertiesList, $arPropertiesValues)
Определения comp_pricetools.php:610
static getFillProductProperties($productProps)
Определения comp_pricetools.php:896
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$iblockId
Определения iblock_catalog_edit.php:30
if(! $catalogEdit->isSuccess()) $iblock
Определения iblock_catalog_edit.php:38
$filterFields
Определения iblock_catalog_list.php:55
$selectFields
Определения iblock_catalog_list.php:160
global $USER
Определения csv_new_run.php:40
$success
Определения mail_entry.php:69
Определения entity.php:2
hasErrors()
Определения errorableimplementation.php:17
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</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
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$k
Определения template_pdf.php:567