Order saving
Saving is always performed using the order's method save()
. Not only the order is saved, but also all entities associated with it (payment and shipment) specifically in the same consistent state that resulted after calculation of objects:
/** \Bitrix\Sale\Order $order */ $order = \Bitrix\Sale\Order::load(18); $order->setField("USER_DESCRIPTION", "Deliver to apartment"); $shipmentCollection = $order->getShipmentCollection(); /** \Bitrix\Sale\Shipment $shipment */ foreach ($shipmentCollection as $shipment) { if (!$shipment->isSystem()) $shipment->allowDelivery(); } $order->save();
There are two saving events that can interrupt the order saving process.
Event | Description and parameters | ||||||
---|---|---|---|---|---|---|---|
OnSaleOrderBeforeSaved | Triggered at the start of saving process.
Parameters
|
||||||
OnSaleOrderSaved | Triggered at the end of saving process, when order and all associated entities are already saved.
Parameters
|
Example
//example of event OnSaleOrderSaved use use Bitrix\Main; Main\EventManager::getInstance()->addEventHandler( 'sale', 'OnSaleOrderSaved', 'myFunction' ); //handler receives the sum to be used for specific actions in the future: function myFunction(Main\Event $event) { /** @var Order $order */ $order = $event->getParameter("ENTITY"); $oldValues = $event->getParameter("VALUES"); $isNew = $event->getParameter("IS_NEW"); if ($isNew) { $sum = $order->getPrice(); // . . . } }
© «Bitrix24», 2001-2024