custom/plugins/TemplaidInvoices/src/Subscriber/ProductSubscriber.php line 43

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace TemplaidInvoices\Subscriber;
  3. use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\RequestEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. class ProductSubscriber implements EventSubscriberInterface
  8. {
  9.     public function __construct(
  10.     )
  11.     {
  12.     }
  13.     /**
  14.      * @return array|string[]
  15.      */
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             KernelEvents::REQUEST => 'onListPageLoaded'
  20.         ];
  21.     }
  22.     /**
  23.      * @param RequestEvent $event
  24.      */
  25.     public function onListPageLoaded(RequestEvent $event): void
  26.     {
  27.         $session $event->getRequest()->getSession();
  28.         $activeRoute $event->getRequest()->attributes->get('_route');
  29.         if (!$activeRoute) {
  30.             return;
  31.         }
  32.         $isListPage str_contains($activeRoute'frontend.templaid.assortment') || $activeRoute === 'frontend.navigation.page';
  33.         if($session->has('listLimit') && $isListPage) {
  34.             $event->getRequest()->query->set('limit'$session->get('listLimit'));
  35.             if ($session->has('limitChanged') && $event->getRequest()->query->has('p')) {
  36.                 $event->getRequest()->query->set('p'1);
  37.                 $session->remove('limitChanged');
  38.             }
  39.         }
  40.     }
  41. }