B
B
BarneyGumble2020-10-08 11:09:59
1C-Bitrix
BarneyGumble, 2020-10-08 11:09:59

How to get all subsections of an infoblock in Bitrix, including nested ones?

There is such a section tree

DmBLBVZSJ1jvnA.png

. The task is to get an array of names of all subsections of the "Tools and Equipment" section.

I do this:


$sections = CIBlockSection::GetList (
        Array("ID" => "ASC"),
        Array("IBLOCK_ID" => 1, "ACTIVE" => "Y", "SECTION_ID" => 10),
        false,
        Array('ID', 'NAME', 'CODE')
    );

    while($ar_fields = $sections->GetNext())
    {
        $sub_sections[] = $ar_fields['NAME'];
    }

    print_r($sub_sections);


As a result, I get 3 subsections of the "Tools and equipment" section:
Mechanical tools
Hand electromechanical tools
Hydraulic tools and accessories


And it was expected to receive 12 sections including subsections of these 3

How to get all subsections, including nested ones?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yaroslav Alexandrov, 2020-10-08
@BarneyGumble

Why didn't the example from the documentation fit?
https://dev.1c-bitrix.ru/api_help/iblock/classes/c...

<?
$rsParentSection = CIBlockSection::GetByID(1);
if ($arParentSection = $rsParentSection->GetNext())
{
   $arFilter = array('IBLOCK_ID' => 2,'>LEFT_MARGIN' => $arParentSection['LEFT_MARGIN'],'<RIGHT_MARGIN' => $arParentSection['RIGHT_MARGIN'],'>DEPTH_LEVEL' => $arParentSection['DEPTH_LEVEL']); // выберет потомков без учета активности
   $rsSect = CIBlockSection::GetList(array('left_margin' => 'asc'),$arFilter);
   while ($arSect = $rsSect->GetNext())
   {
       $arTest[] = $arSect;// получаем подразделы
   }
}
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question