Answer the question
In order to leave comments, you need to log in
How to bind an infoblock element to another section when it is changed?
Hello.
When I change an element, I'm trying to make it automatically bind in addition to one more section.
I can't figure out what's wrong, please tell me:
AddEventHandler("iblock", "OnAfterIBlockElementUpdate", Array("AddToSection", "OnAfterIBlockElementUpdateHandler"));
class AddToSection
{
public static $disableHandler = false;
function OnAfterIBlockElementUpdateHandler(&$arFields)
{
if (self::$disableHandler)
return;
CModule::IncludeModule("iblock");
if( $arFields["ID"] > 0 && $arFields["IBLOCK_ID"] == "21")
{
$el = new CIBlockElement;
$arSections = array();
if(in_array("104", $arFields["IBLOCK_SECTION"], true))
{
file_put_contents("/home/bitrix/www/bitrix/php_interface/log.txt", "Товар уже находится в папке 104");
}
else
{
$arSections = array_push($arFields["IBLOCK_SECTION"], "104");
$arLoadProductArray = Array(
"IBLOCK_SECTION" => $arSections,
);
self::$disableHandler = true;
$res = $el->Update($arFields["ID"], $arLoadProductArray);
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question