<?php
namespace Maxia\MaxiaListingVariants6\Subscriber;
use Maxia\MaxiaListingVariants6\Service\ConfigService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Storefront\Event\ThemeCompilerEnrichScssVariablesEvent;
use Shopware\Core\DevOps\Environment\EnvironmentHelper;
class ScssVariablesSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
ThemeCompilerEnrichScssVariablesEvent::class => 'onAddVariables'
];
}
private ConfigService $configService;
public function __construct(ConfigService $configService)
{
$this->configService = $configService;
}
public function onAddVariables(ThemeCompilerEnrichScssVariablesEvent $event)
{
$databaseUrl = EnvironmentHelper::getVariable('DATABASE_URL', getenv('DATABASE_URL'));
if (!$databaseUrl || $databaseUrl === 'mysql://_placeholder.test') {
// deployment server without database
return;
}
$prefix = 'maxia-listing-variants-';
$config = $this->configService->getBaseConfig($event->getSalesChannelId());
if ($config->getBuyButtonHeight()) {
$event->addVariable($prefix . 'actions-height', $config->getBuyButtonHeight());
}
if ($config->getMediaOptionHeight()) {
$event->addVariable($prefix . 'media-option-height', $config->getMediaOptionHeight());
}
if ($config->getColorOptionHeight()) {
$event->addVariable($prefix . 'color-option-height', $config->getColorOptionHeight());
}
if ($config->isAlignCenter() !== null) {
$event->addVariable($prefix . 'align-center', $config->isAlignCenter() ? 'true' : 'false');
}
if ($config->isUseFlexProductBox() !== null) {
$event->addVariable($prefix . 'use-flex', $config->isUseFlexProductBox() ? 'true' : 'false');
}
if ($config->isSwitchImageOnHover() !== null) {
$event->addVariable($prefix . 'switch-image-on-mobile', $config->isSwitchImageOnHover() ? 'true' : 'false');
}
}
}