custom/plugins/SwagAmazonPay/src/Storefront/EventListeners/AmazonPayButtonEventListener.php line 44

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * (c) shopware AG <info@shopware.com>
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Swag\AmazonPay\Storefront\EventListeners;
  9. use Shopware\Storefront\Page\Checkout\Cart\CheckoutCartPageLoadedEvent;
  10. use Shopware\Storefront\Page\Checkout\Offcanvas\OffcanvasCartPageLoadedEvent;
  11. use Shopware\Storefront\Page\Checkout\Register\CheckoutRegisterPageLoadedEvent;
  12. use Shopware\Storefront\Page\PageLoadedEvent;
  13. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  14. use Swag\AmazonPay\Components\Button\ButtonProviderInterface;
  15. use Swag\AmazonPay\Storefront\Page\Extension\AmazonPayButtonExtension;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. class AmazonPayButtonEventListener implements EventSubscriberInterface
  18. {
  19.     private ButtonProviderInterface $buttonProvider;
  20.     public function __construct(
  21.         ButtonProviderInterface $buttonProvider
  22.     ) {
  23.         $this->buttonProvider $buttonProvider;
  24.     }
  25.     /**
  26.      * {@inheritdoc}
  27.      */
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             CheckoutCartPageLoadedEvent::class => 'addAmazonPayButtonExtension',
  32.             OffcanvasCartPageLoadedEvent::class => 'addAmazonPayButtonExtension',
  33.             ProductPageLoadedEvent::class => 'addAmazonPayButtonExtension',
  34.             CheckoutRegisterPageLoadedEvent::class => 'addAmazonPayButtonExtension',
  35.         ];
  36.     }
  37.     public function addAmazonPayButtonExtension(PageLoadedEvent $event): void
  38.     {
  39.         $buttonExtension $this->buttonProvider->getAmazonPayButton($event);
  40.         if ($buttonExtension === null) {
  41.             return;
  42.         }
  43.         $event->getPage()->addExtension(AmazonPayButtonExtension::EXTENSION_NAME$buttonExtension);
  44.     }
  45. }