<?php declare(strict_types=1);
namespace IronHoliday\Subscriber;
use IronHoliday\Holiday\HolidayDataService;
use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class PluginSettingsSubscriber
*
* @package IronHoliday\Subscriber
*/
class PluginSettingsSubscriber implements EventSubscriberInterface
{
const HOLIDAY_DATA_EXTENSION_ID = 'ironHolidayData';
/**
* @var HolidayDataService
*/
private $holidayDataService;
/**
* PluginSettingsSubscriber constructor.
*
* @param HolidayDataService $holidayDataService
*/
public function __construct(
HolidayDataService $holidayDataService
)
{
$this->holidayDataService = $holidayDataService;
}
/*
* @inherit
*/
public static function getSubscribedEvents(): array
{
return [
ProductPageLoadedEvent::class => 'onProductPageLoaded',
CheckoutConfirmPageLoadedEvent::class => 'onCheckoutConfirmPageLoaded',
];
}
/**
* @param CheckoutConfirmPageLoadedEvent $event
* @throws \Exception
*/
public function onCheckoutConfirmPageLoaded(CheckoutConfirmPageLoadedEvent $event)
{
$page = $event->getPage();
$page->addExtensions([self::HOLIDAY_DATA_EXTENSION_ID => $this->holidayDataService->getHolidayData()]);
}
/**
* @param ProductPageLoadedEvent $event
* @throws \Exception
*/
public function onProductPageLoaded(ProductPageLoadedEvent $event)
{
$page = $event->getPage();
$page->addExtensions([self::HOLIDAY_DATA_EXTENSION_ID => $this->holidayDataService->getHolidayData()]);
}
}