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