/
BitrixShow
/
Sections-Items
Обзор
Документация
Войти
/
BitrixShow
/
Sections-Items
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
components/bitrix/catalog.section/section/result_modifier.php
127 строк
6 KB
BitrixShow
create components/bitrix/catalog.section/section/result_modifier.php
10 апр 2025, 17:57
10 апр 2025, 17:57
fd6feca
Код
Авторство
О чём код?
<? if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die(); /** * @var CBitrixComponentTemplate $this * @var CatalogSectionComponent $component */ $component = $this->getComponent(); $arParams = $component->applyTemplateModifications(); $arProductBrandSectionId = []; if($arParams['BRAND'] == 'neon-night') $arParams['BRAND'] = str_replace('-', '_', $arParams['BRAND']); /* Собираем id категорий в товарах */ $arSelectProductBrand = Array("ID", "IBLOCK_SECTION_ID", "DEPTH_LEVEL"); $arFilterProductBrand = Array("IBLOCK_ID"=> 10, "ACTIVE"=>"Y", "PROPERTY_BRAND_LOGO" => $arParams["BRAND"]); $resProductBrand = CIBlockElement::GetList(Array(), $arFilterProductBrand, false, false, $arSelectProductBrand); while($obProductBrand = $resProductBrand->GetNextElement()) { $arFieldsProductBrand = $obProductBrand->GetFields(); $arProductBrandSectionId[] = $arFieldsProductBrand["IBLOCK_SECTION_ID"]; } /* Чистим массив от дублей */ $arProductBrandSectionIdUnique = array_unique($arProductBrandSectionId); /* Считаем кол-во элементов в массиве по id-категории */ $arProductBrandSectionIdCount = array_count_values($arProductBrandSectionId); //pre($arProductBrandSectionIdUnique); $brand = mb_strtolower($arParams['BRAND']); if($arParams['ELEMENT_BRAND'] == 'neon-night') $arParams['ELEMENT_BRAND'] = str_replace('-', '_', $arParams['ELEMENT_BRAND']); $brand_code = mb_strtolower($arParams['ELEMENT_BRAND']) ?? $brand; $IdSectionsLevelThree = [];// ID 3 уровня $IdSectionsLevelTwoISThree = [];// ID 2 уровня полученные из 3 уровня $IdSectionsLevelTwo = [];// ID 2 уровня из переменной $arSection $allSections = [];// ID всех уровней с их количеством /* Перебрал массив $arSection*/ foreach($arProductBrandSectionIdUnique as $catId){ $resSection = CIBlockSection::GetByID($catId); if($arSection = $resSection->GetNext()) if(empty($arProductBrandSectionIdCount[$catId])){ $count = 1; }else{ $count = $arProductBrandSectionIdCount[$catId]; } $arSection["SECTION_PAGE_URL"] .= 'filter/brand-is-'.$brand_code.'/apply/'; $arSection['COUNT'] = $count; if($arSection['DEPTH_LEVEL'] == '3'){ $ThreeSectionLevel[$arSection['ID']] = $arSection; } /* Перербираем третий уровень и получаем разделы второго уровня */ foreach ($ThreeSectionLevel as $key => $arTwoSection) { $resTwoSection = CIBlockSection::GetByID($arTwoSection['IBLOCK_SECTION_ID']); if($arTwoSection = $resTwoSection->GetNext()) $arTwoSection["SECTION_PAGE_URL"] .= 'filter/brand-is-'.$brand_code.'/apply/'; $IdSectionsLevelTwoISThree[$arTwoSection['ID']] = array_unique($arTwoSection); } if($arSection['DEPTH_LEVEL'] == '2') { $IdSectionsLevelTwo[$arSection['ID']] = $arSection; } $allSections[] = $arSection; } /* Перебрал второй уровень из третьего в первый */ foreach ($IdSectionsLevelTwoISThree as $key => $arIdSectionsLevelTwo) { foreach ($allSections as $Sections) { if ($arIdSectionsLevelTwo['ID'] == $Sections['IBLOCK_SECTION_ID']) { if (/*isset($IdSectionsLevelTwoISThree[$key]['COUNT']) && */isset($Sections['COUNT'])) { $IdSectionsLevelTwoISThree[$key]['COUNT'] += $Sections['COUNT']; } } } $resIdSectionsLevelTwo = CIBlockSection::GetByID($arIdSectionsLevelTwo['IBLOCK_SECTION_ID']); if($arResIdSectionsLevelTwo = $resIdSectionsLevelTwo->GetNext()) $LeftSection[$arResIdSectionsLevelTwo['ID']] = $arResIdSectionsLevelTwo; } /* Перебрал второй уровень в первый */ foreach ($IdSectionsLevelTwo as $key2 => $arIdSectionsLevelTwo) { foreach ($allSections as $Sections) { if ($arIdSectionsLevelTwo['ID'] == $Sections['IBLOCK_SECTION_ID']) { $IdSectionsLevelTwo[$key2]['COUNT'] += $Sections['COUNT']; } } $resIdSectionsLevelTwo = CIBlockSection::GetByID($arIdSectionsLevelTwo['IBLOCK_SECTION_ID']); if($arResIdSectionsLevelTwo = $resIdSectionsLevelTwo->GetNext()) $LeftSection[$arResIdSectionsLevelTwo['ID']] = $arResIdSectionsLevelTwo; } /* Сливаю второй уровень в первый */ foreach ($LeftSection as $key3 => $ItemLeftSection) { foreach ($IdSectionsLevelTwoISThree as $key => $SectionsTwoThree){ if($ItemLeftSection['ID'] == $SectionsTwoThree['IBLOCK_SECTION_ID']){ if(($SectionsTwoThree["ID"] != '277') && ($SectionsTwoThree["ID"] != '244')){ $LeftSection[$key3]['CHILD'][] = $SectionsTwoThree; $LeftSection[$key3]['COUNT'][$SectionsTwoThree['ID']] = $SectionsTwoThree['COUNT']; } } } foreach ($IdSectionsLevelTwo as $key2 => $SectionsTwo) { if($ItemLeftSection['ID'] == $SectionsTwo['IBLOCK_SECTION_ID']){ $LeftSection[$key3]['CHILD'][] = $SectionsTwo; $LeftSection[$key3]['COUNT'][$SectionsTwo['ID']] = $SectionsTwo['COUNT']; } } } foreach ($LeftSection as $key => $Section){ foreach ($Section['COUNT'] as $key2 => $SectionCount){ if (isset($LeftSection[$key]['SUM'])) { $LeftSection[$key]['SUM'] += $SectionCount; } } } $arResult['GROUP_SECTIONS'] = $LeftSection; usort($arResult['GROUP_SECTIONS'], function($a, $b) { return $a['SORT'] <=> $b['SORT']; }); foreach($arResult['GROUP_SECTIONS'] as $key => &$arItem){ usort($arItem['CHILD'], function($a, $b) { return $a['SORT'] <=> $b['SORT']; }); } unset($sectionLinc);