<?php
/**
* PremSoft
* Copyright © 2021 Premsoft - Sven Mittreiter
*
* @copyright Copyright (c) 2021, premsoft - Sven Mittreiter (http://www.premsoft.de)
* @author Sven Mittreiter <info@premsoft.de>
*/
namespace Prems\Plugin\PremsIndividualOffer6\Subscriber;
use Prems\Plugin\PremsIndividualOffer6\Core\Offer\Storefront\OfferService;
use Shopware\Core\Framework\Struct\ArrayStruct;
use Shopware\Storefront\Page\GenericPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PageLoadedSubscriber implements EventSubscriberInterface
{
private OfferService $offerService;
public function __construct(OfferService $offerService)
{
$this->offerService = $offerService;
}
public static function getSubscribedEvents(): array
{
return [
GenericPageLoadedEvent::class => 'onPageLoaded'
];
}
public function onPageLoaded(GenericPageLoadedEvent $event): void
{
$event->getPage()->addExtension(
'premsIndividualOffer',
new ArrayStruct([
'isOfferRequestAllowed' => $this->offerService->isOfferRequestAllowed($event->getSalesChannelContext()),
'isOfferNavAllowed' => $this->offerService->isOfferNavAllowed($event->getSalesChannelContext()),
])
);
}
}