<?php declare(strict_types=1);
/**
* gb media
* All Rights Reserved.
*
* Unauthorized copying of this file, via any medium is strictly prohibited.
* The content of this file is proprietary and confidential.
*
* @category Shopware
* @package Shopware_Plugins
* @subpackage GbmedClientPentagastForms
* @copyright Copyright (c) 2023, gb media
* @license proprietary
* @author Giuseppe Bottino
* @link http://www.gb-media.biz
*/
namespace Gbmed\ClientPentagastForms\Subscriber;
use Shopware\Core\Content\Category\Exception\CategoryNotFoundException;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Page\Navigation\NavigationPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class Navigation implements EventSubscriberInterface
{
private SystemConfigService $systemConfigService;
public function __construct(SystemConfigService $systemConfigService)
{
$this->systemConfigService = $systemConfigService;
}
public static function getSubscribedEvents()
{
return [
NavigationPageLoadedEvent::class => 'onNavigationPageLoadedEvent',
];
}
public function onNavigationPageLoadedEvent(NavigationPageLoadedEvent $event)
{
$configs = $this->getConfigs();
if ($event->getRequest()->getRequestUri() === '/navigation/' . $configs['offerCategoryId'] && !$configs['allowOfferRequest']) {
throw new CategoryNotFoundException($configs['offerCategoryId']);
}
}
public function getConfigs()
{
return $this->getSystemConfigService()->get(
'GbmedClientPentagastForms.config'
);
}
public function getSystemConfigService(): SystemConfigService
{
return $this->systemConfigService;
}
}