Answer the question
In order to leave comments, you need to log in
Why doesn't the OnStartIBlockElementUpdate event change the value of the property?
I want to change the value of the property depending on the value of the property that comes with 1C, at the time of changing the product. To do this, I use the OnStartIBlockElementUpdate event, and for some reason the value changes after the second save, as if it stores the old value and writes it down, and only after the second save saves the desired value.
How to track and how to fix this behavior?
<?
define('CATALOG_IBLOCK_ID', 9);
// Событие при изменении товара в инфоблоке меняет активность в зависимости от значения активности, которое пришло с 1С
AddEventHandler("iblock", "OnStartIBlockElementUpdate", Array("CIBLockHandler", "ChangePropertyActive"));
class CIBLockHandler
{
function ChangePropertyActive(&$arFields)
{
if($arFields['IBLOCK_ID']==CATALOG_IBLOCK_ID){
$db_props = CIBlockElement::GetProperty($arFields['IBLOCK_ID'], $arFields['ID'], array("sort"=>"asc"), array("CODE"=>"AKTIVNOST") );
if($ar_props = $db_props->Fetch()){
$el = new CIBlockElement;
if($ar_props['VALUE_XML_ID']=='true'){
$arFields['ACTIVE'] = 'Y';
}
else
{
$arFields['ACTIVE'] = 'N';
}
}
}
}
}?>
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