How to replace the character code of the element to the property article?

Good day! How to replace the character code of the element to the property article?

use code in the group

AddEventHandler("iblock", "OnAfterIBlockElementAdd", Array("OBEAClass", "OBEA")); // declare handlers 
AddEventHandler("iblock", "OnAfterIBlockElementUpdate", Array("OBEAClass", "OBEA"));
class OBEAClass
{
 public static $disableHandler = false;
 OBEA function(&$arFields)
 { 
 if (self::$disableHandler)
return;
CModule::IncludeModule("iblock");
 if( $arFields["ID"]> 0 && $arFields["IBLOCK_ID"] == "33") // ID of the basic catalog of products
{
 $el = new CIBlockElement;
 foreach($arFields["PROPERTY_VALUES"] as $key=>$value)
{
 if($key == "CML2_ARTICLE") // ID properties of the article (CML2_ARTICLE)
 foreach($value as $key2=>$value2)
{

 $arLoadProductArray = Array("CODE" => mb_strtolower($value2["VALUE"]));
}
}
 self::$disableHandler = true; //disable
 if($res = $el->Update($arFields["ID"], $arLoadProductArray))
{
}
 if($res = $el->Add($arFields["ID"], $arLoadProductArray))
{
}

}

}
}


But nothing happens, as was the character code in Latin, from the name, and nothing happened.
March 23rd 20 at 19:13
2 answers
March 23rd 20 at 19:15
Solution
Don't know how this code looks, good or bad, but I have worked only he. Short, simple and working

CModule::IncludeModule('iblock');
$IBLOCK_ID = 49;


 $elDB = CIBlockElement::GetList(
 array('SORT' => 'asc'),
 array('IBLOCK_ID'=> $IBLOCK_ID),
false,
false,
 array('ID', 'NAME', 'CODE', 'PROPERTY_CML2_ARTICLE')
);

 while($arEl = $elDB->GetNext(false, false))
{
 // echo '<pre>';
 // print_r($arEl);
 // echo '</pre>';
 $arParams = array("replace_space"=>"-","replace_other"=>"-");
 $trans = $arEl[PROPERTY_CML2_ARTICLE_VALUE];
 // echo '<pre>';
 // print_r($trans);
 // echo '</pre>';

 $el = new CIBlockElement;
 $arLoadProductArray = Array(
 'CODE' =>$trans
);
 $res = $el->Update($arEl['ID'], $arLoadProductArray);
 }
March 23rd 20 at 19:17
Try this:
<?
AddEventHandler("iblock", "OnAfterIBlockElementAdd", Array("OBEAClass", "OBEA")); // declare handlers 
AddEventHandler("iblock", "OnAfterIBlockElementUpdate", Array("OBEAClass", "OBEA"));
class OBEAClass 
{
 public static $disableHandler = false;
 OBEA function(&$arFields)
 { 
 if (self::$disableHandler){return;} 
CModule::IncludeModule("iblock");
 if( $arFields["ID"]> 0 && $arFields["IBLOCK_ID"] == "33") // ID of the basic catalog of products
{

 $db_props = CIBlockElement::GetProperty($arFields["IBLOCK_ID"], $arFields["ID"], Array("sort"=>"asc"), Array("CODE"=>"CML2_ARTICLE"));
 if($ar_props = $db_props->Fetch()){
 $arLoadProductArray = Array("CODE" => mb_strtolower($ar_props["VALUE"]));
 if($res = $el->Update($arFields["ID"], $arLoadProductArray)){

}
}
 self::$disableHandler = true; //disable
 } 
}
}
?>
what it also does not work.. neither the group nor from another file :( the character code of the component does not change. can remove transliteration in the settings of the information block? although then names it will be removed. writing should be replaced by the idea of the article... - morgan commented on March 23rd 20 at 19:20

Find more questions by tags 1C-Bitrix