Answer the question
In order to leave comments, you need to log in
How to change the coefficient of unit of measure for a product in the OnAfterIBlockElementUpdate event handler?
I'm trying to change the unit factor in the OnAfterIBlockElementUpdate event handler .
But the value remains the same .
AddEventHandler("iblock", "OnAfterIBlockElementUpdate", "HandlerAfterIBlockElementUpdate");
function HandlerAfterIBlockElementUpdate(&$arFields)
{
//новый коэффициент
$newCoeff = 40;//например
CModule::IncludeModule("iblock");
CModule::IncludeModule("catalog");
CModule::IncludeModule("sale");
$iBlockId = 4;//ИБ
//получаем коэффициент этого товара для изменения
$curElementRatio = CCatalogMeasureRatio::getList(
Array(),
array('IBLOCK_ID' => $iBlockId, 'PRODUCT_ID' => $arFields['ID']),
false, false);
while ($arRatio = $curElementRatio->GetNext()) {
$ratioId = $arRatio['ID'];
$arFieldsNew = Array(
'PRODUCT_ID' => $arFields['ID'],
'RATIO' => $newCoeff,
);
//изменяем кэффициент
CCatalogMeasureRatio::update($ratioId, $arFieldsNew);
}
}
Answer the question
In order to leave comments, you need to log in
As I expected, the result of the action of the OnAfterIBlockElementUpdate event handler is overwritten.
As a result, the OnPriceUpdate price change event handler became the solution (since this event fires at the very end).
AddEventHandler("catalog", "OnPriceUpdate", "HandlerOnPriceUpdate");
function HandlerOnPriceUpdate($ID,&$arFields)
{
$element = $arFields['PRODUCT_ID']; //ID товара
$iblockId = 4;
$coeff= 100; //например
$curElementRatio = CCatalogMeasureRatio::getList(
Array(),
array('IBLOCK_ID' => $iblockId, 'PRODUCT_ID' => $element ),
false, false);
while ($arRatio = $curElementRatio->GetNext()) {
$ratioId = $arRatio['ID'];
$arFieldsNew = Array(
'RATIO' => $coeff,
);
CCatalogMeasureRatio::update($ratioId, $arFieldsNew);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question