<?php declare(strict_types=1);
namespace Cf\CookieFirst\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
use Cf\CookieFirst\Struct\StorefrontPageData;
/**
* Class PageSubscriber
*
* @package Cf\CookieFirst\Subscriber
*/
class PageSubscriber implements EventSubscriberInterface
{
/**
* @var SystemConfigService
*/
private $systemConfigService;
/**
* PageSubscriber constructor.
* @param SystemConfigService $systemConfigService
*/
public function __construct(SystemConfigService $systemConfigService)
{
$this->systemConfigService = $systemConfigService;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
FooterPageletLoadedEvent::class => 'onFooterLoaded',
];
}
/**
* @param FooterPageletLoadedEvent $event
*/
public function onFooterLoaded(FooterPageletLoadedEvent $event): void
{
if (!$this->systemConfigService->get(
'CookieFirst.config.showWidget', $event->getSalesChannelContext()->getSalesChannel()->getId()
)) {
return;
}
$config = $this->systemConfigService->getDomain('CookieFirst.config', $event->getSalesChannelContext()->getSalesChannel()->getId(), true );
$configValues = new StorefrontPageData($config);
$event->getPagelet()->addExtension('CookieFirst', $configValues);
}
}