A
A
Anumik2016-08-22 10:21:17
1C-Bitrix
Anumik, 2016-08-22 10:21:17

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);
      }
}

but for some reason it causes a 500 error
. I also tried this event:
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;
         }
      }
   }
}

but it didn't work at all

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Maksimenko, 2016-08-22
@Anumik

In the first case, you get a loop of handler calls.

S
Stanislav Harakhnin, 2016-08-23
@Chupokabr

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 question

Ask a Question

731 491 924 answers to any question