AddEventHandler("iblock", "OnAfterIBlockElementAdd", Array("OBEAClass", "OBEA")); // объявляем обработчики
AddEventHandler("iblock", "OnAfterIBlockElementUpdate", Array("OBEAClass", "OBEA"));
class OBEAClass
{
public static $disableHandler = false;
function OBEA(&$arFields)
{
if (self::$disableHandler)
return;
CModule::IncludeModule("iblock");
if( $arFields["ID"]> 0 && $arFields["IBLOCK_ID"] == "33") // ID основного каталога товаров
{
$el = new CIBlockElement;
foreach($arFields["PROPERTY_VALUES"] as $key=>$value)
{
if($key == "CML2_ARTICLE") // ID свойства Артикул (CML2_ARTICLE)
foreach($value as $key2=>$value2)
{
$arLoadProductArray = Array("CODE" => mb_strtolower($value2["VALUE"]));
}
}
self::$disableHandler = true; //отключаем
if($res = $el->Update($arFields["ID"], $arLoadProductArray))
{
}
if($res = $el->Add($arFields["ID"], $arLoadProductArray))
{
}
}
}
}
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);
}
<?
AddEventHandler("iblock", "OnAfterIBlockElementAdd", Array("OBEAClass", "OBEA")); // объявляем обработчики
AddEventHandler("iblock", "OnAfterIBlockElementUpdate", Array("OBEAClass", "OBEA"));
class OBEAClass
{
public static $disableHandler = false;
function OBEA(&$arFields)
{
if (self::$disableHandler){return;}
CModule::IncludeModule("iblock");
if( $arFields["ID"]> 0 && $arFields["IBLOCK_ID"] == "33") // ID основного каталога товаров
{
$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; //отключаем
}
}
}
?>