Answer the question
In order to leave comments, you need to log in
Why does the OnSaleOrderSaved event fire multiple times?
I made a handler for the OnSaleOrderSaved event and noticed that this event fires for me three times after placing an order, although it should probably work only once.
The code of my event handler OnSaleOrderSaved
use Bitrix\Main;
use Bitrix\Main\EventManager;
use Bitrix\Main\Loader;
use Bitrix\Main\Event;
use Bitrix\Sale\Order;
use Bitrix\Main\Entity;
global $USER;
$eventManager = EventManager::getInstance();
// ЗАКАЗ
// при создании заказа
$eventManager->addEventHandler(
"sale",
"OnSaleOrderSaved",
"onSaleOrderSaved"
);
function onSaleOrderSaved(Bitrix\Main\Event $event){
$order = $event->getParameter("ENTITY");
setLog('OnSaleOrderSaved'); // записываем в файл что обработчик был вызван
}
// запись в файл логов
function setLog($arFields){
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/log_iblock_setlog.txt', serialize($arFields)."\r\n", FILE_APPEND);
}
Answer the question
In order to leave comments, you need to log in
Perhaps this is due to the fact that the order has several statuses. So you created an order - there is one status, the payment went through - it becomes a different status (i.e. you need to resave it), the status is set - the payment is completed - the automation of processes is triggered and the status is set completed - once again resaving is in progress
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question