custom/plugins/SasBlogModule/src/Subscriber/BlogNavigationSubscriber.php line 19

Open in your IDE?
  1. <?php
  2. namespace Sas\BlogModule\Subscriber;
  3. use Shopware\Storefront\Event\StorefrontRenderEvent;
  4. use Shopware\Storefront\Page\Navigation\NavigationPage;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. class BlogNavigationSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents(): array
  10.     {
  11.         return [
  12.             StorefrontRenderEvent::class => 'onStorefrontRenderEvent',
  13.         ];
  14.     }
  15.     public function onStorefrontRenderEvent(StorefrontRenderEvent $event)
  16.     {
  17.         if (array_key_exists('page'$event->getParameters())) {
  18.             /* @var $page NavigationPage */
  19.             $page $event->getParameters()['page'];
  20.             if ($page instanceof NavigationPage) {
  21.                 if ($page->getCmsPage()->getName() == 'Blog Listing') {
  22.                     if (is_null($event->getRequest()->get('now'))) {
  23.                         $url $event->getSalesChannelContext()->getSalesChannel()->getDomains()->first()->getUrl();
  24.                         $url .= $event->getRequest()->getRequestUri();
  25.                         $url .= (parse_url($urlPHP_URL_QUERY) ? '&' '?') . 'now=' time();
  26.                         (new RedirectResponse($url))->send();
  27.                     }
  28.                 }
  29.             }
  30.         }
  31.     }
  32. }