vendor/store.shopware.com/swagamazonpay/src/Storefront/Pagelet/Footer/FooterPageletLoadedEventSubscriber.php line 39

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.     private AmazonPayPaymentMethodHelperInterface $amazonPayPaymentMethodHelper;
  17.     private ConfigServiceInterface $configService;
  18.     public function __construct(
  19.         AmazonPayPaymentMethodHelperInterface $amazonPayPaymentMethodHelper,
  20.         ConfigServiceInterface $configService
  21.     ) {
  22.         $this->amazonPayPaymentMethodHelper $amazonPayPaymentMethodHelper;
  23.         $this->configService $configService;
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             FooterPageletLoadedEvent::class => 'onFooterPageletLoaded',
  29.         ];
  30.     }
  31.     public function onFooterPageletLoaded(FooterPageletLoadedEvent $event): void
  32.     {
  33.         if (!$this->amazonPayPaymentMethodHelper->isAmazonPayActive($event->getSalesChannelContext())) {
  34.             return;
  35.         }
  36.         try {
  37.             $amazonPayConfigStruct $this->configService->getPluginConfig($event->getSalesChannelContext()->getSalesChannel()->getId());
  38.         } catch (ConfigValidationException $e) {
  39.             return;
  40.         }
  41.         if ($amazonPayConfigStruct->isHideOneClickCheckoutButtons()) {
  42.             return;
  43.         }
  44.         $event->getPagelet()->addExtension(self::AMAZON_PAY_FOOTER_EXTENSION, new AmazonPayFooterStruct());
  45.     }
  46. }