<?php declare(strict_types=1);
namespace Huebert\SeoUltimate\Subscriber;
use Shopware\Core\Defaults;
use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\System\SystemConfig\SystemConfigService;
class ThemeVariablesSubscriber implements EventSubscriberInterface
{
/*
* @var SystemConfigService
*/
private $systemConfig;
// add the `SystemConfigService` to your constructor
public function __construct(SystemConfigService $systemConfig)
{
$this->systemConfig = $systemConfig;
}
public static function getSubscribedEvents(): array
{
return [
ThemeCompilerEnrichScssVariablesEvent::class => 'onAddVariables'
];
}
public function onAddVariables(ThemeCompilerEnrichScssVariablesEvent $event)
{
$languageId = Defaults::LANGUAGE_SYSTEM;
$newsletterColorBg = $this->systemConfig->get('HuebertSeoUltimate.config.conversion.newsletter.'.$languageId.'.colorBg', $event->getSalesChannelId());
$newsletterColorText = $this->systemConfig->get('HuebertSeoUltimate.config.conversion.newsletter.'.$languageId.'.colorText', $event->getSalesChannelId());
if($newsletterColorBg) {$event->addVariable('hueb-seo-newsletter-colorBg', $newsletterColorBg);}
if($newsletterColorText) {$event->addVariable('hueb-seo-newsletter-colorText', $newsletterColorText);}
$headerColorBg = $this->systemConfig->get('HuebertSeoUltimate.config.conversion.header.'.$languageId.'.colorBg', $event->getSalesChannelId());
$headerColorText = $this->systemConfig->get('HuebertSeoUltimate.config.conversion.header.'.$languageId.'.colorText', $event->getSalesChannelId());
if($headerColorBg) {$event->addVariable('hueb-seo-header-colorBg', $headerColorBg);}
if($headerColorText) {$event->addVariable('hueb-seo-header-colorText', $headerColorText);}
$socialmediaColorBg = $this->systemConfig->get('HuebertSeoUltimate.config.conversion.socialmedia.'.$languageId.'.colorBg', $event->getSalesChannelId());
$socialmediaColorText = $this->systemConfig->get('HuebertSeoUltimate.config.conversion.socialmedia.'.$languageId.'.colorText', $event->getSalesChannelId());
if($socialmediaColorBg) {$event->addVariable('hueb-seo-socialmedia-colorBg', $socialmediaColorBg);}
if($socialmediaColorText) {$event->addVariable('hueb-seo-socialmedia-colorText', $socialmediaColorText);}
}
}