<?php declare(strict_types=1);
namespace NetzpNotifications6\Subscriber;
use NetzpNotifications6\Helper\NotificationsHelper;
use Shopware\Storefront\Pagelet\Header\HeaderPageletLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FrontendSubscriber implements EventSubscriberInterface
{
private $helper;
public function __construct(NotificationsHelper $helper)
{
$this->helper = $helper;
}
public static function getSubscribedEvents(): array
{
return [
HeaderPageletLoadedEvent::class => 'loadNotifications'
];
}
public function loadNotifications(HeaderPageletLoadedEvent $event): void
{
$baseUrl = $event->getRequest()->getBaseUrl();
$url = $event->getRequest()->get('sw-original-request-uri');
if($url == null) {
$url = $event->getRequest()->getPathInfo();
}
if($url != null) {
$url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8'); // prevent XSS
}
$data['cookiename'] = $this->helper->getCookieName();
$data['channelid'] = $event->getSalesChannelContext()->getSalesChannel()->getId();
$data['channelurl'] = $event->getRequest()->get('sw-sales-channel-base-url');
$data['url'] = $url;
$data['route'] = $event->getRequest()->attributes->get('_route');
$data['baseurl'] = $baseUrl;
$data['privacylink'] = '';
$event->getPagelet()->assign(['netzp_notification' => $data]);
}
}