<?php declare(strict_types=1);
namespace zenit\PlatformShippingBar\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 = 'zenitPlatformShippingBar.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 $textColor
* @var string $textHoverColor
* @var string $backgroundColor
*/
$textColor = $this->systemConfig->get($this->configPath . 'textColor', $shopId);
$textHoverColor = $this->systemConfig->get($this->configPath . 'textHoverColor', $shopId);
$backgroundColor = $this->systemConfig->get($this->configPath . 'backgroundColor', $shopId);
/**
* @var string $fontSize
*/
$fontSize = $this->systemConfig->get($this->configPath . 'fontSize', $shopId);
/**
* @var string $padding
*/
$padding = $this->systemConfig->get($this->configPath . 'padding', $shopId) ?? '0';
$event->addVariable('zen-shipping-bar-text-color', $textColor);
$event->addVariable('zen-shipping-bar-text-hover-color', $textHoverColor);
$event->addVariable('zen-shipping-bar-background-color', $backgroundColor);
$event->addVariable('zen-shipping-bar-font-size', $fontSize . 'px');
$event->addVariable('zen-shipping-bar-icon-size', $fontSize * 1.5 . 'px');
$event->addVariable('zen-shipping-bar-line-height', $fontSize * 1.5 . 'px');
$event->addVariable('zen-shipping-bar-padding-vertical', $padding . 'px');
$event->addVariable('zen-shipping-bar-padding-horizontal', $padding * 0.75 . 'px');
$event->addVariable('zen-shipping-bar-padding-vertical-item', $fontSize * 0.25 . 'px');
$event->addVariable('zen-shipping-bar-padding-horizontal-item', $fontSize * 0.5 . 'px');
$event->addVariable('zen-shipping-bar-margin', $fontSize * 0.25 . 'px');
$event->addVariable('zen-shipping-bar-margin-negative', $fontSize * -0.25 . 'px');
}
}