<?php declare(strict_types=1);
namespace ZweiPunktVariantsTableOverview\Subscriber;
use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use ZweiPunktVariantsTableOverview\ZweiPunktVariantsTableOverview;
class AddConfigToView implements EventSubscriberInterface
{
private $systemConfigService;
public function __construct(SystemConfigService $systemConfigService)
{
// Get system config
$this->systemConfigService = $systemConfigService;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
ProductPageLoadedEvent::class => 'onPageLoaded'
];
}
public function onPageLoaded(ProductPageLoadedEvent $event): void
{
// Get sales channel id
$salesChannelId = $event->getSaleschannelContext()->getSalesChannelId();
// Get plugin configuration
$pluginConfig = $this->systemConfigService
->get(ZweiPunktVariantsTableOverview::PLUGIN_NAME . '.config', $salesChannelId);
$event->getPage()->assign(['zweiPunktVariantTableConfig' => $pluginConfig]);
}
}