<?php declare(strict_types=1);
namespace EsmConfigurator\Storefront\Subscriber;
use DateTime;
use Shopware\Core\Content\Product\Events\ProductCrossSellingIdsCriteriaEvent;
use Shopware\Core\Content\Product\Events\ProductCrossSellingStreamCriteriaEvent;
use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
use Shopware\Core\Content\Product\ProductEntity;
use Shopware\Core\Content\Product\ProductEvents;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
use Shopware\Storefront\Page\Product\ProductPage;
use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class HideUpgradesSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
ProductEvents::PRODUCT_LISTING_CRITERIA => 'onProductListingCriteria',
ProductEvents::PRODUCT_SEARCH_CRITERIA => 'onProductListingCriteria',
ProductEvents::PRODUCT_SUGGEST_CRITERIA => 'onProductListingCriteria'
];
}
public function onProductListingCriteria(ProductListingCriteriaEvent $event): void
{
if ($event->getCriteria()->hasState(self::class)) {
return;
}
$this->addCustomCriteria($event->getCriteria());
}
private function addCustomCriteria(Criteria $criteria): void
{
$criteria->addFilter(new NotFilter(NotFilter::CONNECTION_AND, [new EqualsFilter('customFields.custom_product_configurator_is_upgrade', 1)]));
$criteria->addState(self::class);
}
}