Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question