custom/plugins/MuehldorferSitemap/src/Subscriber/MuehldorferSitemapSubscriber.php line 35

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MuehldorferSitemap\Subscriber;
  3. use MuehldorferSitemap\Service\MuehldorferSitemapService;
  4. use Shopware\Core\Content\Category\CategoryEvents;
  5. use Shopware\Core\Content\Cms\CmsPageEvents;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Shopware\Core\Content\Product\ProductEvents;
  9. class MuehldorferSitemapSubscriber implements EventSubscriberInterface
  10. {
  11.     private $muehldorferSitemapService;
  12.     public function __construct(MuehldorferSitemapService $muehldorferSitemapService    )
  13.     {
  14.         $this->muehldorferSitemapService $muehldorferSitemapService// Service in die Klasse injizieren
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         // Return the events to listen to as array like this:  <event to listen to> => <method to execute>
  19.         return [
  20.             CmsPageEvents::PAGE_WRITTEN_EVENT => "resetSitemap",
  21.             CmsPageEvents::PAGE_DELETED_EVENT => "resetSitemap",
  22.             ProductEvents::PRODUCT_WRITTEN_EVENT => "resetSitemap",
  23.             ProductEvents::PRODUCT_DELETED_EVENT => "resetSitemap",
  24.             CategoryEvents::CATEGORY_WRITTEN_EVENT => "resetSitemap",
  25.             CategoryEvents::CATEGORY_DELETED_EVENT => "resetSitemap",
  26.         ];
  27.     }
  28.     public function resetSitemap()
  29.     {
  30.         $this->muehldorferSitemapService->reset();
  31.     }
  32. }