M
M
m4son2022-02-08 19:14:07
1C-Bitrix
m4son, 2022-02-08 19:14:07

How to remove the error "Maximum function nesting level of '256' reached, aborting!"?

At the "Save order" event, I try to change the status of the order, I write the code:

$order = $event->getParameter("ENTITY");
$order->setField("STATUS_ID", "T");
$order->save();

But the error "Maximum function nesting level of '256' reached, aborting!"
I increased the nesting to 2000, but it didn't help.
Tell me what's wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Tkachev, 2022-02-09
@m4son

You are entering an endless cycle of updates. At the entrance to the function, check that the desired status is already set.

R
Roman Gritsuk, 2022-02-09
@winer

No need to call $order->save();

public function changeStatusOnOrderCreate(\Bitrix\Main\Event $event)
{
    /** @var \Bitrix\Sale\Order $order */
    $order = $event->getParameter("ENTITY");
    $order->setField("STATUS_ID", "T");

    $event->addResult(
        new Main\EventResult(
            Main\EventResult::SUCCESS, $order
        )
    );
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question