<?php
namespace EnetMinOrderValue\Subscriber;
use EnetMinOrderValue\Struct\MinOrderValueSettingsStruct;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
use Shopware\Storefront\Page\Checkout\Offcanvas\OffcanvasCartPageLoadedEvent;
use Shopware\Storefront\Page\PageLoadedEvent;
use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FooterSubscriber implements EventSubscriberInterface
{
/** @var SystemConfigService $systemConfigService */
private $systemConfigService;
public function __construct(SystemConfigService $systemConfigService)
{
$this->systemConfigService = $systemConfigService;
}
public static function getSubscribedEvents()
{
return [
FooterPageletLoadedEvent::class => 'onPageletLoaded',
OffcanvasCartPageLoadedEvent::class => 'onPageLoaded',
CheckoutConfirmPageLoadedEvent::class => 'onPageLoaded'
];
}
public function onPageLoaded(PageLoadedEvent $event)
{
$event->getPage()->addExtension(
'enetMinOrderValueSettings',
$this->getSettings()
);
}
public function onPageletLoaded(FooterPageletLoadedEvent $event)
{
$event->getPagelet()->addExtension(
'enetMinOrderValueSettings',
$this->getSettings()
);
}
private function getSettings()
{
$settings = $this->systemConfigService->get('EnetMinOrderValue.config');
return new MinOrderValueSettingsStruct($settings);
}
}