custom/static-plugins/ThemeAfterPlugins/src/Subscriber/ProductListingSubscriber.php line 36

Open in your IDE?
  1. <?php
  2. namespace K3n\ThemeAfterPlugins\Subscriber;
  3. use Shopware\Core\Content\Product\Events\ProductSearchCriteriaEvent;
  4. use Shopware\Core\Content\Product\Exception\ProductNotFoundException;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  6. use Shopware\Core\Framework\Event\NestedEvent;
  7. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
  10. class ProductListingSubscriber implements EventSubscriberInterface
  11. {
  12.     public static function getSubscribedEvents()
  13.     {
  14.         return [
  15. //            ProductListingCriteriaEvent::class => 'hideProductsBeforeCustomerLogin',
  16. //            ProductSearchCriteriaEvent::class => 'hideProductsBeforeCustomerLogin',
  17.             ProductPageLoadedEvent::class => 'onProductPageLoaded',
  18.         ];
  19.     }
  20.     public function hideProductsBeforeCustomerLogin(NestedEvent $event)
  21.     {
  22.         if ($event instanceof ProductListingCriteriaEvent || $event instanceof ProductSearchCriteriaEvent)
  23.         {
  24.             $criteria $event->getCriteria();
  25.             $criteria->addFilter(
  26.                 new EqualsFilter('product.id'null)
  27.             );
  28.         }
  29.     }
  30.     public function onProductPageLoaded(ProductPageLoadedEvent $event)
  31.     {
  32.         throw new ProductNotFoundException($event->getPage()->getProduct()->getId());
  33.     }
  34. }