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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace zenit\PlatformDataBadges\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 'zenitPlatformDataBadges.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 $shippingfreeBadgeColor
  32.          * @var string $variantBadgeColor
  33.          * @var string $stockBadgeColor
  34.          * @var string $closeoutBadgeColor
  35.          * @var string $manufacturerBadgeColor
  36.          * @var string $custom1BadgeColor
  37.          * @var string $custom2BadgeColor
  38.          * @var string $custom3BadgeColor
  39.          */
  40.         $shippingfreeBadgeColor $this->systemConfig->get($this->configPath 'shippingfreeBadgeColor'$shopId);
  41.         $variantBadgeColor $this->systemConfig->get($this->configPath 'variantBadgeColor'$shopId);
  42.         $stockBadgeColor $this->systemConfig->get($this->configPath 'stockBadgeColor'$shopId);
  43.         $closeoutBadgeColor $this->systemConfig->get($this->configPath 'closeoutBadgeColor'$shopId);
  44.         $manufacturerBadgeColor $this->systemConfig->get($this->configPath 'manufacturerBadgeColor'$shopId);
  45.         $custom1BadgeColor $this->systemConfig->get($this->configPath 'custom1BadgeColor'$shopId);
  46.         $custom2BadgeColor $this->systemConfig->get($this->configPath 'custom2BadgeColor'$shopId);
  47.         $custom3BadgeColor $this->systemConfig->get($this->configPath 'custom3BadgeColor'$shopId);
  48.         if (isset($shippingfreeBadgeColor) && !empty($shippingfreeBadgeColor)) {
  49.             $event->addVariable('databadges-shipping-free-color'$shippingfreeBadgeColor);
  50.         } else {
  51.             $event->addVariable('databadges-shipping-free-color''#333333');
  52.         };
  53.         if (isset($variantBadgeColor) && !empty($variantBadgeColor)) {
  54.             $event->addVariable('databadges-variant-color'$variantBadgeColor);
  55.         } else {
  56.             $event->addVariable('databadges-variant-color''#333333');
  57.         };
  58.         if (isset($stockBadgeColor) && !empty($stockBadgeColor)) {
  59.             $event->addVariable('databadges-stock-color'$stockBadgeColor);
  60.         } else {
  61.             $event->addVariable('databadges-stock-color''#333333');
  62.         };
  63.         if (isset($closeoutBadgeColor) && !empty($closeoutBadgeColor)) {
  64.             $event->addVariable('databadges-close-out-color'$closeoutBadgeColor);
  65.         } else {
  66.             $event->addVariable('databadges-close-out-color''#333333');
  67.         };
  68.         if (isset($manufacturerBadgeColor) && !empty($manufacturerBadgeColor)) {
  69.             $event->addVariable('databadges-manufacturer-color'$manufacturerBadgeColor);
  70.         } else {
  71.             $event->addVariable('databadges-manufacturer-color''#333333');
  72.         };
  73.         if (isset($custom1BadgeColor) && !empty($custom1BadgeColor)) {
  74.             $event->addVariable('databadges-custom-first-color'$custom1BadgeColor);
  75.         } else {
  76.             $event->addVariable('databadges-custom-first-color''#333333');
  77.         };
  78.         if (isset($custom2BadgeColor) && !empty($custom2BadgeColor)) {
  79.             $event->addVariable('databadges-custom-second-color'$custom2BadgeColor);
  80.         } else {
  81.             $event->addVariable('databadges-custom-second-color''#333333');
  82.         };
  83.         if (isset($custom3BadgeColor) && !empty($custom3BadgeColor)) {
  84.             $event->addVariable('databadges-custom-third-color'$custom3BadgeColor);
  85.         } else {
  86.             $event->addVariable('databadges-custom-third-color''#333333');
  87.         };
  88.         /**
  89.          * @var string $listingsFontSize
  90.          * @var string $listingsRadiusLeft
  91.          * @var string $listingsRadiusRight
  92.          * @var string $listingsPadding
  93.          * @var string $listingsMarginLeft
  94.          */
  95.         $listingsFontSize $this->systemConfig->get($this->configPath 'listingsFontSize'$shopId);
  96.         $listingsRadiusLeft $this->systemConfig->get($this->configPath 'listingsRadiusLeft'$shopId) ?? '0';
  97.         $listingsRadiusRight $this->systemConfig->get($this->configPath 'listingsRadiusRight'$shopId) ?? '0';
  98.         $listingsPadding $this->systemConfig->get($this->configPath 'listingsPadding'$shopId) ?? '0';
  99.         $listingsPaddingVertical = ($listingsPadding >= 5) ? (int)$listingsPadding '0';
  100.         $listingsMarginLeft = ($listingsRadiusLeft 0) ? '10' '0';
  101.         $event->addVariable('databadges-listings-font-size'$listingsFontSize 'px');
  102.         $event->addVariable('databadges-listings-height', (int)$listingsFontSize 'px');
  103.         $event->addVariable('databadges-listings-radius-left'$listingsRadiusLeft 'px');
  104.         $event->addVariable('databadges-listings-radius-right'$listingsRadiusRight 'px');
  105.         $event->addVariable('databadges-listings-padding-horizontal'$listingsPadding 'px');
  106.         $event->addVariable('databadges-listings-padding-vertical'$listingsPaddingVertical'px');
  107.         $event->addVariable('databadges-listings-margin-left'$listingsMarginLeft 'px');
  108.         /**
  109.          * @var string $detailsFontSize
  110.          * @var string $detailsRadiusLeft
  111.          * @var string $detailsRadiusRight
  112.          * @var string $detailsPadding
  113.          * @var string $detailsMarginLeft
  114.          */
  115.         $detailsFontSize $this->systemConfig->get($this->configPath 'detailsFontSize'$shopId);
  116.         $detailsRadiusLeft $this->systemConfig->get($this->configPath 'detailsRadiusLeft'$shopId) ?? '0';
  117.         $detailsRadiusRight $this->systemConfig->get($this->configPath 'detailsRadiusRight'$shopId) ?? '0';
  118.         $detailsPadding $this->systemConfig->get($this->configPath 'detailsPadding'$shopId) ?? '0';
  119.         $detailsPaddingVertical = ($detailsPadding >= 5) ? (int)$detailsPadding '0';
  120.         $detailsMarginLeft = ($detailsRadiusLeft 0) ? '10' '0';
  121.         $event->addVariable('databadges-details-font-size'$detailsFontSize 'px');
  122.         $event->addVariable('databadges-details-height', (int)$detailsFontSize 'px');
  123.         $event->addVariable('databadges-details-radius-left'$detailsRadiusLeft 'px');
  124.         $event->addVariable('databadges-details-radius-right'$detailsRadiusRight 'px');
  125.         $event->addVariable('databadges-details-padding-horizontal'$detailsPadding 'px');
  126.         $event->addVariable('databadges-details-padding-vertical'$detailsPaddingVertical 'px');
  127.         $event->addVariable('databadges-details-margin-left'$detailsMarginLeft 'px');
  128.     }
  129. }