Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
dataloader.php
1<?php
3
11
12Loc::loadMessages(__FILE__);
13
14if (Loader::includeModule('landing'))
15{
16 class DataLoader extends Source\DataLoader
17 {
18 protected $catalogIncluded = null;
19
20 protected $saleIncluded = null;
21
22 protected $iblockId = 0;
23
25 protected $catalog = null;
26
27 protected $productFields = null;
28
29 protected $priceTypes = null;
30
34 public function __construct()
35 {
36 parent::__construct();
37 $this->catalogIncluded = Loader::includeModule('catalog');
38 $this->saleIncluded = Loader::includeModule('sale');
39 }
40
44 public function getElementListData()
45 {
46 $this->seo->clear();
47
48 $this->initIblock();
49
50 $settings = self::getInternalSettings();
51
52 $rawSelect = $this->getPreparedSelectFields();
53 if (empty($rawSelect))
54 return [];
55
56 $rawOrder = $this->getOrder();
57 self::prepareOrder($settings, $rawOrder);
58
59 $rawSelect[] = 'DETAIL_PAGE_URL';
60 $this->prepareSelectFields($settings, $rawSelect);
61 unset($rawSelect);
62
63 $settings['filter'] = $this->getIblockElementListFilter();
64
65 $settings['limit'] = $this->getLimit();
66
67 $detailPageUrl = $this->getOptionsValue('detail_page_url');
68 if (!empty($detailPageUrl))
69 $settings['templates']['detailPageUrl'] = $detailPageUrl;
70
71 $settings['loadSeo'] = false;
72
73 $settings['mode'] = 'list';
74
75 return array_values($this->getElementsInternal($settings));
76 }
77
82 public function getElementData($element)
83 {
84 $this->seo->clear();
85
86 $this->initIblock();
87
88 $result = [];
89 if (!is_string($element) && !is_int($element))
90 return $result;
91 $element = (int)$element;
92 if ($element <= 0)
93 return $result;
94
95 $rawSelect = $this->getPreparedSelectFields();
96 if (empty($rawSelect))
97 return $result;
98
99 $settings = self::getInternalSettings();
100
101 $this->prepareSelectFields($settings, $rawSelect);
102 unset($rawSelect);
103
104 $filter = [];
105 if (!empty($internalFilter) && is_array($internalFilter))
106 $filter = array_merge($filter, $internalFilter);
107 $filter['ID'] = $element;
108 $settings['filter'] = $filter;
109 unset($filter);
110
111 $settings['loadSeo'] = true;
112
113 $settings['mode'] = 'detail';
114
115 $result = $this->getElementsInternal($settings);;
116 unset($settings);
117 if (!empty($result))
118 {
119 $result = reset($result);
120 if (!empty($result))
121 {
122 $this->seo->setProperties($result['SEO_PROPERTIES']);
123 unset($result['SEO_PROPERTIES']);
124 $result = [$result];
125 }
126 }
127
128 return $result;
129 }
130
134 private static function getInternalSettings()
135 {
136 return [
137 'rawSelect' => [],
138 'element' => [],
139 'element_properties' => [],
140 'product' => [],
141 'prices' => false,
142 'limit' => 0,
143 'order' => [],
144 'rawOrder' => [],
145 'sortByPrice' => false,
146 'templates' => []
147 ];
148 }
149
153 protected function getPreparedSelectFields()
154 {
155 $result = parent::getPreparedSelectFields();
156 if (!empty($result))
157 {
158 if (!in_array('ID', $result))
159 {
160 $result[] = 'ID';
161 }
162 if (!in_array('IBLOCK_ID', $result))
163 {
164 $result[] = 'IBLOCK_ID';
165 }
166 if (!in_array('NAME', $result))
167 {
168 $result[] = 'NAME';
169 }
170 }
171 return $result;
172 }
173
179 protected function getOrder()
180 {
181 $result = parent::getOrder();
182 if (!is_array($result))
183 {
184 $result = [];
185 }
186 return $result;
187 }
188
194 protected function getLimit()
195 {
196 return (int)$this->getSettingsValue('limit');
197 }
198
202 protected function initIblock()
203 {
204 $internalFilter = $this->getInternalFilter();
205 if (!empty($internalFilter) && is_array($internalFilter))
206 {
207 if (isset($internalFilter['IBLOCK_ID']))
208 $this->iblockId = (int)$internalFilter['IBLOCK_ID'];
209 if ($this->iblockId > 0 && $this->catalogIncluded)
210 {
211 $catalog = \CCatalogSku::GetInfoByProductIBlock($this->iblockId);
212 if (!empty($catalog))
213 $this->catalog = $catalog;
214 unset($catalog);
215 }
216 }
217 unset($internalFilter);
218 }
219
223 protected function getIblockElementListFilter()
224 {
225 $result = $this->compileIblockElementListFilter(
226 $this->getPreparedFilter($this->getFilterFieldsDescription())
227 );
228 $internalFilter = $this->getInternalFilter();
229 if (!empty($internalFilter) && is_array($internalFilter))
230 {
231 $result = array_merge($result, $internalFilter);
232 }
233 unset($internalFilter);
234 return $result;
235 }
236
241 protected function compileIblockElementListFilter(array $filter)
242 {
243 $result = [];
244 if (isset($filter['master']))
245 $result = $filter['master'];
246 if (!empty($this->catalog) && isset($filter['offer']))
247 {
248 $subFilter = $filter['offer'];
249 $subFilter['IBLOCK_ID'] = $this->catalog['IBLOCK_ID'];
250 $result['=ID'] = \CIBlockElement::SubQuery('PROPERTY_'.$this->catalog['SKU_PROPERTY_ID'], $subFilter);
251 unset($subFilter);
252 }
253
254 if (!isset($result['ACTIVE']))
255 $result['ACTIVE'] = 'Y';
256 return $result;
257 }
258
264 private function prepareSelectFields(array &$settings, array $select)
265 {
266 $settings['rawSelect'] = $select;
267 if (!empty($settings['order']))
268 {
269 foreach (array_keys($settings['order']) as $field)
270 {
271 if (!in_array($field, $select))
272 $select[] = $field;
273 }
274 }
275
276 $productFields = $this->getProductFields();
277 foreach ($select as $index => $field)
278 {
279 if ($field == 'PRICE')
280 {
281 $settings['prices'] = true;
282 unset($select[$index]);
283 }
284 elseif (isset($productFields[$field]))
285 {
286 $settings['product'][$field] = $productFields[$field];
287 unset($select[$index]);
288 }
289 elseif (strncmp($field, 'PROPERTY_', 9) == 0)
290 {
291 $propertyId = (int)mb_substr($field, 9);
292 if ($propertyId > 0)
293 $settings['element_properties'][$propertyId] = $propertyId;
294 unset($select[$index]);
295 unset($propertyId);
296 }
297 }
298 unset($index, $field);
299 unset($productFields);
300
301 $settings['element'] = $select;
302 }
303
309 private static function prepareOrder(array &$settings, array $order)
310 {
311 if (!isset($order['by']) || !isset($order['order']))
312 return;
313 $rawOrder = [$order['by'] => $order['order']];
314 $settings['rawOrder'] = $rawOrder;
315 if (isset($rawOrder['PRICE']))
316 {
317 $settings['sortByPrice'] = true;
318 $settings['prices'] = true;
319 unset($rawOrder['PRICE']);
320 }
321 $settings['order'] = $rawOrder;
322 }
323
327 protected function getProductFields()
328 {
329 if ($this->productFields === null)
330 {
331 $result = [];
332 if ($this->catalogIncluded)
333 {
334 $result = Catalog\ProductTable::getEntity()->getScalarFields();
335 unset($result['ID']);
336 $result = array_fill_keys(array_keys($result), true);
337 }
338 $this->productFields = $result;
339 unset($result);
340 }
341 return $this->productFields;
342 }
343
344 private function getFilterFieldsDescription()
345 {
346 $result = [];
347 $result['NAME'] = [
348 'id' => 'NAME',
349 'type' => 'string',
350 'operators' => [
351 'default' => '%',
352 'quickSearch' => '?'
353 ],
354 'quickSearch' => true
355 ];
356 $result['ID'] = [
357 'id' => 'ID',
358 'type' => 'number',
359 'operators' => [
360 'default' => '=',
361 'exact' => '=',
362 'range' => '><',
363 'more' => '>',
364 'less' => '<'
365 ]
366 ];
367 $result['SECTION_ID'] = [
368 'id' => 'SECTION_ID',
369 'type' => 'list',
370 'operators' => [
371 'default' => '='
372 ]
373 ];
374 $result['INCLUDE_SUBSECTIONS'] = [
375 'id' => 'INCLUDE_SUBSECTIONS',
376 'type' => 'checkbox',
377 'operators' => [
378 'default' => ''
379 ]
380 ];
381 $result['ACTIVE'] = [
382 'id' => 'ACTIVE',
383 'type' => 'list',
384 'operators' => [
385 'default' => '='
386 ]
387 ];
388 $result['XML_ID'] = [
389 'id' => 'XML_ID',
390 'type' => 'string',
391 'operators' => [
392 'default' => '='
393 ]
394 ];
395 $result['CODE'] = [
396 'id' => 'CODE',
397 'type' => 'string',
398 'operators' => [
399 'default' => '='
400 ]
401 ];
402 $result['ACTIVE_FROM'] = [
403 'id' => 'ACTIVE_FROM',
404 'type' => 'date',
405 'operators' => [
406 'default' => '=',
407 'range' => '><'
408 ]
409 ];
410 $result['ACTIVE_TO'] = [
411 'id' => 'ACTIVE_TO',
412 'type' => 'date',
413 'operators' => [
414 'default' => '=',
415 'range' => '><'
416 ]
417 ];
418
419 if ($this->catalogIncluded)
420 {
421 $result['TYPE'] = [
422 'id' => 'TYPE',
423 'type' => 'list',
424 'operators' => [
425 'default' => '='
426 ],
427 'params' => ['multiple' => 'Y']
428 ];
429 $result['BUNDLE'] = [
430 'id' => 'BUNDLE',
431 'type' => 'list',
432 'operators' => [
433 'default' => '='
434 ]
435 ];
436 $result['AVAILABLE'] = [
437 'id' => 'AVAILABLE',
438 'type' => 'list',
439 'operators' => [
440 'default' => '='
441 ]
442 ];
443 }
444 if ($this->iblockId > 0)
445 {
446 $properties = $this->getFilterProductPropertiesDescription();
447 if (!empty($properties))
448 $result = array_merge($result, $properties);
449 $properties = $this->getFilterOfferPropertiesDescription();
450 if (!empty($properties))
451 $result = array_merge($result, $properties);
452 unset($properties);
453 }
454
455 return $result;
456 }
457
458 private static function getFilterPropertiesDescription(array $filter)
459 {
460 $result = [];
461
462 $operators = [
463 Iblock\PropertyTable::TYPE_STRING => [
464 'default' => '?',
465 'quickSearch' => '?'
466 ],
467 Iblock\PropertyTable::TYPE_NUMBER => [
468 'default' => '=',
469 'exact' => '=',
470 'range' => '><',
471 'more' => '>',
472 'less' => '<'
473 ],
474 Iblock\PropertyTable::TYPE_LIST => [
475 'default' => '='
476 ],
477 Iblock\PropertyTable::TYPE_ELEMENT => [
478 'default' => '='
479 ],
480 Iblock\PropertyTable::TYPE_SECTION => [
481 'default' => '='
482 ]
483 ];
484
485 $iterator = Iblock\PropertyTable::getList([
486 'select' => [
487 'ID', 'IBLOCK_ID', 'NAME', 'SORT', 'PROPERTY_TYPE',
488 'MULTIPLE', 'LINK_IBLOCK_ID', 'FILTRABLE', 'VERSION',
489 'USER_TYPE', 'USER_TYPE_SETTINGS_LIST'
490 ],
491 'filter' => $filter,
492 'order' => ['SORT' => 'ASC', 'NAME' => 'ASC']
493 ]);
494 while ($row = $iterator->fetch())
495 {
496 $row['USER_TYPE'] = (string)$row['USER_TYPE'];
497 $row['PROPERTY_USER_TYPE'] = ($row['USER_TYPE'] !== '' ? \CIBlockProperty::GetUserType($row['USER_TYPE']) : []);
498 $row['USER_TYPE_SETTINGS'] = $row['USER_TYPE_SETTINGS_LIST'];
499 unset($row['USER_TYPE_SETTINGS_LIST']);
500
501 $field = null;
502 $id = 'PROPERTY_'.$row['ID'];
503 $row['USER_TYPE'] = (string)$row['USER_TYPE'];
504 $type = $row['PROPERTY_TYPE'];
505 $settings = $row['USER_TYPE_SETTINGS'];
506 if (
507 $row['USER_TYPE'] !== ''
508 && !empty($settings)
509 && is_array($settings)
510 )
511 {
512 $row['PROPERTY_USER_TYPE'] = \CIBlockProperty::GetUserType($row['USER_TYPE']);
513 if (
514 isset($row['PROPERTY_USER_TYPE']['GetUIFilterProperty'])
515 && is_callable($row['PROPERTY_USER_TYPE']['GetUIFilterProperty'])
516 )
517 {
518 $type = 'USER_TYPE';
519 }
520 }
521 switch ($type)
522 {
523 case 'USER_TYPE':
524 $field = [
525 'type' => 'custom',
526 'value' => ''
527 ];
528 if (isset($operators[$row['PROPERTY_TYPE']]))
529 $field['operators'] = $operators[$row['PROPERTY_TYPE']];
530 call_user_func_array(
531 $row['PROPERTY_USER_TYPE']['GetUIFilterProperty'],
532 [
533 $row,
534 ['VALUE' => $id, 'FORM_NAME' => 'main-ui-filter'],
535 &$field
536 ]
537 );
538 break;
539 case Iblock\PropertyTable::TYPE_STRING:
540 $field = [
541 'type' => 'string',
542 'operators' => $operators[Iblock\PropertyTable::TYPE_STRING],
543 ];
544 break;
545 case Iblock\PropertyTable::TYPE_NUMBER:
546 $field = [
547 'type' => 'number',
548 'operators' => $operators[Iblock\PropertyTable::TYPE_NUMBER]
549 ];
550 break;
551 case Iblock\PropertyTable::TYPE_LIST:
552 $field = [
553 'type' => 'list',
554 'operators' => $operators[Iblock\PropertyTable::TYPE_LIST]
555 ];
556 break;
557 case Iblock\PropertyTable::TYPE_ELEMENT:
558 $field = [
559 'type' => 'list',
560 'operators' => $operators[Iblock\PropertyTable::TYPE_ELEMENT]
561 ];
562 break;
563 case Iblock\PropertyTable::TYPE_SECTION:
564 $field = [
565 'type' => 'list',
566 'operators' => $operators[Iblock\PropertyTable::TYPE_SECTION]
567 ];
568 break;
569 }
570
571 if (!empty($field))
572 {
573 $field['id'] = $id;
574 $result[$id] = $field;
575 }
576 }
577 unset($row, $iterator);
578
579 return $result;
580 }
581
582 private function getFilterProductPropertiesDescription()
583 {
584 return self::getFilterPropertiesDescription([
585 '=IBLOCK_ID' => $this->iblockId,
586 '=ACTIVE' => 'Y',
587 '=FILTRABLE' => 'Y',
588 '!=PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_FILE
589 ]);
590 }
591
592 private function getFilterOfferPropertiesDescription()
593 {
594 $result = [];
595 if (!empty($this->catalog))
596 {
597 $result = self::getFilterPropertiesDescription([
598 '=IBLOCK_ID' => $this->catalog['IBLOCK_ID'],
599 '!=ID' => $this->catalog['SKU_PROPERTY_ID'],
600 '=ACTIVE' => 'Y',
601 '=FILTRABLE' => 'Y',
602 '!=PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_FILE
603 ]);
604 if (!empty($result))
605 {
606 foreach (array_keys($result) as $index)
607 $result[$index]['entity'] = 'offer';
608 unset($index);
609 }
610 }
611 return $result;
612 }
613
618 private function getElementsInternal(array $settings)
619 {
620 $result = [];
621
622 $iterator = \CIBlockElement::GetList(
623 $settings['order'],
624 $settings['filter'],
625 false,
626 ($settings['limit'] > 0 ? ['nTopCount' => $settings['limit']] : false),
627 $settings['element']
628 );
629 if (!empty($settings['templates']['detailPageUrl']))
630 $iterator->SetUrlTemplates($settings['templates']['detailPageUrl']);
631
632 $needPreview = in_array('PREVIEW_PICTURE', $settings['element']);
633 $needDetailPicture = in_array('DETAIL_PICTURE', $settings['element']);
634
635 $loadSeo = ($needPreview || $needDetailPicture || $settings['loadSeo']);
636
637 if (!empty($settings['element_properties']))
638 {
639 $settings['element_properties'] = $this->getAllowedPropertyId(
640 $settings['filter']['IBLOCK_ID'],
641 $settings['element_properties'],
642 ($settings['mode'] == 'list'
643 ? Iblock\Model\PropertyFeature::FEATURE_ID_LIST_PAGE_SHOW
644 : Iblock\Model\PropertyFeature::FEATURE_ID_DETAIL_PAGE_SHOW
645 )
646 );
647 }
648
649 while ($row = $iterator->GetNext())
650 {
651 $id = (int)$row['ID'];
652 if ($loadSeo)
653 {
654 Iblock\InheritedProperty\ElementValues::queue($row['IBLOCK_ID'], $row['ID']);
655 }
656
657 $row['PROPERTIES'] = [];
658
659 $result[$id] = $row;
660 }
661 unset($row, $iterator);
662
663 if (!empty($result))
664 {
665 $needDiscountCache = false;
666 if ($this->catalogIncluded && $settings['prices'])
667 {
668 $needDiscountCache = \CIBlockPriceTools::SetCatalogDiscountCache(
669 $this->getPriceTypes(),
670 $this->getUserGroups()
671 );
672 }
673 $loadProperties = (!empty($settings['element_properties']) || $needDiscountCache);
674 if ($loadProperties)
675 {
676 $propertyFilter = [];
677 if (!$needDiscountCache)
678 {
679 $propertyFilter = ['ID' => $settings['element_properties']];
680 }
681
682 \CIBlockElement::GetPropertyValuesArray(
683 $result,
684 $settings['filter']['IBLOCK_ID'],
685 ['ID' => array_keys($result)],
686 $propertyFilter,
687 ['USE_PROPERTY_ID' => 'Y']
688 );
689 unset($propertyFilter);
690 }
691 if ($needDiscountCache)
692 {
693 $elementIds = array_keys($result);
694 foreach ($elementIds as $itemId)
695 {
696 \CCatalogDiscount::SetProductPropertiesCache($itemId, $result[$itemId]['PROPERTIES']);
697 }
698 Catalog\Discount\DiscountManager::preloadPriceData($elementIds, $this->getPriceTypes());
699 Catalog\Discount\DiscountManager::preloadProductDataToExtendOrder($elementIds, $this->getUserGroups());
700 \CCatalogDiscount::SetProductSectionsCache($elementIds);
701 }
702
703 foreach ($result as &$row)
704 {
705 if ($loadSeo)
706 {
707 $ipropValues = new Iblock\InheritedProperty\ElementValues($row['IBLOCK_ID'], $row['ID']);
708 $row['IPROPERTY_VALUES'] = $ipropValues->getValues();
709 }
710 if ($needPreview || $needDetailPicture)
711 {
712 Iblock\Component\Tools::getFieldImageData(
713 $row,
714 ['PREVIEW_PICTURE', 'DETAIL_PICTURE'],
715 Iblock\Component\Tools::IPROPERTY_ENTITY_ELEMENT,
716 'IPROPERTY_VALUES'
717 );
718 if ($needPreview)
719 {
720 if (!empty($row['PREVIEW_PICTURE']))
721 {
722 $row['PREVIEW_PICTURE'] = [
723 'src' => $row['PREVIEW_PICTURE']['SRC'],
724 'alt' => $row['PREVIEW_PICTURE']['ALT'],
725 ];
726 }
727 }
728 if ($needDetailPicture)
729 {
730 if (!empty($row['DETAIL_PICTURE']))
731 {
732 $row['DETAIL_PICTURE'] = [
733 'src' => $row['DETAIL_PICTURE']['SRC'],
734 'alt' => $row['DETAIL_PICTURE']['ALT'],
735 ];
736 }
737 }
738 }
739
740 if (!empty($settings['element_properties']))
741 {
742 foreach ($settings['element_properties'] as $propertyId)
743 {
744 $row['PROPERTY_'.$propertyId] = null;
745 if (isset($row['PROPERTIES'][$propertyId]))
746 {
747 $row['PROPERTY_'.$propertyId] = self::getPropertyValue($row['PROPERTIES'][$propertyId]);
748 }
749 }
750 unset($propertyId);
751 }
752 unset($row['PROPERTIES']);
753
754 if ($settings['prices'])
755 {
756 $row['PRICE'] = null;
757 $row['SORT_ORDER'] = null;
758 }
759
760 if ($settings['loadSeo'])
761 {
762 $this->fillElementSeo($row);
763 }
764
765 if ($loadSeo)
766 {
767 unset($row['IPROPERTY_VALUES']);
768 unset($ipropValues);
769 }
770 }
771 unset($row);
772
773 if ($this->catalogIncluded)
774 {
775 if (!empty($settings['product']))
776 {
777 self::loadProduct($result, $settings['product']);
778 }
779
780 if ($settings['prices'])
781 {
782 $this->loadPrices($result);
783 if (!empty($settings['sortByPrice']))
784 {
785 $sortPrice = mb_strtoupper($settings['sortByPrice']);
786 $sortPrice = ($sortPrice === 'ASC' ? SORT_ASC : SORT_DESC);
787 Main\Type\Collection::sortByColumn($result, ['SORT_ORDER' => $sortPrice]);
788 }
789 foreach ($result as &$item)
790 {
791 unset($item['SORT_ORDER']);
792 }
793 }
794 if ($needDiscountCache)
795 {
796 \CCatalogDiscount::ClearDiscountCache(array(
797 'PRODUCT' => true,
798 'SECTIONS' => true,
799 'PROPERTIES' => true
800 ));
801 }
802 }
803 }
804
805 return $result;
806 }
807
812 private static function getPropertyValue(array $property)
813 {
814 $result = null;
815
816 $multiValue = is_array($property['VALUE']);
817 if (
818 ($multiValue && !empty($property['VALUE'])) ||
819 (!$multiValue && (string)$property['VALUE'] !== '')
820 )
821 {
822 if ($property['PROPERTY_TYPE'] == Iblock\PropertyTable::TYPE_FILE)
823 {
824 if ($multiValue)
825 {
826 foreach ($property['VALUE'] as $value)
827 {
828 $file = \CFile::GetFileArray($value);
829 if (!empty($file))
830 {
831 $result = [
832 'src' => $file['SRC'],
833 'alt' => ''
834 ];
835 break;
836 }
837 }
838 }
839 else
840 {
841 $file = \CFile::GetFileArray($property['VALUE']);
842 if (!empty($file))
843 {
844 $result = [
845 'src' => $file['SRC'],
846 'alt' => ''
847 ];
848 }
849 }
850 }
851 else
852 {
853 $result = \CIBlockFormatProperties::GetDisplayValue(['NAME' => ''], $property, '');
854
855 if (empty($result))
856 {
857 $result = null;
858 }
859 elseif (is_array($result))
860 {
861 if (empty($result['DISPLAY_VALUE']))
862 $result = null;
863 elseif (is_array($result['DISPLAY_VALUE']))
864 $result = implode(', ', $result['DISPLAY_VALUE']);
865 else
866 $result = $result['DISPLAY_VALUE'];
867 }
868 }
869 }
870
871 return $result;
872 }
873
874 private static function loadProduct(array &$result, array $fields)
875 {
876 $select = ['ID'];
877 $descr = [];
878
879 foreach ($fields as $index => $item)
880 {
881 if (is_array($item))
882 {
883 if (isset($item['COMPILE']))
884 {
885 $select = array_merge($select, $item['COMPILE']['FIELDS']);
886 }
887 else
888 {
889 $select[] = $item['ID'];
890 }
891 $descr[$index] = $item;
892 }
893 elseif (is_bool($item))
894 {
895 $select[] = $index;
896 $descr[$index] = ['ID' => $index];
897 }
898 }
899
900 $iterator = Catalog\ProductTable::getList([
901 'select' => $select,
902 'filter' => ['@ID' => array_keys($result)]
903 ]);
904 while ($row = $iterator->fetch())
905 {
906 $id = (int)$row['ID'];
907 foreach ($descr as $item)
908 {
909 $fieldId = $item['ID'];
910 $result[$id][$fieldId] = null;
911 if (isset($item['COMPILE']))
912 {
913 $value = [];
914 foreach ($item['COMPILE']['FIELDS'] as $index)
915 {
916 if ($row[$index] === null)
917 continue;
918 $value[] = $row[$index];
919 }
920 if (!empty($value))
921 $result[$id][$fieldId] = implode($item['COMPILE']['SEPARATOR'], $value);
922 }
923 else
924 {
925 if ($fieldId == 'AVAILABLE')
926 $row[$fieldId] = ($row[$fieldId] == 'Y'
927 ? Loc::getMessage('PRODUCT_FIELD_STATUS_YES')
928 : Loc::getMessage('PRODUCT_FIELD_STATUS_NO')
929 );
930 $result[$id][$fieldId] = $row[$fieldId];
931 }
932 }
933 }
934 unset($row, $iterator);
935 }
936
937 private function loadPrices(array &$result)
938 {
939 $priceTypes = $this->getPriceTypes();
940 if (!empty($priceTypes))
941 {
942 $productIds = array_keys($result);
943 $prices = [];
944 $priceFilter = [
945 '@PRODUCT_ID' => array_keys($result),
946 '@CATALOG_GROUP_ID' => $priceTypes,
947 [
948 'LOGIC' => 'OR',
949 '<=QUANTITY_FROM' => 1,
950 '=QUANTITY_FROM' => null
951 ],
952 [
953 'LOGIC' => 'OR',
954 '>=QUANTITY_TO' => 1,
955 '=QUANTITY_TO' => null
956 ]
957 ];
958
959 $iterator = Catalog\PriceTable::getList([
960 'select' => ['ID', 'PRODUCT_ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY'],
961 'filter' => $priceFilter
962 ]);
963
964 while ($price = $iterator->fetch())
965 {
966 $id = (int)$price['PRODUCT_ID'];
967 $priceTypeId = (int)$price['CATALOG_GROUP_ID'];
968 $prices[$id][$priceTypeId] = $price;
969 unset($priceTypeId, $id);
970 }
971 unset($price, $iterator);
972
973 $calculationConfig = [
974 'CURRENCY' => Currency\CurrencyManager::getBaseCurrency(),
975 'USE_DISCOUNTS' => true,
976 'RESULT_WITH_VAT' => true,
977 'RESULT_MODE' => Catalog\Product\Price\Calculation::RESULT_MODE_COMPONENT
978 ];
979
980 if ($this->saleIncluded)
981 {
982 $saleDiscountOnly = (string)Main\Config\Option::get('sale', 'use_sale_discount_only') == 'Y';
983 if ($saleDiscountOnly)
984 $calculationConfig['PRECISION'] = (int)Main\Config\Option::get('sale', 'value_precision');
985 }
986 Catalog\Product\Price\Calculation::pushConfig();
987 Catalog\Product\Price\Calculation::setConfig($calculationConfig);
988 unset($calculationConfig);
989
990 foreach ($productIds as $id)
991 {
992 $minimalPrice = \CCatalogProduct::GetOptimalPrice(
993 $id,
994 1,
995 [2],
996 'N',
997 $prices[$id],
998 false,
999 []
1000 );
1001 $result[$id]['SORT_ORDER'] = 0;
1002 if (!empty($minimalPrice))
1003 {
1004 $minimalPrice = $minimalPrice['RESULT_PRICE'];
1005 $result[$id]['PRICE'] = \CCurrencyLang::CurrencyFormat(
1006 $minimalPrice['DISCOUNT_PRICE'],
1007 $minimalPrice['CURRENCY'],
1008 true
1009 );
1010 if ($minimalPrice['BASE_PRICE'] > $minimalPrice['DISCOUNT_PRICE'])
1011 {
1012 $result[$id]['PRICE'] .= ' <span style="text-decoration: line-through;">'.
1013 \CCurrencyLang::CurrencyFormat(
1014 $minimalPrice['BASE_PRICE'],
1015 $minimalPrice['CURRENCY'],
1016 true
1017 ).
1018 '</span>';
1019 }
1020 $result[$id]['SORT_ORDER'] = $minimalPrice['DISCOUNT_PRICE'];
1021 }
1022 unset($minimalPrice);
1023 }
1024
1025 Catalog\Product\Price\Calculation::popConfig();
1026 }
1027 unset($priceTypes);
1028 }
1029
1030 private function fillElementSeo(array &$row)
1031 {
1032 $iproperty = (!empty($row['IPROPERTY_VALUES']) ? $row['IPROPERTY_VALUES'] : []);
1033 $row['SEO_PROPERTIES'] = [
1034 Source\Seo::TITLE => [isset($iproperty['ELEMENT_PAGE_TITLE']) && $iproperty['ELEMENT_PAGE_TITLE'] != ''
1035 ? $iproperty['ELEMENT_PAGE_TITLE']
1036 : $row['NAME']
1037 ],
1038 ];
1039
1040 if (!empty($iproperty))
1041 {
1042 $entity = [
1043 Source\Seo::BROWSER_TITLE => 'ELEMENT_META_TITLE',
1044 Source\Seo::KEYWORDS => 'ELEMENT_META_KEYWORDS',
1045 Source\Seo::DESCRIPTION => 'ELEMENT_META_DESCRIPTION'
1046 ];
1047
1048 foreach ($entity as $seoItem => $meta)
1049 {
1050 if (!empty($iproperty[$meta]))
1051 {
1052 $row['SEO_PROPERTIES'][$seoItem] = $iproperty[$meta];
1053 if (is_array($row['SEO_PROPERTIES'][$seoItem]))
1054 {
1055 $row['SEO_PROPERTIES'][$seoItem] = implode(' ', $row['SEO_PROPERTIES'][$seoItem]);
1056 }
1057 }
1058 }
1059 unset($entity, $seoItem, $meta);
1060 }
1061 unset($iproperty);
1062 }
1063
1070 private function getAllowedPropertyId($iblockId, array $propertyIds, $mode)
1071 {
1072 $list = null;
1073 switch ($mode)
1074 {
1075 case Iblock\Model\PropertyFeature::FEATURE_ID_LIST_PAGE_SHOW:
1076 $list = Iblock\Model\PropertyFeature::getListPageShowPropertyCodes($iblockId);
1077 break;
1078 case Iblock\Model\PropertyFeature::FEATURE_ID_DETAIL_PAGE_SHOW:
1079 $list = Iblock\Model\PropertyFeature::getDetailPageShowPropertyCodes($iblockId);
1080 break;
1081 }
1082 if (empty($list))
1083 {
1084 return [];
1085 }
1086
1087 $result = array_intersect_key(
1088 array_fill_keys($propertyIds, true),
1089 array_fill_keys($list, true)
1090 );
1091
1092 return (!empty($result) ? array_keys($result) : []);
1093 }
1094
1100 protected function getUserGroups()
1101 {
1103 global $USER;
1104 $result = [2];
1105 if (isset($USER) && $USER instanceof \CUser)
1106 {
1107 $result = $USER->GetUserGroupArray();
1108 Main\Type\Collection::normalizeArrayValuesByInt($result, true);
1109 }
1110 return $result;
1111 }
1112
1116 protected function getPriceTypes()
1117 {
1118 if ($this->priceTypes === null)
1119 {
1120 $this->priceTypes = [];
1121 $iterator = Catalog\GroupAccessTable::getList([
1122 'select' => ['CATALOG_GROUP_ID'],
1123 'filter' => ['=GROUP_ID' => 2]
1124 ]);
1125 while ($row = $iterator->fetch())
1126 {
1127 $id = (int)$row['CATALOG_GROUP_ID'];
1128 $this->priceTypes[$id] = $id;
1129 }
1130 unset($row, $iterator);
1131 }
1132 return $this->priceTypes;
1133 }
1134 }
1135}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29