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

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