custom/plugins/NetiNextGoogleCustomerReviews/src/Subscriber/Frontend.php line 30

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace NetInventors\NetiNextGoogleCustomerReviews\Subscriber;
  3. use NetInventors\NetiNextGoogleCustomerReviews\Service\PluginConfig;
  4. use NetInventors\NetiNextGoogleCustomerReviews\Struct\GoogleRatingBadge;
  5. use Shopware\Storefront\Event\StorefrontRenderEvent;
  6. use Shopware\Storefront\Page\Page;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class Frontend implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var PluginConfig
  12.      */
  13.     private $pluginConfig;
  14.     public function __construct(PluginConfig $pluginConfig)
  15.     {
  16.         $this->pluginConfig $pluginConfig;
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             StorefrontRenderEvent::class => 'onStorefrontRender',
  22.         ];
  23.     }
  24.     public function onStorefrontRender(StorefrontRenderEvent $event): void
  25.     {
  26.         if (!$this->pluginConfig->isActive() || !$this->pluginConfig->isShowBadge()) {
  27.             return;
  28.         }
  29.         $struct = new GoogleRatingBadge();
  30.         $struct->setMerchantId($this->pluginConfig->getMerchantId());
  31.         $struct->setPosition($this->pluginConfig->getBadgePosition());
  32.         $parameters $event->getParameters();
  33.         $page       $parameters['page'] ?? null;
  34.         if ($page instanceof Page) {
  35.             $struct = new GoogleRatingBadge();
  36.             $struct->setMerchantId($this->pluginConfig->getMerchantId());
  37.             $struct->setPosition($this->pluginConfig->getBadgePosition());
  38.             $page->addExtension('NetiNextGoogleCustomerReviewsFrontend'$struct);
  39.         }
  40.     }
  41. }