Shopware 6 update listing criteria from javascript

I am searching for a possibility to filter listing results based on own filters that I need to update from the PHP or Javascript.

I already tried it with adding customer criteria using the event

    static function getSubscribedEvents()
    {
        return [
            ProductListingCriteriaEvent::class => ["criteriaEvent", 500],
        ];
    }

And then setting the criteria like the following:

public function criteriaEvent(ProductListingCriteriaEvent $event)
    {
        $this->getLogger()->info('criteriaEvent for request uri: ' . $event->getRequest()->getRequestUri());
        if (!array_key_exists('cit-model-id', $_COOKIE)) {
            $this->getLogger()->warning('criteriaEvent: modelId not set in cookies');
            return;
        }

        $modelId = $_COOKIE['cit-model-id'];
        $this->getLogger()->info('criteriaEvent: modelId from cookie: ' . $modelId);

        $event->getCriteria()->addFilter(new EqualsFilter('product.propertyIds', $modelId));
    }

In the test system this works fine and after changing the cookie value and redirecting to the page the product listing is filtered correctly. However, in the production environment it seems that the event is only called for the first time when entering a page and then the criteria is cached.

Is there any way to still update this criteria maybe from javascript or PHP, or am I going the wrong aproach?

Kindest, Luca

1 Like

Hi everybody,

so I figured out, that the problem is the object cache.
I disabled it now via cache.yml file for the production system.

Is there an option to disable the object cache only for specific DAL queries?

// Luca