custom/plugins/b2bsellerscore/src/Components/Product/Subscriber/ProductHidingSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. namespace B2bSellersCore\Components\Product\Subscriber;
  3. use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
  4. use Shopware\Core\Content\Product\Events\ProductSearchCriteriaEvent;
  5. use Shopware\Core\Content\Product\Events\ProductSuggestCriteriaEvent;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class ProductHidingSubscriber implements EventSubscriberInterface
  12. {
  13.     public static function getSubscribedEvents(): array
  14.     {
  15.         return [
  16.             ProductListingCriteriaEvent::class => 'addProductListingHidingCriteria',
  17.             ProductSuggestCriteriaEvent::class => 'addProductSuggestHidingCriteria',
  18.             ProductSearchCriteriaEvent::class => 'addProductSearchHidingCriteria',
  19.         ];
  20.     }
  21.     public function addProductSuggestHidingCriteria(ProductSuggestCriteriaEvent $event)
  22.     {
  23.         $this->addHidingCriteria($event->getCriteria());
  24.     }
  25.     public function addProductListingHidingCriteria(ProductListingCriteriaEvent $event)
  26.     {
  27.         $this->addHidingCriteria($event->getCriteria());
  28.     }
  29.     public function addProductSearchHidingCriteria(ProductListingCriteriaEvent $event)
  30.     {
  31.         $this->addHidingCriteria($event->getCriteria());
  32.     }
  33.     private function addHidingCriteria(Criteria $criteria) {
  34.         $criteria->addFilter(new MultiFilter(MultiFilter::CONNECTION_OR, [
  35.             new NotFilter(NotFilter::CONNECTION_AND, [
  36.                     new EqualsFilter('customFields.b2b_hide_product'true),
  37.                 ]
  38.             ),
  39.             new EqualsFilter('customFields.b2b_hide_product'NULL)
  40.         ]));
  41.     }
  42. }