<?php declare(strict_types=1);
namespace zenit\PlatformFeaturesBar\Subscriber;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ThemeVariablesSubscriber implements EventSubscriberInterface
{
/**
* @var string
*/
private $configPath = 'zenitPlatformFeaturesBar.config.';
/**
* @var SystemConfigService
*/
protected $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)
{
$shopId = $event->getSalesChannelId();
/**
* @var string $fontSize
* @var string $textColor
* @var string $textColorHover
* @var string $backgroundColor
* @var string $columnBackgroundColor
*/
$fontSize = $this->systemConfig->get($this->configPath . 'fontSize', $shopId);
$textColor = $this->systemConfig->get($this->configPath . 'textColor', $shopId);
$textColorHover = $this->systemConfig->get($this->configPath . 'textColorHover', $shopId);
$backgroundColor = $this->systemConfig->get($this->configPath . 'backgroundColor', $shopId);
$columnBackgroundColor = $this->systemConfig->get($this->configPath . 'columnBackgroundColor', $shopId);
/**
* @var string $borderRadius
*/
$borderRadius = $this->systemConfig->get($this->configPath . 'borderRadius', $shopId) ?? '0';
/**
* @var string $fontSize
* @var string $iconFont
*/
$iconSize = $this->systemConfig->get($this->configPath . 'iconSize', $shopId);
$iconFont = $this->systemConfig->get($this->configPath . 'iconFont', $shopId);
/**
* @var string $padding
*/
$padding = $this->systemConfig->get($this->configPath . 'padding', $shopId) ?? '0';
$event->addVariable('zen-features-bar-font-size', $fontSize . 'px');
$event->addVariable('zen-features-bar-text-color', $textColor);
$event->addVariable('zen-features-bar-text-color-hover', $textColorHover);
$event->addVariable('zen-features-bar-background-color', $backgroundColor);
$event->addVariable('zen-features-bar-background-color-column', $columnBackgroundColor);
$event->addVariable('zen-features-bar-border-radius', $borderRadius . 'px');
$event->addVariable('zen-features-bar-icon-size', $iconSize . 'px');
$event->addVariable('zen-features-bar-icon-font', $iconFont);
$event->addVariable('zen-features-bar-padding', $padding . 'px');
$event->addVariable('zen-features-bar-element-height', ($padding * 2) + ($fontSize * 1.5) . 'px');
}
}