custom/plugins/NetiNextEasyCoupon/src/Subscriber/SalesChannelSubscriber.php line 33

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextEasyCoupon\Subscriber;
  4. use NetInventors\NetiNextEasyCoupon\Service\ProductService;
  5. use NetInventors\NetiNextEasyCoupon\Struct\PluginConfigStruct;
  6. use Shopware\Core\System\SalesChannel\Entity\SalesChannelEntityLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class SalesChannelSubscriber implements EventSubscriberInterface
  9. {
  10.     private PluginConfigStruct $pluginConfig;
  11.     private ProductService     $productService;
  12.     public function __construct(
  13.         PluginConfigStruct $pluginConfig,
  14.         ProductService     $productService
  15.     ) {
  16.         $this->pluginConfig   $pluginConfig;
  17.         $this->productService $productService;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             'sales_channel.product.loaded' => 'onSalesChannelProductLoaded',
  23.         ];
  24.     }
  25.     public function onSalesChannelProductLoaded(SalesChannelEntityLoadedEvent $event): void
  26.     {
  27.         if (!$this->pluginConfig->isActive()) {
  28.             return;
  29.         }
  30.         $this->productService->setPriceRanges($event->getEntities(), $event->getSalesChannelContext()->getCurrency()->getId());
  31.     }
  32. }