Answer the question
In order to leave comments, you need to log in
Why does the event in Bitrix not work?
Good afternoon
The task is to change the price when unloading, in init.php added such an event
AddEventHandler("catalog", "OnBeforePriceUpdate", array("MyClass", "OnBeforePriceUpdateHandler"));
class MyClass {
function OnBeforePriceUpdateHandler($PRICE_ID, $arFields)
{
$NewPrice = 5000;
$arPrice = array(
"PRODUCT_ID" => $arFields['PRODUCT_ID'],
"CATALOG_GROUP_ID" => 1,
"PRICE" => $NewPrice,
"CURRENCY" => "RUB"
);
CPrice::Update($PRICE_ID, $arPrice);
}
}
AddEventHandler("catalog", "OnBeforePriceUpdate", array("MyClass", "OnBeforePriceUpdateHandler"));
class MyClass
{
function OnBeforePriceUpdateHandler($PRICE_ID, $arFields)
{
$db_price = CPrice::GetList(
array(),
array(
"ID" => $PRICE_ID
)
);
if($ar_price = $db_price->Fetch())
{
if($ar_price['PRICE'] != $arFields['PRICE'])
{
$arFields['PRICE']=$arFields['PRICE']/100*110;
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Just change the value of the field and return that value.
OnBeforePriceUpdateHandler($PRICE_ID, & $arFields) - write in such a way that you get an array by reference and change its value, and not work in another instance.
Fix it and use the second option
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question