<?php
declare(strict_types=1);
namespace NetInventors\NetiNextEasyCoupon\Subscriber;
use NetInventors\NetiNextEasyCoupon\Service\ProductService;
use NetInventors\NetiNextEasyCoupon\Struct\PluginConfigStruct;
use Shopware\Core\System\SalesChannel\Entity\SalesChannelEntityLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class SalesChannelSubscriber implements EventSubscriberInterface
{
private PluginConfigStruct $pluginConfig;
private ProductService $productService;
public function __construct(
PluginConfigStruct $pluginConfig,
ProductService $productService
) {
$this->pluginConfig = $pluginConfig;
$this->productService = $productService;
}
public static function getSubscribedEvents(): array
{
return [
'sales_channel.product.loaded' => 'onSalesChannelProductLoaded',
];
}
public function onSalesChannelProductLoaded(SalesChannelEntityLoadedEvent $event): void
{
if (!$this->pluginConfig->isActive()) {
return;
}
$this->productService->setPriceRanges($event->getEntities(), $event->getSalesChannelContext()->getCurrency()->getId());
}
}