custom/plugins/SwagAmazonPay/src/Storefront/Pagelet/Footer/FooterPageletLoadedEventSubscriber.php line 43

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /*
  3.  * (c) shopware AG <info@shopware.com>
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Swag\AmazonPay\Storefront\Pagelet\Footer;
  8. use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
  9. use Swag\AmazonPay\Components\Config\ConfigServiceInterface;
  10. use Swag\AmazonPay\Components\Config\Validation\Exception\ConfigValidationException;
  11. use Swag\AmazonPay\Util\Helper\AmazonPayPaymentMethodHelperInterface;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class FooterPageletLoadedEventSubscriber implements EventSubscriberInterface
  14. {
  15.     public const AMAZON_PAY_FOOTER_EXTENSION 'amazonPayFooterExtension';
  16.     /**
  17.      * @var AmazonPayPaymentMethodHelperInterface
  18.      */
  19.     private $amazonPayPaymentMethodHelper;
  20.     /**
  21.      * @var ConfigServiceInterface
  22.      */
  23.     private $configService;
  24.     public function __construct(AmazonPayPaymentMethodHelperInterface $amazonPayPaymentMethodHelperConfigServiceInterface $configService)
  25.     {
  26.         $this->amazonPayPaymentMethodHelper $amazonPayPaymentMethodHelper;
  27.         $this->configService $configService;
  28.     }
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             FooterPageletLoadedEvent::class => 'onFooterPageletLoaded',
  33.         ];
  34.     }
  35.     public function onFooterPageletLoaded(FooterPageletLoadedEvent $event): void
  36.     {
  37.         if (!$this->amazonPayPaymentMethodHelper->isAmazonPayActive($event->getSalesChannelContext())) {
  38.             return;
  39.         }
  40.         try {
  41.             $amazonPayConfigStruct $this->configService->getPluginConfig($event->getSalesChannelContext()->getSalesChannel()->getId());
  42.         } catch (ConfigValidationException $e) {
  43.             return;
  44.         }
  45.         if ($amazonPayConfigStruct->isHideOneClickCheckoutButtons()) {
  46.             return;
  47.         }
  48.         $event->getPagelet()->addExtension(self::AMAZON_PAY_FOOTER_EXTENSION, new AmazonPayFooterStruct());
  49.     }
  50. }