Documentation

Value updates

EventDescription and parametersFull event names
OnBeforeSetField* Triggered before the update and you can cancel this update and prohibit field update.

Parameters
ENTITY Object with the field.
NAME Field name.
VALUE Field value.
OnBeforeSaleOrderSetField

OnBeforeSaleBasketItemSetField

OnBeforeSaleShipmentSetField

OnBeforeSaleShipmentItemSetField

OnBeforeSalePaymentSetField

OnBeforeSalePropertyValueSetField
OnSetField* Triggered directly before the update, the event almost started.

Parameters
ENTITY Object with field.
NAME Field name.
VALUE Field value.
OLD_VALUE Old field value.
OnSaleOrderSetField

OnSaleBasketItemSetField

OnSaleShipmentSetField

OnSaleShipmentItemSetField

OnSalePaymentSetField

OnSalePropertyValueSetField
* <descendant> - one of descendants for class \Bitrix\Sale\Internals\Entity:
  • order - SaleOrder;
  • product in shopping cart - SaleBasketItem;
  • shipment - SaleShipment;
  • product in shipment - SaleShipmentItem;
  • payment - SalePayment;
  • order property - SalePropertyValue.

Example

/*
let's review an example, when prices in shopping cart are rounded off. In this example, we will round off prices not only using shopping cart rules, but also to discard pennies. We will need the event handler OnBeforeSaleBasketItemSetField for this.
*/

\Bitrix\Main\EventManager::getInstance()->addEventHandler(
    'sale',
    'OnBeforeSaleBasketItemSetField',
    'roundPrice'
);

/*
Handler for this will be called each time, when attempting to update a shopping cart item price. Accordingly, in this handler you are checking, that the price is indeed updated and you round off VALUE to discard pennies.
*/

function roundPrice(\Bitrix\Main\Event $event)
{
    $name = $event->getParameter('NAME');
    $value = $event->getParameter('VALUE');

    if ($name === 'PRICE')
    {
        $value = floor($value);
        $event->addResult(
            new Main\EventResult(
                Main\EventResult::SUCCESS, array('VALUE' => $value)
            )
        );
    }
}



© «Bitrix24», 2001-2024