<?php
namespace SwagHoggi\Storefront\Subscriber;
use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
/**
* @see https://stackoverflow.com/a/68962668
*/
class HideConfiguratorProductsSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
public function __construct(
private SystemConfigService $systemConfigService
) { }
/**
* @inheritDoc
*/
public static function getSubscribedEvents()
{
return [
ProductPageLoadedEvent::class => "onProductPageLoaded",
ProductListingCriteriaEvent::class => "onProductListingCriteria"
];
}
public function onProductPageLoaded(ProductPageLoadedEvent $event): void
{
// TODO block detail page from loading?
}
public function onProductListingCriteria(ProductListingCriteriaEvent $event): void
{
/*
\Shopware\Production\Kernel::getConnection()->getConfiguration()->setSQLLogger(
new \Frosh\DevelopmentHelper\Doctrine\EchoSQLLogger()
);
*/
$criteria = $event->getCriteria();
// Hide all products in listing that have a configurator
$criteria->addAssociation("product.hoggiConfigurators");
$criteria->addFilter(new EqualsFilter('product.hoggiConfigurators.id', null));
//dump($criteria->getTitle()); die;
//dump($criteria); die;
}
}