Documentation

Entity saving

EventDescription and parametersFull event names
OnEntitySaved Triggered directly after saving an entity of order system.

Parameters
ENTITY Saved object.
VALUES Old field values.
IS_NEW Indicates a new shipment. This parameter is available from sale 22.0.200 and only for the event OnSaleShipmentEntitySaved.
OnSaleOrderEntitySaved

OnSaleBasketItemEntitySaved

OnSaleShipmentEntitySaved

OnSaleShipmentItemEntitySaved

OnSalePaymentEntitySaved

OnSalePropertyValueEntitySaved
where <descendant> is one of descendants from class \Bitrix\Sale\Internals\Entity:
  • order - SaleOrder;
  • product in shopping cart - SaleBasketItem;
  • shipment - SaleShipment;
  • shipment item - SaleShipmentItem;
  • payment - SalePayment;
  • order property - SalePropertyValue.

Example

//let's review an example for event OnSalePaymentEntitySaved:

\Bitrix\Main\EventManager::getInstance()->addEventHandler(
    'sale',
    'OnSalePaymentEntitySaved',
    'myFunction'
);

/*
The handler defines if payment is performed using the internal account,
then entity saving actions are performed:
*/

function myFunction(\Bitrix\Main\Event $event)
{
     /** @var Payment $payment */
    $payment = $event->getParameter("ENTITY");
    $oldValues = $event->getParameter("VALUES");

    if ($payment->isInner())
    {
        // this is an internal account
        // . . . 
    }
}


//example with execution of specific actions when updating order status

\Bitrix\Main\EventManager::getInstance()->addEventHandler(
	'sale',
	'OnSaleOrderEntitySaved',
	'OnStatusChange'
);

function OnStatusChange(Bitrix\Main\Event $event)
{
	$arEmailFields = array();
	$order = $event->getParameter("ENTITY");
	$oldValues = $event->getParameter("VALUES");
	$arOrderVals = $order->getFields()->getValues();
	if($arOrderVals['STATUS_ID'] == 'F' && isset($oldValues['STATUS_ID']) && $oldValues['STATUS_ID'] != 'F') // status updated
		{
         // Execute the actions you require
         //  ...
		}

}



© «Bitrix24», 2001-2024