<?php
namespace B2bSellersCore\Components\Product\Subscriber;
use Shopware\Core\Content\Product\Events\ProductListingCollectFilterEvent;
use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ProductListingSubscriber implements EventSubscriberInterface
{
private SystemConfigService $configService;
public function __construct(
SystemConfigService $configService
)
{
$this->configService = $configService;
}
public static function getSubscribedEvents(): array
{
return [
ProductListingCriteriaEvent::class => 'handleRequest',
ProductListingCollectFilterEvent::class => 'removePriceFilter'
];
}
public function handleRequest(ProductListingCriteriaEvent $event)
{
$event->getCriteria()->addAssociation('properties.group');
}
public function removePriceFilter(ProductListingCollectFilterEvent $event)
{
if ($event->getSalesChannelContext()->getCustomerId()) {
return;
}
if (!$this->configService->getBool('B2bSellersCore.config.disableProductPricesVisibility', $event->getSalesChannelContext()->getSalesChannelId())) {
return;
}
$event->getFilters()->remove('price');
}
}