<?php declare(strict_types=1);
namespace Cogi\Closeout\Subscriber;
use Cogi\Closeout\Core\Service\CloseoutService;
use Shopware\Core\Content\Product\ProductEvents;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class StorefrontSubscriber implements EventSubscriberInterface
{
private $closeoutService;
public function __construct(
CloseoutService $closeoutService
)
{
$this->closeoutService = $closeoutService;
}
public static function getSubscribedEvents(): array
{
return [
ProductEvents::PRODUCT_CONFIGURATOR_SETTING_LOADED_EVENT => 'onProductConfiguratorSettingLoaded'
// ProductPageLoadedEvent::class => 'onProductPageLoadedEvent'
];
}
public function onProductConfiguratorSettingLoaded(EntityLoadedEvent $event): void
{
if ($event->getContext()->getScope() === Context::USER_SCOPE) {
$event = $this->closeoutService->getCloseoutOptions($event);
}
}
/*
public function onProductPageLoadedEvent(ProductPageLoadedEvent $event): void
{
$cogiConfiguratorSettings = $this->closeoutService->getCloseoutOptionsPageLoaded($event);
$event->getPage()->setConfiguratorSettings($cogiConfiguratorSettings);
}
*/
}