A
A
Andrew Sky2015-02-02 17:13:27
1C-Bitrix
Andrew Sky, 2015-02-02 17:13:27

Bitrix catalog.section how to display sections and elements?

It is necessary to display the elements sorted by sections on one page.
For example: Section 1{Element1, Element2, Element3}, then on the same page below Section 2{Element1, element2, element3}, etc.
Through result_modifer I was able to get the section name for each element:
foreach ($arResult['ITEMS'] as $key => $arItem)
{
$arSectionList = array();
$rsSections = CIBlockElement::GetElementGroups($arItem['ID']);
while ($arSection = $rsSections->Fetch())
{
$arSectionList[] = array(
'ID' => $arSection['ID'],
'NAME' => $arSection['NAME'],
);
}
$arItem['SECTION_NAME'
$arResult['ITEMS'][$key] = $arItem;
}
Now I want to collect an array of the form Section 1{Element1, Element2, Element3}. Suggest a solution.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander, 2015-02-02
@Sky161

Request in a loop - ah-ah-ah, how bad.
And in general, right here for this solution:

foreach ($arResult['ITEMS'] as $key => $arItem) {
    $arSectionList = array();
    $rsSections = CIBlockElement::GetElementGroups($arItem['ID']);
    while ($arSection = $rsSections->Fetch())
    {
        $arSectionList[] = array(
                'ID' => $arSection['ID'],
                'NAME' => $arSection['NAME'],
            );
        $arResult['ITEMS_BY_GROUP'][$arSection['ID']][] = $key;
    }
    $arItem['SECTION_NAME'] = $arSectionList;
    $arResult['ITEMS'][$key] = $arItem;

}

And at the output you will get $arResult['ITEMS_BY_GROUP'] where the keys will be section IDs, and the values ​​will be arrays containing the keys of the ITEMS elements belonging to this section.
But if there are many elements, then this is it: CIBlockElement::GetElementGroups must be moved outside the loop.

R
Rad1calDreamer, 2015-02-03
@Rad1calDreamer

once stumbled across the open spaces. I took it for myself, sometimes I redo it)
https://github.com/Rad1calDreamer/bitrix.article.list
here is both a component and a base template

A
Alexey Emelyanov, 2015-02-02
@babarun

The easiest way, "on the forehead":
If the directory is small (<1000), then select all sections from the beginning.
Next, iterate over the resulting array of sections and for each section select all the elements belonging to it
- but there will be a huge number of extra requests. You can get by with two:
1. select all sections of CIBlockSection::GetTreeList()
2. select all elements of CIBlockElement::GetList()
3. combine two arrays into one.
If you mentioned result_modifer, then you are using some component, most likely it is either news.list or catalog.section. It's easier to write your own than to remake a finished one.

Z
ZardoZAntony, 2020-10-31
@ZardoZAntony

Does the bitrix:catalog.sections.top component do the wrong thing? We specify a number with a large margin for the top elements and that's it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question