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

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.     /**
  20.      * @var ButtonProviderInterface
  21.      */
  22.     private $buttonProvider;
  23.     public function __construct(
  24.         ButtonProviderInterface $buttonProvider
  25.     ) {
  26.         $this->buttonProvider $buttonProvider;
  27.     }
  28.     /**
  29.      * {@inheritdoc}
  30.      */
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [
  34.             CheckoutCartPageLoadedEvent::class => 'addAmazonPayButtonExtension',
  35.             OffcanvasCartPageLoadedEvent::class => 'addAmazonPayButtonExtension',
  36.             ProductPageLoadedEvent::class => 'addAmazonPayButtonExtension',
  37.             CheckoutRegisterPageLoadedEvent::class => 'addAmazonPayButtonExtension',
  38.         ];
  39.     }
  40.     public function addAmazonPayButtonExtension(PageLoadedEvent $event): void
  41.     {
  42.         $buttonExtension $this->buttonProvider->getAmazonPayButton($event);
  43.         if ($buttonExtension === null) {
  44.             return;
  45.         }
  46.         $event->getPage()->addExtension(AmazonPayButtonExtension::EXTENSION_NAME$buttonExtension);
  47.     }
  48. }