<?php declare(strict_types=1);
namespace MuehldorferSitemap\Subscriber;
use MuehldorferSitemap\Service\MuehldorferSitemapService;
use Shopware\Core\Content\Category\CategoryEvents;
use Shopware\Core\Content\Cms\CmsPageEvents;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Content\Product\ProductEvents;
class MuehldorferSitemapSubscriber implements EventSubscriberInterface
{
private $muehldorferSitemapService;
public function __construct(MuehldorferSitemapService $muehldorferSitemapService )
{
$this->muehldorferSitemapService = $muehldorferSitemapService; // Service in die Klasse injizieren
}
public static function getSubscribedEvents(): array
{
// Return the events to listen to as array like this: <event to listen to> => <method to execute>
return [
CmsPageEvents::PAGE_WRITTEN_EVENT => "resetSitemap",
CmsPageEvents::PAGE_DELETED_EVENT => "resetSitemap",
ProductEvents::PRODUCT_WRITTEN_EVENT => "resetSitemap",
ProductEvents::PRODUCT_DELETED_EVENT => "resetSitemap",
CategoryEvents::CATEGORY_WRITTEN_EVENT => "resetSitemap",
CategoryEvents::CATEGORY_DELETED_EVENT => "resetSitemap",
];
}
public function resetSitemap()
{
$this->muehldorferSitemapService->reset();
}
}