vendor/lnb/shopware6-lnb-trusted-shops-rates/src/Subscriber/FrontEndSubscriber.php line 39

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Lnb\Shopware6\LnbTrustedShopsRates\Subscriber;
  4. use Lnb\Shopware6\LnbTrustedShopsRates\Service\TrustedShopsService;
  5. use Lnb\Shopware6\LnbTrustedShopsRates\Struct\TrustedShopsRates;
  6. use Shopware\Core\System\SystemConfig\SystemConfigService;
  7. use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
  8. use Shopware\Storefront\Pagelet\Header\HeaderPageletLoadedEvent;
  9. use Symfony\Component\DependencyInjection\ContainerInterface;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class FrontEndSubscriber implements EventSubscriberInterface
  12. {
  13.     protected ContainerInterface $container;
  14.     protected TrustedShopsService $service;
  15.     protected SystemConfigService $systemConfigService;
  16.     public function __construct(
  17.         ContainerInterface $container,
  18.         TrustedShopsService $service,
  19.         SystemConfigService $systemConfigService,
  20.     ) {
  21.         $this->container $container;
  22.         $this->service $service;
  23.         $this->systemConfigService $systemConfigService;
  24.     }
  25.     public static function getSubscribedEvents()
  26.     {
  27.         return [
  28.             HeaderPageletLoadedEvent::class => ['onHeaderPageletLoaded'],
  29.             FooterPageletLoadedEvent::class => ['onFooterPageletLoaded'],
  30.         ];
  31.     }
  32.     public function onFooterPageletLoaded(FooterPageletLoadedEvent $event)
  33.     {
  34.         $footerEnabled $this->systemConfigService->get('LnbTrustedShopsRates.config.enableFooter');
  35.         if (!$footerEnabled) {
  36.             return null;
  37.         }
  38.         $rates $this->service->loadAndSaveTrustedShopsRates();
  39.         if (!$rates) {
  40.             return;
  41.         }
  42.         $trustedShopsRates = new TrustedShopsRates($rates);
  43.         $event->getPagelet()->addExtension('trustedShops'$trustedShopsRates);
  44.     }
  45.     public function onHeaderPageletLoaded(HeaderPageletLoadedEvent $event)
  46.     {
  47.         $headerEnabled $this->systemConfigService->get('LnbTrustedShopsRates.config.enableHeader');
  48.         if (!$headerEnabled) {
  49.             return null;
  50.         }
  51.         $rates $this->service->loadAndSaveTrustedShopsRates();
  52.         if (!$rates) {
  53.             return;
  54.         }
  55.         $trustedShopsRates = new TrustedShopsRates($rates);
  56.         $event->getPagelet()->addExtension('trustedShops'$trustedShopsRates);
  57.     }
  58. }