custom/static-plugins/SamsonCustomer/src/Subscriber/GenericPageSubscriber.php line 33

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Samson\Subscriber;
  3. /***
  4.  *
  5.  * This file is part of the "SAMSON Shop" project.
  6.  *
  7.  * For the full copyright and license information, please read the
  8.  * LICENSE.txt file that was distributed with this source code.
  9.  *
  10.  *  (c) 2024
  11.  *
  12.  ***/
  13. use Samson\Pagelets\SalesChannelCountrySwitcher\SalesChannelCountrySwitcherPageletLoader;
  14. use Shopware\Storefront\Page\GenericPageLoadedEvent;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class GenericPageSubscriber implements EventSubscriberInterface
  17. {
  18.     public function __construct(private SalesChannelCountrySwitcherPageletLoader $salesChannelCountrySwitcherPageletLoader)
  19.     {
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             GenericPageLoadedEvent::class => 'onPageLoaded'
  25.         ];
  26.     }
  27.     public function onPageLoaded(GenericPageLoadedEvent $event)
  28.     {
  29.         try {
  30.             $salesChannelCountrySwitcherPagelet $this->salesChannelCountrySwitcherPageletLoader->load($event->getRequest(), $event->getSalesChannelContext());
  31.             if($salesChannelCountrySwitcherPagelet) {
  32.                 $event->getPage()->addExtension('salesChannelCountrySwitcher'$salesChannelCountrySwitcherPagelet);
  33.             }
  34.         } catch (\Exception $e) {
  35.         }
  36.     }
  37. }