custom/plugins/MaxiaListingVariants6/src/Subscriber/ScssVariablesSubscriber.php line 26

Open in your IDE?
  1. <?php
  2. namespace Maxia\MaxiaListingVariants6\Subscriber;
  3. use Maxia\MaxiaListingVariants6\Service\ConfigService;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
  6. use Shopware\Core\DevOps\Environment\EnvironmentHelper;
  7. class ScssVariablesSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents(): array
  10.     {
  11.         return [
  12.             ThemeCompilerEnrichScssVariablesEvent::class => 'onAddVariables'
  13.         ];
  14.     }
  15.     private ConfigService $configService;
  16.     public function __construct(ConfigService $configService)
  17.     {
  18.         $this->configService $configService;
  19.     }
  20.     public function onAddVariables(ThemeCompilerEnrichScssVariablesEvent $event)
  21.     {
  22.         $databaseUrl EnvironmentHelper::getVariable('DATABASE_URL'getenv('DATABASE_URL'));
  23.         if (!$databaseUrl || $databaseUrl === 'mysql://_placeholder.test') {
  24.             // deployment server without database
  25.             return;
  26.         }
  27.         $prefix 'maxia-listing-variants-';
  28.         $config $this->configService->getBaseConfig($event->getSalesChannelId());
  29.         if ($config->getBuyButtonHeight()) {
  30.             $event->addVariable($prefix 'actions-height'$config->getBuyButtonHeight());
  31.         }
  32.         if ($config->getMediaOptionHeight()) {
  33.             $event->addVariable($prefix 'media-option-height'$config->getMediaOptionHeight());
  34.         }
  35.         if ($config->getColorOptionHeight()) {
  36.             $event->addVariable($prefix 'color-option-height'$config->getColorOptionHeight());
  37.         }
  38.         if ($config->isAlignCenter() !== null) {
  39.             $event->addVariable($prefix 'align-center'$config->isAlignCenter() ? 'true' 'false');
  40.         }
  41.         if ($config->isUseFlexProductBox() !== null) {
  42.             $event->addVariable($prefix 'use-flex'$config->isUseFlexProductBox() ? 'true' 'false');
  43.         }
  44.         if ($config->isSwitchImageOnHover() !== null) {
  45.             $event->addVariable($prefix 'switch-image-on-mobile'$config->isSwitchImageOnHover() ? 'true' 'false');
  46.         }
  47.     }
  48. }