custom/plugins/SwagPayPal/src/Checkout/SPBCheckout/SPBMarksSubscriber.php line 51

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\PayPal\Checkout\SPBCheckout;
  8. use Psr\Log\LoggerInterface;
  9. use Shopware\Storefront\Page\Account\Order\AccountEditOrderPageLoadedEvent;
  10. use Shopware\Storefront\Page\Account\PaymentMethod\AccountPaymentMethodPageLoadedEvent;
  11. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  12. use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
  13. use Swag\PayPal\Checkout\ExpressCheckout\SalesChannel\ExpressPrepareCheckoutRoute;
  14. use Swag\PayPal\Checkout\SPBCheckout\Service\SPBMarksDataServiceInterface;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. /**
  17.  * @deprecated tag:v5.0.0 - will be removed, unbranded APMs will be introduced in v4.0.0 as replacement
  18.  */
  19. class SPBMarksSubscriber implements EventSubscriberInterface
  20. {
  21.     public const PAYPAL_SMART_PAYMENT_MARKS_DATA_EXTENSION_ID 'payPalSpbMarksData';
  22.     private SPBMarksDataServiceInterface $spbMarksDataService;
  23.     private LoggerInterface $logger;
  24.     public function __construct(
  25.         SPBMarksDataServiceInterface $spbMarksDataService,
  26.         LoggerInterface $logger
  27.     ) {
  28.         $this->logger $logger;
  29.         $this->spbMarksDataService $spbMarksDataService;
  30.     }
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [
  34.             AccountEditOrderPageLoadedEvent::class => 'addMarksExtension',
  35.             AccountPaymentMethodPageLoadedEvent::class => 'addMarksExtension',
  36.             FooterPageletLoadedEvent::class => 'addMarksExtension',
  37.             CheckoutConfirmPageLoadedEvent::class => 'addMarksExtension',
  38.         ];
  39.     }
  40.     /**
  41.      * @param AccountEditOrderPageLoadedEvent|AccountPaymentMethodPageLoadedEvent|FooterPageletLoadedEvent|CheckoutConfirmPageLoadedEvent $event
  42.      */
  43.     public function addMarksExtension($event): void
  44.     {
  45.         $spbMarksData $this->spbMarksDataService->getSpbMarksData($event->getSalesChannelContext());
  46.         if ($spbMarksData === null) {
  47.             return;
  48.         }
  49.         $this->logger->debug('Adding SPB marks to {page}', ['page' => \get_class($event)]);
  50.         if ($event instanceof CheckoutConfirmPageLoadedEvent) {
  51.             $confirmPage $event->getPage();
  52.             if ($confirmPage->getCart()->getExtension(ExpressPrepareCheckoutRoute::PAYPAL_EXPRESS_CHECKOUT_CART_EXTENSION_ID) !== null) {
  53.                 return;
  54.             }
  55.             $confirmPage->addExtension(self::PAYPAL_SMART_PAYMENT_MARKS_DATA_EXTENSION_ID$spbMarksData);
  56.             return;
  57.         }
  58.         if ($event instanceof AccountPaymentMethodPageLoadedEvent || $event instanceof AccountEditOrderPageLoadedEvent) {
  59.             $event->getPage()->addExtension(self::PAYPAL_SMART_PAYMENT_MARKS_DATA_EXTENSION_ID$spbMarksData);
  60.             return;
  61.         }
  62.         $event->getPagelet()->addExtension(self::PAYPAL_SMART_PAYMENT_MARKS_DATA_EXTENSION_ID$spbMarksData);
  63.     }
  64. }