Philipp Tuchardt / Shopware 6 Subscriber Example

Created Tue, 21 Jan 2025 06:08:08 +0000

Path: MyTheme/src/Subscriber/ProductListingSubscriber.php

<?php

namespace MyTheme\Subscriber;

use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class ProductListingSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            ProductListingCriteriaEvent::class => 'onProductListingCriteria',
        ];
    }

    public function onProductListingCriteria(ProductListingCriteriaEvent $event): void
    {
        $criteria = $event->getCriteria();
        $criteria->addAssociation('properties');
    }
}

Path: src/Resources/config/services.xml

<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    <services>
        <service id="MyTheme\Subscriber\ProductListingSubscriber" public="true">
            <tag name="kernel.event_subscriber"/>
        </service>
    </services>
</container>

Don’t forget to clear your cache :)