vendor/store.shopware.com/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 $variantBadgeColor
  32.          * @var string $stockBadgeColor
  33.          * @var string $salesBadgeColor
  34.          * @var string $discountBadgeColor
  35.          * @var string $closeoutBadgeColor
  36.          * @var string $shippingfreeBadgeColor
  37.          * @var string $topsellerBadgeColor
  38.          * @var string $newBadgeColor
  39.          * @var string $releaseBadgeColor
  40.          * @var string $preorderBadgeColor
  41.          * @var string $manufacturerBadgeColor
  42.          * @var string $custom1BadgeColor
  43.          * @var string $custom2BadgeColor
  44.          * @var string $custom3BadgeColor
  45.          */
  46.         $variantBadgeColor $this->systemConfig->get($this->configPath 'variantBadgeColor'$shopId);
  47.         $stockBadgeColor $this->systemConfig->get($this->configPath 'stockBadgeColor'$shopId);
  48.         $salesBadgeColor $this->systemConfig->get($this->configPath 'salesBadgeColor'$shopId);
  49.         $discountBadgeColor $this->systemConfig->get($this->configPath 'discountBadgeColor'$shopId);
  50.         $closeoutBadgeColor $this->systemConfig->get($this->configPath 'closeoutBadgeColor'$shopId);
  51.         $shippingfreeBadgeColor $this->systemConfig->get($this->configPath 'shippingfreeBadgeColor'$shopId);
  52.         $topsellerBadgeColor $this->systemConfig->get($this->configPath 'topsellerBadgeColor'$shopId);
  53.         $newBadgeColor $this->systemConfig->get($this->configPath 'newBadgeColor'$shopId);
  54.         $releaseBadgeColor $this->systemConfig->get($this->configPath 'releaseBadgeColor'$shopId);
  55.         $preorderBadgeColor $this->systemConfig->get($this->configPath 'preorderBadgeColor'$shopId);
  56.         $manufacturerBadgeColor $this->systemConfig->get($this->configPath 'manufacturerBadgeColor'$shopId);
  57.         $custom1BadgeColor $this->systemConfig->get($this->configPath 'custom1BadgeColor'$shopId);
  58.         $custom2BadgeColor $this->systemConfig->get($this->configPath 'custom2BadgeColor'$shopId);
  59.         $custom3BadgeColor $this->systemConfig->get($this->configPath 'custom3BadgeColor'$shopId);
  60.         if (isset($variantBadgeColor) && !empty($variantBadgeColor)) {
  61.             $event->addVariable('zen-data-badges-variant-color'$variantBadgeColor);
  62.         } else {
  63.             $event->addVariable('zen-data-badges-variant-color''#bcc1c7');
  64.         };
  65.         if (isset($stockBadgeColor) && !empty($stockBadgeColor)) {
  66.             $event->addVariable('zen-data-badges-stock-color'$stockBadgeColor);
  67.         } else {
  68.             $event->addVariable('zen-data-badges-stock-color''#5f7285');
  69.         };
  70.         if (isset($salesBadgeColor) && !empty($salesBadgeColor)) {
  71.             $event->addVariable('zen-data-badges-sales-color'$salesBadgeColor);
  72.         } else {
  73.             $event->addVariable('zen-data-badges-sales-color''#e52427');
  74.         };
  75.         if (isset($discountBadgeColor) && !empty($discountBadgeColor)) {
  76.             $event->addVariable('zen-data-badges-discount-color'$discountBadgeColor);
  77.         } else {
  78.             $event->addVariable('zen-data-badges-discount-color''#e52427');
  79.         };
  80.         if (isset($closeoutBadgeColor) && !empty($closeoutBadgeColor)) {
  81.             $event->addVariable('zen-data-badges-close-out-color'$closeoutBadgeColor);
  82.         } else {
  83.             $event->addVariable('zen-data-badges-close-out-color''#e74c3c');
  84.         };
  85.         if (isset($shippingfreeBadgeColor) && !empty($shippingfreeBadgeColor)) {
  86.             $event->addVariable('zen-data-badges-shipping-free-color'$shippingfreeBadgeColor);
  87.         } else {
  88.             $event->addVariable('zen-data-badges-shipping-free-color''#2ecc71');
  89.         };
  90.         if (isset($topsellerBadgeColor) && !empty($topsellerBadgeColor)) {
  91.             $event->addVariable('zen-data-badges-topseller-color'$topsellerBadgeColor);
  92.         } else {
  93.             $event->addVariable('zen-data-badges-topseller-color''#ffbd5d');
  94.         };
  95.         if (isset($newBadgeColor) && !empty($newBadgeColor)) {
  96.             $event->addVariable('zen-data-badges-new-color'$newBadgeColor);
  97.         } else {
  98.             $event->addVariable('zen-data-badges-new-color''#3cc261');
  99.         };
  100.         if (isset($releaseBadgeColor) && !empty($releaseBadgeColor)) {
  101.             $event->addVariable('zen-data-badges-release-color'$releaseBadgeColor);
  102.         } else {
  103.             $event->addVariable('zen-data-badges-release-color''#ffbd5d');
  104.         };
  105.         if (isset($preorderBadgeColor) && !empty($preorderBadgeColor)) {
  106.             $event->addVariable('zen-data-badges-preorder-color'$preorderBadgeColor);
  107.         } else {
  108.             $event->addVariable('zen-data-badges-preorder-color''#ffbd5d');
  109.         };
  110.         if (isset($manufacturerBadgeColor) && !empty($manufacturerBadgeColor)) {
  111.             $event->addVariable('zen-data-badges-manufacturer-color'$manufacturerBadgeColor);
  112.         } else {
  113.             $event->addVariable('zen-data-badges-manufacturer-color''#5f7285');
  114.         };
  115.         if (isset($custom1BadgeColor) && !empty($custom1BadgeColor)) {
  116.             $event->addVariable('zen-data-badges-custom-first-color'$custom1BadgeColor);
  117.         } else {
  118.             $event->addVariable('zen-data-badges-custom-first-color''#f1c40f');
  119.         };
  120.         if (isset($custom2BadgeColor) && !empty($custom2BadgeColor)) {
  121.             $event->addVariable('zen-data-badges-custom-second-color'$custom2BadgeColor);
  122.         } else {
  123.             $event->addVariable('zen-data-badges-custom-second-color''#f1c40f');
  124.         };
  125.         if (isset($custom3BadgeColor) && !empty($custom3BadgeColor)) {
  126.             $event->addVariable('zen-data-badges-custom-third-color'$custom3BadgeColor);
  127.         } else {
  128.             $event->addVariable('zen-data-badges-custom-third-color''#f1c40f');
  129.         };
  130.         /**
  131.          * @var string $listingsFontSize
  132.          * @var string $listingsRadiusLeft
  133.          * @var string $listingsRadiusRight
  134.          * @var string $listingsPadding
  135.          * @var string $listingsMarginLeft
  136.          */
  137.         $listingsFontSize $this->systemConfig->get($this->configPath 'listingsFontSize'$shopId);
  138.         $listingsRadiusLeft $this->systemConfig->get($this->configPath 'listingsRadiusLeft'$shopId) ?? '0';
  139.         $listingsRadiusRight $this->systemConfig->get($this->configPath 'listingsRadiusRight'$shopId) ?? '0';
  140.         $listingsPadding $this->systemConfig->get($this->configPath 'listingsPadding'$shopId) ?? '0';
  141.         $listingsPaddingVertical = ($listingsPadding >= 5) ? (int)$listingsPadding '0';
  142.         $listingsMarginLeft = ($listingsRadiusLeft 0) ? '10' '0';
  143.         $event->addVariable('zen-data-badges-listings-font-size'$listingsFontSize 'px');
  144.         $event->addVariable('zen-data-badges-listings-height', (int)$listingsFontSize 'px');
  145.         $event->addVariable('zen-data-badges-listings-radius-left'$listingsRadiusLeft 'px');
  146.         $event->addVariable('zen-data-badges-listings-radius-right'$listingsRadiusRight 'px');
  147.         $event->addVariable('zen-data-badges-listings-padding-horizontal'$listingsPadding 'px');
  148.         $event->addVariable('zen-data-badges-listings-padding-vertical'$listingsPaddingVertical'px');
  149.         $event->addVariable('zen-data-badges-listings-margin-left'$listingsMarginLeft 'px');
  150.         /**
  151.          * @var string $detailsFontSize
  152.          * @var string $detailsRadiusLeft
  153.          * @var string $detailsRadiusRight
  154.          * @var string $detailsPadding
  155.          * @var string $detailsMarginLeft
  156.          */
  157.         $detailsFontSize $this->systemConfig->get($this->configPath 'detailsFontSize'$shopId);
  158.         $detailsRadiusLeft $this->systemConfig->get($this->configPath 'detailsRadiusLeft'$shopId) ?? '0';
  159.         $detailsRadiusRight $this->systemConfig->get($this->configPath 'detailsRadiusRight'$shopId) ?? '0';
  160.         $detailsPadding $this->systemConfig->get($this->configPath 'detailsPadding'$shopId) ?? '0';
  161.         $detailsPaddingVertical = ($detailsPadding >= 5) ? (int)$detailsPadding '0';
  162.         $detailsMarginLeft = ($detailsRadiusLeft 0) ? '10' '0';
  163.         $event->addVariable('zen-data-badges-details-font-size'$detailsFontSize 'px');
  164.         $event->addVariable('zen-data-badges-details-height', (int)$detailsFontSize 'px');
  165.         $event->addVariable('zen-data-badges-details-radius-left'$detailsRadiusLeft 'px');
  166.         $event->addVariable('zen-data-badges-details-radius-right'$detailsRadiusRight 'px');
  167.         $event->addVariable('zen-data-badges-details-padding-horizontal'$detailsPadding 'px');
  168.         $event->addVariable('zen-data-badges-details-padding-vertical'$detailsPaddingVertical 'px');
  169.         $event->addVariable('zen-data-badges-details-margin-left'$detailsMarginLeft 'px');
  170.     }
  171. }