Answer the question
In order to leave comments, you need to log in
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");
Answer the question
In order to leave comments, you need to log in
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();
// . . .
}
}
it will include include.php from the module folder and the function will already be found there .
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.
i register like this
RegisterModuleDependences('main', 'OnProlog', self::MODULE_ID, 'my_class', 'OnProlog');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question