custom/plugins/zenitPlatformShippingBar/src/Subscriber/ThemeVariablesSubscriber.php line 34

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace zenit\PlatformShippingBar\Subscriber;
  3. use Shopware\Core\System\SystemConfig\SystemConfigService;
  4. use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class ThemeVariablesSubscriber implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @var string
  10.      */
  11.     private $configPath 'zenitPlatformShippingBar.config.';
  12.     /**
  13.      * @var SystemConfigService
  14.      */
  15.     protected $systemConfig;
  16.     // add the `SystemConfigService` to your constructor
  17.     public function __construct(SystemConfigService $systemConfig)
  18.     {
  19.         $this->systemConfig $systemConfig;
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             ThemeCompilerEnrichScssVariablesEvent::class => 'onAddVariables'
  25.         ];
  26.     }
  27.     public function onAddVariables(ThemeCompilerEnrichScssVariablesEvent $event)
  28.     {
  29.         $shopId $event->getSalesChannelId();
  30.         /**
  31.          * @var string $textColor
  32.          * @var string $textHoverColor
  33.          * @var string $backgroundColor
  34.          */
  35.         $textColor $this->systemConfig->get($this->configPath 'textColor'$shopId);
  36.         $textHoverColor $this->systemConfig->get($this->configPath 'textHoverColor'$shopId);
  37.         $backgroundColor $this->systemConfig->get($this->configPath 'backgroundColor'$shopId);
  38.         /**
  39.          * @var string $fontSize
  40.          */
  41.         $fontSize $this->systemConfig->get($this->configPath 'fontSize'$shopId);
  42.         /**
  43.          * @var string $padding
  44.          */
  45.         $padding $this->systemConfig->get($this->configPath 'padding'$shopId) ?? '0';
  46.         $event->addVariable('zen-shipping-bar-text-color'$textColor);
  47.         $event->addVariable('zen-shipping-bar-text-hover-color'$textHoverColor);
  48.         $event->addVariable('zen-shipping-bar-background-color'$backgroundColor);
  49.         $event->addVariable('zen-shipping-bar-font-size'$fontSize 'px');
  50.         $event->addVariable('zen-shipping-bar-icon-size'$fontSize 1.5 'px');
  51.         $event->addVariable('zen-shipping-bar-line-height'$fontSize 1.5 'px');
  52.         $event->addVariable('zen-shipping-bar-padding-vertical'$padding 'px');
  53.         $event->addVariable('zen-shipping-bar-padding-horizontal'$padding 0.75 'px');
  54.         $event->addVariable('zen-shipping-bar-padding-vertical-item'$fontSize 0.25 'px');
  55.         $event->addVariable('zen-shipping-bar-padding-horizontal-item'$fontSize 0.5 'px');
  56.         $event->addVariable('zen-shipping-bar-margin'$fontSize 0.25 'px');
  57.         $event->addVariable('zen-shipping-bar-margin-negative'$fontSize * -0.25 'px');
  58.     }
  59. }