<?php declare(strict_types=1);
namespace TemplaidInvoices\Subscriber;
use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class ProductSubscriber implements EventSubscriberInterface
{
public function __construct(
)
{
}
/**
* @return array|string[]
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => 'onListPageLoaded'
];
}
/**
* @param RequestEvent $event
*/
public function onListPageLoaded(RequestEvent $event): void
{
$session = $event->getRequest()->getSession();
$activeRoute = $event->getRequest()->attributes->get('_route');
if (!$activeRoute) {
return;
}
$isListPage = str_contains($activeRoute, 'frontend.templaid.assortment') || $activeRoute === 'frontend.navigation.page';
if($session->has('listLimit') && $isListPage) {
$event->getRequest()->query->set('limit', $session->get('listLimit'));
if ($session->has('limitChanged') && $event->getRequest()->query->has('p')) {
$event->getRequest()->query->set('p', 1);
$session->remove('limitChanged');
}
}
}
}