BeforeBasketRemoveOnPlaceOrder

This event belongs to the graphql-storefront module. It will be fired before basket remove when an order is placed and holds the ID of the user basket which was ordered. You may call the setPreserveBasketAfterOrder(bool $preserveBasketAfterOrder = true) method to preserve basket after order.

  • true will preserve basket

  • false will remove basket (default)

BeforeBasketRemoveOnPlaceOrderEventSubscriber

<?php

declare(strict_types=1);

namespace Full\Qualified\Namespace;

use OxidEsales\GraphQL\Storefront\Basket\Event\BeforeBasketRemoveOnPlaceOrder;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class DeveloperBeforeBasketRemoveOnPlaceOrderEventSubscriber implements EventSubscriberInterface
{
    public function handle(BeforeBasketRemoveOnPlaceOrder $event): BeforeBasketRemoveOnPlaceOrder
    {
        //get the user basket id from event
        $userBasketId = (string) $event->getBasketId();

        // decide
        if (rand(0, 1)) {
            $event->setPreserveBasketAfterOrder(true);
        }

        return $event;
    }

    public static function getSubscribedEvents()
    {
        return [
            'OxidEsales\GraphQL\Storefront\Basket\Event\BeforeBasketRemoveOnPlaceOrder' => 'handle'
        ];
    }
}

Important

The code above is only an example. In case you need to handle the BeforeBasketRemoveOnPlaceOrder event, please adapt to your needs.

services.yaml

services:

    _defaults:
        public: false
        autowire: true

    Full\Qualified\Namespace\DeveloperBeforeBasketRemoveOnPlaceOrderEventSubscriber:
        class: Full\Qualified\Namespace\DeveloperBeforeBasketRemoveOnPlaceOrderEventSubscriber
        tags: ['kernel.event_subscriber']