custom/plugins/NetiNextOrderAmountHandler/src/Subscriber/PaymentMethodSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextOrderAmountHandler\Subscriber;
  4. use NetInventors\NetiNextOrderAmountHandler\Service\PluginConfig;
  5. use Shopware\Storefront\Event\RouteRequest\PaymentMethodRouteRequestEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class PaymentMethodSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var PluginConfig
  11.      */
  12.     protected $pluginConfig;
  13.     public function __construct(PluginConfig $pluginConfig)
  14.     {
  15.         $this->pluginConfig $pluginConfig;
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             PaymentMethodRouteRequestEvent::class => 'onPaymentRequestRoute',
  21.         ];
  22.     }
  23.     public function onPaymentRequestRoute(PaymentMethodRouteRequestEvent $event): void
  24.     {
  25.         if (!$this->pluginConfig->isActive()) {
  26.             return;
  27.         }
  28.         $event->getStoreApiRequest()->attributes->set(
  29.             'orderId',
  30.             $event->getStorefrontRequest()->attributes->get('orderId''')
  31.         );
  32.     }
  33. }