A
A
Anton Golubkov2018-02-21 10:53:05
1C-Bitrix
Anton Golubkov, 2018-02-21 10:53:05

How to prohibit order cancellation on Bitrix?

Good afternoon!
There was a question, how to prohibit changing the order status to "Cancelled"?
The essence of the problem is that a ban on changing the status of an order is now implemented if the order is "sent" or "delivered".
But changing from "shipped" to "delivered" also fails
. How can I prevent orders with the status "shipped" or "delivered" from changing the status to "cancelled"?

use Bitrix\Main;

Main\EventManager::getInstance()->addEventHandler(
    'sale',
    'OnSaleOrderBeforeSaved',
    'onSaleOrderBeforeSavedHandler'
);

function onSaleOrderBeforeSavedHandler(Main\Event $event)
{
    global $USER;

    /* @var Order $order */
    $order = $event->getParameter("ENTITY");
    $oldValues = $event->getParameter("VALUES");
    $isNew = $event->getParameter("IS_NEW");

    if (!$isNew) {
        $userGroups = $USER->GetUserGroupArray();

        if ($order->getField('STATUS_ID') === 'J' || $order->getField('STATUS_ID') === 'V') {

            return new \Bitrix\Main\EventResult(
                \Bitrix\Main\EventResult::ERROR,
                new \Bitrix\Sale\ResultError('Редактирование заказа запрещено'),
                'sale'
            );

        }

    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2021-07-14
@akhx

I came across this page looking for a solution.
You need to use the action before changing OnSaleBeforeStatusOrderChange to cancel it, in OnSaleOrderBeforeSaved the saving has already happened and you can only set it again

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question