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

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (c) 2020, Net Inventors GmbH
  4.  * @category  Shopware
  5.  * @author    mpeters
  6.  */
  7. declare(strict_types=1);
  8. namespace NetInventors\NetiNextEasyCoupon\Subscriber;
  9. use NetInventors\NetiNextEasyCoupon\Service\PluginConfig;
  10. use NetInventors\NetiNextEasyCoupon\Service\ProductService;
  11. use Shopware\Core\System\SalesChannel\Entity\SalesChannelEntityLoadedEvent;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class SalesChannelSubscriber implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * @var PluginConfig
  17.      */
  18.     private $pluginConfig;
  19.     /**
  20.      * @var ProductService
  21.      */
  22.     private $productService;
  23.     public function __construct(
  24.         PluginConfig $pluginConfig,
  25.         ProductService $productService
  26.     ) {
  27.         $this->pluginConfig   $pluginConfig;
  28.         $this->productService $productService;
  29.     }
  30.     public static function getSubscribedEvents(): array
  31.     {
  32.         return [
  33.             'sales_channel.product.loaded' => 'onSalesChannelProductLoaded',
  34.         ];
  35.     }
  36.     public function onSalesChannelProductLoaded(SalesChannelEntityLoadedEvent $event): void
  37.     {
  38.         if (!$this->pluginConfig->isActive()) {
  39.             return;
  40.         }
  41.         $this->productService->setPriceRanges($event->getEntities(), $event->getSalesChannelContext()->getCurrency()->getId());
  42.     }
  43. }