M
M
Maxim Markin2016-01-18 17:18:10
1C-Bitrix
Maxim Markin, 2016-01-18 17:18:10

How to correctly register an event handler in your own module?

How to make a handler? I did everything according to the documentation, according to information on the Internet, but nothing came out. And in general, there is very little information about this.
Here, first I register the handler when installing the module

RegisterModuleDependences("sale", "OnOrderSave",   $this->MODULE_ID, "", "importOrderAdd");

The documentation says that if parameter 4 is empty, it will include include.php from the module folder and the function will already be found there. In this case, it's importOrderAdd.
And now, adding a new order, nothing happens. What's the catch? Can someone solve these issues

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya, 2016-01-19
@owl1n

The API has changed, some events are no longer working, in version 15. See the doc:
dev.1c-bitrix.ru/learning/course/index.php?COURSE_...

EventManager::getInstance()->addEventHandler(
    'sale',
    'OnSaleOrderSaved',
    'myFunction'
);

function myFunction(\Main\Event $event)
{
    /** @var Order $order */
    $order = $event->getParameter("ENTITY");
    $oldValues = $event->getParameter("VALUES");
    $isNew = $event->getParameter("IS_NEW");

    if ($isNew)
    {
        $sum = $order->getPrice();
        // . . . 
    }
}

A
Alexey Ukolov, 2016-01-18
@alexey-m-ukolov

it will include include.php from the module folder and the function will already be found there .

No, it doesn't say that:
to_class A class belonging to module module whose method is an event handler function.
Optional parameter. By default - "" (the /bitrix/modules/to_module_id/include.php file will be simply included).
to_method Class method to_class which is an event handler function.
Optional parameter. By default - "" (the /bitrix/modules/to_module_id/include.php file will be simply included).
The most correct: create a class and a method in it.

V
Vladislav Kopylov, 2016-01-18
@kopylov_vlad

i register like this

RegisterModuleDependences('main', 'OnProlog', self::MODULE_ID, 'my_class', 'OnProlog');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question