<?php declare(strict_types=1);
namespace Samson\Subscriber;
/***
*
* This file is part of the "SAMSON Shop" project.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2024
*
***/
use Samson\Pagelets\SalesChannelCountrySwitcher\SalesChannelCountrySwitcherPageletLoader;
use Shopware\Storefront\Page\GenericPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class GenericPageSubscriber implements EventSubscriberInterface
{
public function __construct(private SalesChannelCountrySwitcherPageletLoader $salesChannelCountrySwitcherPageletLoader)
{
}
public static function getSubscribedEvents(): array
{
return [
GenericPageLoadedEvent::class => 'onPageLoaded'
];
}
public function onPageLoaded(GenericPageLoadedEvent $event)
{
try {
$salesChannelCountrySwitcherPagelet = $this->salesChannelCountrySwitcherPageletLoader->load($event->getRequest(), $event->getSalesChannelContext());
if($salesChannelCountrySwitcherPagelet) {
$event->getPage()->addExtension('salesChannelCountrySwitcher', $salesChannelCountrySwitcherPagelet);
}
} catch (\Exception $e) {
}
}
}