custom/plugins/b2bsellerscore/src/Components/Product/Subscriber/ProductListingSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. namespace B2bSellersCore\Components\Product\Subscriber;
  3. use Shopware\Core\Content\Product\Events\ProductListingCollectFilterEvent;
  4. use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
  5. use Shopware\Core\System\SystemConfig\SystemConfigService;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class ProductListingSubscriber implements EventSubscriberInterface
  8. {
  9.     private SystemConfigService $configService;
  10.     public function __construct(
  11.         SystemConfigService $configService
  12.     )
  13.     {
  14.         $this->configService $configService;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             ProductListingCriteriaEvent::class => 'handleRequest',
  20.             ProductListingCollectFilterEvent::class => 'removePriceFilter'
  21.         ];
  22.     }
  23.     public function handleRequest(ProductListingCriteriaEvent $event)
  24.     {
  25.         $event->getCriteria()->addAssociation('properties.group');
  26.     }
  27.     public function removePriceFilter(ProductListingCollectFilterEvent $event)
  28.     {
  29.         if ($event->getSalesChannelContext()->getCustomerId()) {
  30.             return;
  31.         }
  32.         if (!$this->configService->getBool('B2bSellersCore.config.disableProductPricesVisibility'$event->getSalesChannelContext()->getSalesChannelId())) {
  33.             return;
  34.         }
  35.         $event->getFilters()->remove('price');
  36.     }
  37. }