Y
Y
Yuri Voronin2018-11-06 17:54:48
1C-Bitrix
Yuri Voronin, 2018-11-06 17:54:48

How to get the root section of an infoblock element?

Hello
There is an element ID. There are several levels of nesting in the infoblock. How to get the root folder ID of this element?
If we use CIBlockElement::GetByID($id) , then we get the folder in which this element is nested, and I need the parent of this folder.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Nikolaev, 2018-11-06
@yuraSco

CIblockElement receives an element, but not a section, and an element cannot be nested within an element - only within a section (not just one).
If you are interested in all root elements (i.e. elements that do not have a section to bind to), then you need to use CIblockElement::getList() and get all products with SECTION_ID = false, "" or 0. Read the documentation on this topic : https://dev.1c-bitrix.ru/api_help/iblock/classes/c...
If it turns out that you have 1 root section in the infoblock and you need to get its elements, then first you need to get it ID through CIblockSection::getList() and only then in SECTION_ID through CIblockelement::getList get all its elements (INCLUDE_SUBSECTIONS = N!). Read the documentation on this topic:https://dev.1c-bitrix.ru/api_help/iblock/classes/c...

R
Rustam, 2019-09-20
@htmaker

I recently encountered a similar problem, perhaps someone will find this solution useful:
How to get the root section of an infoblock element?

S
serginhold, 2018-11-06
@serginhold

There is an element ID. There are several levels of nesting in the infoblock. How to get the root folder ID of this element?

select 
    s.*
from b_iblock_section_element l
join b_iblock_section s
    on s.ID = l.IBLOCK_SECTION_ID
where
    l.IBLOCK_ELEMENT_ID = $id
    and s.DEPTH_LEVEL = 1

only here there can be several root sections, if the element has several of them,
in short, these are the basics of sql and the value of the infoblock architecture
(something similar has already been asked How to add products to the cart from only one parent category? )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question