custom/plugins/GbmedClientPentagastForms/src/Subscriber/Navigation.php line 41

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * gb media
  4.  * All Rights Reserved.
  5.  *
  6.  * Unauthorized copying of this file, via any medium is strictly prohibited.
  7.  * The content of this file is proprietary and confidential.
  8.  *
  9.  * @category       Shopware
  10.  * @package        Shopware_Plugins
  11.  * @subpackage     GbmedClientPentagastForms
  12.  * @copyright      Copyright (c) 2023, gb media
  13.  * @license        proprietary
  14.  * @author         Giuseppe Bottino
  15.  * @link           http://www.gb-media.biz
  16.  */
  17. namespace Gbmed\ClientPentagastForms\Subscriber;
  18. use Shopware\Core\Content\Category\Exception\CategoryNotFoundException;
  19. use Shopware\Core\System\SystemConfig\SystemConfigService;
  20. use Shopware\Storefront\Page\Navigation\NavigationPageLoadedEvent;
  21. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  22. class Navigation implements EventSubscriberInterface
  23. {
  24.     private SystemConfigService $systemConfigService;
  25.     public function __construct(SystemConfigService $systemConfigService)
  26.     {
  27.         $this->systemConfigService $systemConfigService;
  28.     }
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             NavigationPageLoadedEvent::class => 'onNavigationPageLoadedEvent',
  33.         ];
  34.     }
  35.     public function onNavigationPageLoadedEvent(NavigationPageLoadedEvent $event)
  36.     {
  37.         $configs $this->getConfigs();
  38.         if ($event->getRequest()->getRequestUri() === '/navigation/' $configs['offerCategoryId'] && !$configs['allowOfferRequest']) {
  39.             throw new CategoryNotFoundException($configs['offerCategoryId']);
  40.         }
  41.     }
  42.     public function getConfigs()
  43.     {
  44.         return $this->getSystemConfigService()->get(
  45.             'GbmedClientPentagastForms.config'
  46.         );
  47.     }
  48.     public function getSystemConfigService(): SystemConfigService
  49.     {
  50.         return $this->systemConfigService;
  51.     }
  52. }