Answer the question
In order to leave comments, you need to log in
1C-Bitrix. How to make the status "Cancelled" when canceling an order instead of "Completed"?
Good afternoon.
When canceling an order in Bitrix, the status "Completed" is set to the order.
How to make the status "Canceled" when canceling an order instead of "Completed"? If I create valid status "Cancelled" in statuses with CN code
Thanks in advance
Answer the question
In order to leave comments, you need to log in
We need to write an event handler for the sale OnSaleOrderBeforeSaved module.
Here is an example handler
<?
namespace Gricuk\Sale;
class OrderEvents
{
/**
* 1) Смена статуса для отмененного заказа
* 2) Комиссия за наложенный платёж
* @param \Bitrix\Main\Event $event
* @link https://dev.1c-bitrix.ru/api_d7/bitrix/sale/events/order_saved.php
*/
public static function OnSaleOrderBeforeSavedHandler(\Bitrix\Main\Event $event)
{
/** @var \Bitrix\Sale\Order $order */
$order = $event->getParameter("ENTITY");
global $USER;
if (!$order->isNew()) {
$orderStatus = $order->getField("STATUS_ID");
if ($order->isCanceled() && ($orderStatus != "CN")) {
$order->setField("STATUS_ID", "CN");
$event->addResult(new \Bitrix\Main\EventResult(
\Bitrix\Main\EventResult::SUCCESS,
array(
"RESULT" => $order,
)
));
}
return;
}
}
}
<?
$bxEventManager = \Bitrix\Main\EventManager::getInstance();
$bxEventManager->addEventHandler(
"sale",
"OnSaleOrderBeforeSaved",
array(
\Gricuk\Sale\OrderEvents::class,
"OnSaleOrderBeforeSavedHandler"
)
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question