M
M
Michael Kim2021-02-24 12:25:45
1C-Bitrix
Michael Kim, 2021-02-24 12:25:45

Bitrix — How to subscribe to an order blocking event?

I need to record in the history of work with the order.
When viewed in the admin panel - the order is automatically blocked.
/bitrix/modules/sale/admin/order_view.php:149

if ($boolLocked)
  $errorMsgs[] = Admin\OrderEdit::getLockingMessage($ID);
else
  $orderClass::lock($ID);


/bitrix/modules/sale/lib/order.php:1850
return static::updateInternal($id, array(
  'DATE_LOCK' => new Main\Type\DateTime(),
  'LOCKED_BY' => (is_object($USER) ? $USER->GetID(): false)
));


/bitrix/modules/main/lib/entity/datamanager.php:772
$event = new Event($entity, self::EVENT_ON_BEFORE_UPDATE, array("id" => $primary, "fields" => $fields));
$event->send();


I'm trying to subscribe to the events OnBeforeUpdate, OnBeforeEventSend - nothing happens.
Where to dig?

Or will you have to implement a custom order view form?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2021-02-24
@devjob

I don’t know specifically about the lock, you can update the order like this, check there if LOCKED_BY is not null, it means it’s locked

$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('sale', '\Bitrix\Sale\Internals\Order::onUpdate', ['OrderEvents', 'onUpdate']);

class OrderEvents {
  public static function onUpdate(\Bitrix\Main\Event $event) {
    $fields = $event->getParameters()['fields'];
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question