<?php declare(strict_types=1);
namespace Expert\AutobatMarktThemePlugin\Subscriber;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Page\Navigation\NavigationPageLoadedEvent;
use Shopware\Storefront\Pagelet\Header\HeaderPageletLoadedEvent;
use Shopware\Storefront\Pagelet\PageletLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
class FrontendAsigneesSubscriber implements EventSubscriberInterface
{
/**
* Plugin Name
*/
const CONFIG_NAMESPACE = 'AutobatMarktThemePlugin';
/**
* @var SystemConfigService
*/
private $systemConfig;
/**
* FrontendAsigneesSubscriber constructor.
*
* @param SystemConfigService $systemConfig
*/
public function __construct(SystemConfigService $systemConfig)
{
$this->systemConfig = $systemConfig;
}
public static function getSubscribedEvents()
{
return [
HeaderPageletLoadedEvent::class => 'onStorefrontLoaded'
];
}
/**
* @param HeaderPageletLoadedEvent $event
*/
public function onStorefrontLoaded(HeaderPageletLoadedEvent $event)
{
$cfg = $this->systemConfig;
// icons
$customIcon1 = $cfg->get('AutobatMarktThemePlugin.config.customIcon1');
$customIcon2 = $cfg->get('AutobatMarktThemePlugin.config.customIcon2');
$customIcon3 = $cfg->get('AutobatMarktThemePlugin.config.customIcon3');
$customIcon4 = $cfg->get('AutobatMarktThemePlugin.config.customIcon4');
$customIcon5 = $cfg->get('AutobatMarktThemePlugin.config.customIcon5');
// urls
$customUrl1 = $cfg->get('AutobatMarktThemePlugin.config.customCatUrl1');
$customUrl2 = $cfg->get('AutobatMarktThemePlugin.config.customCatUrl2');
$customUrl3 = $cfg->get('AutobatMarktThemePlugin.config.customCatUrl3');
$customUrl4 = $cfg->get('AutobatMarktThemePlugin.config.customCatUrl4');
$customUrl5 = $cfg->get('AutobatMarktThemePlugin.config.customCatUrl5');
// well organized assigns
$pluginConfig = [
'catIcon1' => $customIcon1,
'catIcon2' => $customIcon2,
'catIcon3' => $customIcon3,
'catIcon4' => $customIcon4,
'catIcon5' => $customIcon5,
'catUrl1' => $customUrl1,
'catUrl2' => $customUrl2,
'catUrl3' => $customUrl3,
'catUrl4' => $customUrl4,
'catUrl5' => $customUrl5
];
$event->getPagelet()->assign([self::CONFIG_NAMESPACE => $pluginConfig]);
}
}