custom/plugins/TomRocketsTheme/src/Subscriber/ProductDetailSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. namespace TomRockets\Subscriber;
  3. use Shopware\Core\Framework\Uuid\Uuid;
  4. use Shopware\Core\System\SystemConfig\SystemConfigService;
  5. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class ProductDetailSubscriber implements EventSubscriberInterface
  8. {
  9.     /** @var SystemConfigService */
  10.     private $config;
  11.     public function __construct(SystemConfigService $config)
  12.     {
  13.         $this->config $config;
  14.     }
  15.     /**
  16.      * @inheritDoc
  17.      */
  18.     public static function getSubscribedEvents()
  19.     {
  20.         return [
  21.             ProductPageLoadedEvent::class => "productLoaded"
  22.         ];
  23.     }
  24.     public function productLoaded(ProductPageLoadedEvent $event){
  25.         $product $event->getPage()->getProduct();
  26.         if(!$product->getManufacturer() && $this->config->get("TomRockets.config.contactCategory")){
  27.             return;
  28.         }
  29.         $manufacturerCategoryId Uuid::fromStringToHex($product->getManufacturer()->getName());
  30.         $contactCategory $this->config->get("TomRockets.config.contactCategory");
  31.         $event->getPage()->assign([
  32.             'productManufacturerCategory' => $manufacturerCategoryId,
  33.             'contactCategory' => $contactCategory
  34.         ]);
  35.     }
  36. }