Documentation

Shopping cart saving

Shopping cart specifics: it can be associated or not associated with an order. When order is placed and checkout is complete, the cart used is associated with this specific order. When order is not yet placed and checkout process is unfinished, the cart accordingly is not associated. In cases when cart is not associated with the order, the cart has two additional events.

EventDescription and parameters
OnSaleBasketBeforeSaved Triggered before saving a shopping cart.

Parameters
ENTITY Shopping cart object.
OnSaleBasketSaved Triggered after shopping cart is saved.

Parameters
ENTITY Shopping cart object.

Example

//example of event OnSaleBasketBeforeSaved

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

//handler specifies limit by weight for shopping cart saving:

function myFunction(Main\Event $event)
{
    /** @var Basket $basket */
    $basket = $event->getParameter("ENTITY");

    if ($basket->getWeight() > 100)
    {
        return new Main\EventResult(Main\EventResult::ERROR);
    }

    return new Main\EventResult(Main\EventResult::SUCCESS);
}



© «Bitrix24», 2001-2024