Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types=1);
- namespace Foo\Bar\Subscriber;
- use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
- use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
- /**
- * @class FrontendSubscriber
- * @package Foo\Bar\Subscriber
- */
- class FrontendSubscriber implements EventSubscriberInterface
- {
- /**
- * @return string[]
- */
- public static function getSubscribedEvents(): array
- {
- return [
- ProductListingCriteriaEvent::class => 'onLoadProductListing'
- ];
- }
- /**
- * @param ProductListingCriteriaEvent $event
- * @return void
- */
- public function onLoadProductListing(ProductListingCriteriaEvent $event): void
- {
- $request = $event->getRequest();
- $criteria = $event->getCriteria();
- $categoryId = $request->get('navigationId');
- $criteria->addFilter(
- new EqualsFilter('categories.id', $categoryId)
- );
- }
- }
Add Comment
Please, Sign In to add comment