<?php declare(strict_types=1);
/**
* @copyright 2020 Crehler Sp. z o. o.
* @link https://crehler.com/
* @support support@crehler.com
*
* @author Mateusz FlasiĆski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Crehler\AdvancedMenu\Subscriber;
use Crehler\AdvancedMenu\Service\ProductsNavigationLoader;
use Shopware\Storefront\Pagelet\Header\HeaderPageletLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class HeaderPageletSubscriber implements EventSubscriberInterface
{
protected ProductsNavigationLoader $productsNavigationLoader;
public function __construct(ProductsNavigationLoader $productsNavigationLoader)
{
$this->productsNavigationLoader = $productsNavigationLoader;
}
public static function getSubscribedEvents()
{
return [HeaderPageletLoadedEvent::class => 'onHeaderPageletLoaded'];
}
public function onHeaderPageletLoaded(HeaderPageletLoadedEvent $event): void
{
$event->getPagelet()->addExtension('productsCategory', $this->productsNavigationLoader->loadProductCategory($event->getSalesChannelContext()));
}
}