<?php declare(strict_types=1);
namespace Tds\Orlob\Subscriber;
use DateTime;
use Shopware\Storefront\Event\StorefrontRenderEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class StorefrontSubscriber implements EventSubscriberInterface
{
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return [
StorefrontRenderEvent::class => 'onStorefrontRender'
];
}
public function onStorefrontRender(StorefrontRenderEvent $event): void
{
$event->setParameter('seasonThreshold', $this->buildSeasonThreshold());
$event->setParameter('currentSeasonThreshold', $this->buildCurrenSeasonThreshold());
}
/**
* @return string
*
* @throws \Exception
*/
private function buildSeasonThreshold()
{
$format = date('Y-03-01', strtotime('+1 year'));
$date = new DateTime($format);
return $date->format('U');
}
/**
* @return string
*
* @throws \Exception
*/
private function buildCurrenSeasonThreshold()
{
$format = date('Y-03-01');
$date = new DateTime($format);
return $date->format('U');
}
}