<?php declare(strict_types=1);
namespace Nd\Stl\Service;
use Nd\Stl\Storefront\Framework\Seo\SeoUrlRoute\LookPageSeoUrlRoute;
use Shopware\Core\Content\Seo\SeoUrlUpdater;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityDeletedEvent;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class LookSeoUrlPageSubscriber implements EventSubscriberInterface
{
private SeoUrlUpdater $seoUrlUpdater;
public function __construct(SeoUrlUpdater $seoUrlUpdater) {
$this->seoUrlUpdater = $seoUrlUpdater;
}
public static function getSubscribedEvents(): array
{
return [
'look.written' => 'onEntityWritten',
'look.deleted' => 'onEntityDeleted'
];
}
public function onEntityWritten(EntityWrittenEvent $event): void
{
$this->seoUrlUpdater->update(LookPageSeoUrlRoute::ROUTE_NAME, $event->getIds());
}
public function onEntityDeleted(EntityDeletedEvent $event): void
{
$this->seoUrlUpdater->update(LookPageSeoUrlRoute::ROUTE_NAME, $event->getIds());
}
}