I
I
Ilya17912022-03-23 16:56:47
1C-Bitrix
Ilya1791, 2022-03-23 16:56:47

How is an event triggered in Bitrix after changing or adding a price?

Implemented a functionality in which the discounted price writes the price of the discounted product into a separate property (this is necessary for the filter to work at discounted prices, it is the same for all products). Implemented through init.php handlers, found only OnPriceAdd and OnPriceUpdate. But then it turned out that these events are written to the property before the price is updated, that is, they are processed at the old price.

I tried an event of type OnAfterPriceUpdate, the same garbage - the property is overwritten at the old price. How to write a handler, tell me, please?

My code:

AddEventHandler("catalog", "OnPriceAdd", Array("SetPrice", "SetPriceHandler"));
AddEventHandler("catalog", "OnPriceUpdate", Array("SetPrice", "SetPriceHandler"));
CModule::IncludeModule('iblock');
CModule::IncludeModule('catalog');
CModule::IncludeModule('currency');

class SetPrice
{
    function SetPriceHandler(&$arFields)
    {
        $rsPrices = CPrice::GetList(
            array(),
            array(
                "PRODUCT_ID" => $arFields['ID'],
            )
        );
        while($arPrice = $rsPrices->Fetch())
        {
            $PropPrice = $arPrice["PRICE"]*0.9;
        }
        CIBlockElement::SetPropertyValueCode($arFields['ID'], "PRICE", $PropPrice);
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question