Answer the question
In order to leave comments, you need to log in
Why is the event handler not being called?
Good afternoon.
The event handler registered in its module in the ../install/index.php file is not called
RegisterModuleDependences('sale', 'OnSaleOrderSaved', $this->MODULE_ID, '\\Yolo\\Bonus\\EventHandler', 'myFunction');
<?php
namespace Yolo\Bonus;
require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php');
$module_id = "yolo.bonus";
\CModule::IncludeModule('main');
\CModule::IncludeModule('sale');
\CModule::IncludeModule($module_id);
use Bitrix\Main;
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Application;
use Bitrix\Main\Type\DateTime;
use Yolo\Bonus;
use Yolo\Bonus\Core;
use Bitrix\Sale;
use Bitrix\Sale\Order;
use Bitrix\Sale\Basket;
use Bitrix\Sale\Delivery;
use Bitrix\Sale\PaySystem;
class EventHandler{
public function OnSaleStatusOrder($order_id, $status_val){
// ...
}
public function myFunction(\Bitrix\Main\Event $event)
{
/** @var Order $order */
$order = $event->getParameter("ENTITY");
$oldValues = $event->getParameter("VALUES");
$isNew = $event->getParameter("IS_NEW");
if ($isNew)
{
$sum = $order->getPrice();
// . . .
}
}
}
?>
Argument 1 passed to Yolo\Bonus\EventHandler::myFunction() must be an instance of Bitrix\Main\Event, instance of Bitrix\Sale\Order given (0)
Answer the question
In order to leave comments, you need to log in
I had to blunt a little ...
If you register an event like this, your version will work ok
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->registerEventHandler('sale', 'OnSaleOrderSaved', $this->MODULE_ID, '\\Yolo\\Bonus\\EventHandler', 'myFunction');
First, such methods should be marked as static so as not to cause errors in php itself.
Secondly, there is a description of events - https://dev.1c-bitrix.ru/api_d7/bitrix/sale/events... which says that the event handler takes 3 parameters.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question