BasketAuthorization

This event belongs to the graphql-storefront module. It will be fired when basket authorization is done. You may call the setAuthorized(bool $authorized) method to oversteer the default basket authorization logic.

  • true will succeed the authorization

  • false will fail the authorization (default)

BasketAuthorizationEventSubscriber

<?php

declare(strict_types=1);

namespace Full\Qualified\Namespace;

use OxidEsales\GraphQL\Storefront\Basket\Event\BasketAuthorization;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use function rand;

class BasketAuthorizationEventSubscriber implements EventSubscriberInterface
{
    public function handleAuth(BasketAuthorization $event): BasketAuthorization {
        // decide
        if (rand(0, 1)) {
            $event->setAuthorized(true);
        }
        return $event;
    }

    public static function getSubscribedEvents(): array
    {
        return [
            BasketAuthorization::class => 'handleAuth'
        ];
    }
}

Important

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

services.yaml

services:

    _defaults:
        public: false
        autowire: true

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