<?php declare(strict_types=1);
namespace Dvdw\PlatformChoice\Content\Category\Subscriber;
use Dvdw\PlatformChoice\System\SalesChannel\Struct\PlatformChoiceExtension;
use Shopware\Core\Content\Category\Event\NavigationRouteCacheKeyEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class NavigationRouteCacheKeySubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): iterable
{
return [NavigationRouteCacheKeyEvent::class => 'extendKey'];
}
public function extendKey(NavigationRouteCacheKeyEvent $event): void
{
/** @var PlatformChoiceExtension|null $extension */
$extension = $event->getContext()->getExtension(PlatformChoiceExtension::KEY);
$choice = PlatformChoiceExtension::B2C;
if ($extension !== null) {
$choice = $extension->getChoice();
}
$event->addPart($choice);
}
}