custom/plugins/SwagHoggi/src/Storefront/Subscriber/HideConfiguratorProductsSubscriber.php line 37

Open in your IDE?
  1. <?php
  2. namespace SwagHoggi\Storefront\Subscriber;
  3. use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
  6. use Shopware\Core\System\SystemConfig\SystemConfigService;
  7. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  8. /**
  9.  * @see https://stackoverflow.com/a/68962668
  10.  */
  11. class HideConfiguratorProductsSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
  12. {
  13.     public function __construct(
  14.         private SystemConfigService $systemConfigService
  15.     ) { }
  16.     /**
  17.      * @inheritDoc
  18.      */
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             ProductPageLoadedEvent::class => "onProductPageLoaded",
  23.             ProductListingCriteriaEvent::class => "onProductListingCriteria"
  24.         ];
  25.     }
  26.     public function onProductPageLoaded(ProductPageLoadedEvent $event): void
  27.     {
  28.         // TODO block detail page from loading?
  29.     }
  30.     public function onProductListingCriteria(ProductListingCriteriaEvent $event): void
  31.     {
  32.         /*
  33.         \Shopware\Production\Kernel::getConnection()->getConfiguration()->setSQLLogger(
  34.             new \Frosh\DevelopmentHelper\Doctrine\EchoSQLLogger()
  35.         );
  36.         */
  37.         $criteria $event->getCriteria();
  38.         // Hide all products in listing that have a configurator
  39.         $criteria->addAssociation("product.hoggiConfigurators");
  40.         $criteria->addFilter(new EqualsFilter('product.hoggiConfigurators.id'null));
  41.         //dump($criteria->getTitle()); die;
  42.         //dump($criteria); die;
  43.     }
  44. }