custom/plugins/EsmConfigurator/src/Storefront/Subscriber/HideUpgradesSubscriber.php line 31

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace EsmConfigurator\Storefront\Subscriber;
  3. use DateTime;
  4. use Shopware\Core\Content\Product\Events\ProductCrossSellingIdsCriteriaEvent;
  5. use Shopware\Core\Content\Product\Events\ProductCrossSellingStreamCriteriaEvent;
  6. use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
  7. use Shopware\Core\Content\Product\ProductEntity;
  8. use Shopware\Core\Content\Product\ProductEvents;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  12. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
  13. use Shopware\Storefront\Page\Product\ProductPage;
  14. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  17. class HideUpgradesSubscriber implements EventSubscriberInterface
  18. {
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             ProductEvents::PRODUCT_LISTING_CRITERIA => 'onProductListingCriteria',
  23.             ProductEvents::PRODUCT_SEARCH_CRITERIA => 'onProductListingCriteria',
  24.             ProductEvents::PRODUCT_SUGGEST_CRITERIA => 'onProductListingCriteria'
  25.         ];
  26.     }
  27.     public function onProductListingCriteria(ProductListingCriteriaEvent $event): void
  28.     {
  29.         if ($event->getCriteria()->hasState(self::class)) {
  30.             return;
  31.         }
  32.         $this->addCustomCriteria($event->getCriteria());
  33.     }
  34.     private function addCustomCriteria(Criteria $criteria): void
  35.     {
  36.         $criteria->addFilter(new NotFilter(NotFilter::CONNECTION_AND, [new EqualsFilter('customFields.custom_product_configurator_is_upgrade'1)]));
  37.         $criteria->addState(self::class);
  38.     }
  39. }