<?php
declare(strict_types=1);
namespace NetInventors\NetiNextOrderAmountHandler\Subscriber;
use NetInventors\NetiNextOrderAmountHandler\Service\PluginConfig;
use Shopware\Storefront\Event\RouteRequest\PaymentMethodRouteRequestEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PaymentMethodSubscriber implements EventSubscriberInterface
{
/**
* @var PluginConfig
*/
protected $pluginConfig;
public function __construct(PluginConfig $pluginConfig)
{
$this->pluginConfig = $pluginConfig;
}
public static function getSubscribedEvents(): array
{
return [
PaymentMethodRouteRequestEvent::class => 'onPaymentRequestRoute',
];
}
public function onPaymentRequestRoute(PaymentMethodRouteRequestEvent $event): void
{
if (!$this->pluginConfig->isActive()) {
return;
}
$event->getStoreApiRequest()->attributes->set(
'orderId',
$event->getStorefrontRequest()->attributes->get('orderId', '')
);
}
}