<?php declare(strict_types=1);
namespace DreiscSeoPro\Subscriber\Installment\BaseInformation;
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
use Shopware\Storefront\Page\Navigation\NavigationPageLoadedEvent;
use Shopware\Storefront\Page\Page;
use Shopware\Storefront\Page\PageLoadedEvent;
use Shopware\Storefront\Page\Product\ProductPage;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class BaseInformationSubscriber implements EventSubscriberInterface
{
public const DREISC_SEO_INSTALLMENT_BASE_INFORMATION_DATA = 'dreiscSeoInstallmentBaseInformationData';
public static function getSubscribedEvents()
{
return [
NavigationPageLoadedEvent::class => 'addInstallment',
];
}
/**
* @param PageLoadedEvent $event
* @throws InconsistentCriteriaIdsException
*/
public function addInstallment(PageLoadedEvent $event)
{
/** @var Page|ProductPage $page */
$page = $event->getPage();
$baseInformationDataStruct = new BaseInformationDataStruct(
$event->getRequest()->attributes->get('navigationId')
);
$page->addExtension(
self::DREISC_SEO_INSTALLMENT_BASE_INFORMATION_DATA,
$baseInformationDataStruct
);
}
}