A
A
azesmhook2019-01-25 12:19:17
1C-Bitrix
azesmhook, 2019-01-25 12:19:17

How to programmatically assign the main section to the infoblock elements without resetting all the others?

On the site, the goods belong to several categories at the same time, and the task was to specify the root category as the main section. Tried through update (), specifying the desired section in the "IBLOCK_SECTION_ID" parameter, does not work, only the selected section remains, the rest of the bindings are reset. Has anyone faced such a task? How did they decide?5c4ad4ac34f53592148783.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2019-01-25
@azesmhook

If you look at the Add and Update methods of the CIblockElement class, the update is performed by the following code:

if(array_key_exists("IBLOCK_SECTION_ID", $arFields))
{
    if (!array_key_exists("IBLOCK_SECTION", $arFields))
    {
        $arFields["IBLOCK_SECTION"] = array($arFields["IBLOCK_SECTION_ID"]);
    }
    elseif (is_array($arFields["IBLOCK_SECTION"]) && !in_array($arFields["IBLOCK_SECTION_ID"], $arFields["IBLOCK_SECTION"]))
    {
        unset($arFields["IBLOCK_SECTION_ID"]);
    }
}

Thus, if you pass IBLOCK_SECTION_ID and do not pass an array of other sections - IBLOCK_SECTION, then they will be reset to zero.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question