custom/plugins/ZweiPunktVariantsTableOverview/src/Subscriber/AddConfigToView.php line 30

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace ZweiPunktVariantsTableOverview\Subscriber;
  3. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Shopware\Core\System\SystemConfig\SystemConfigService;
  6. use ZweiPunktVariantsTableOverview\ZweiPunktVariantsTableOverview;
  7. class AddConfigToView implements EventSubscriberInterface
  8. {
  9.     private $systemConfigService;
  10.     public function __construct(SystemConfigService $systemConfigService)
  11.     {
  12.         // Get system config
  13.         $this->systemConfigService $systemConfigService;
  14.     }
  15.     /**
  16.      * @return array
  17.      */
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             ProductPageLoadedEvent::class => 'onPageLoaded'
  22.         ];
  23.     }
  24.     public function onPageLoaded(ProductPageLoadedEvent $event): void
  25.     {
  26.         // Get sales channel id
  27.         $salesChannelId $event->getSaleschannelContext()->getSalesChannelId();
  28.         // Get plugin configuration
  29.         $pluginConfig $this->systemConfigService
  30.             ->get(ZweiPunktVariantsTableOverview::PLUGIN_NAME '.config'$salesChannelId);
  31.         $event->getPage()->assign(['zweiPunktVariantTableConfig' => $pluginConfig]);
  32.     }
  33. }