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 authorizationfalse
will fail the authorization (default)
BasketAuthorizationEventSubscriber
<?php
declare(strict_types=1);
namespace Full\Qualified\Namespace;
use OxidEsales\EshopCommunity\Internal\Framework\Event\AbstractShopAwareEventSubscriber;
use OxidEsales\GraphQL\Storefront\Basket\Event\BasketAuthorization;
use function rand;
class BasketAuthorizationEventSubscriber extends AbstractShopAwareEventSubscriber
{
public function handleAuth(BasketAuthorization $event): BasketAuthorization {
// decide
if (rand(0, 1)) {
$event->setAuthorized(true);
}
return $event;
}
public static function getSubscribedEvents(): array
{
return [
BasketAuthorization::NAME => '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']