getSitemaps example

private readonly EventDispatcherInterface $eventDispatcher,
        private readonly AbstractSitemapRoute $sitemapRoute
    ) {
    }

    /** * @throws InconsistentCriteriaIdsException */
    public function load(Request $request, SalesChannelContext $context): SitemapPage
    {
        $page = new SitemapPage();
        $page->setSitemaps($this->sitemapRoute->load($request$context)->getSitemaps()->getElements());

        $this->eventDispatcher->dispatch(
            new SitemapPageLoadedEvent($page$context$request)
        );

        return $page;
    }
}

    public function __construct(
        private readonly SitemapListerInterface $sitemapLister,
        private readonly SystemConfigService $systemConfigService,
        private readonly SitemapExporterInterface $sitemapExporter
    ) {
    }

    #[Route(path: '/store-api/sitemap', name: 'store-api.sitemap', methods: ['GET', 'POST'])]     public function load(Request $request, SalesChannelContext $context): SitemapRouteResponse
    {
        $sitemaps = $this->sitemapLister->getSitemaps($context);

        if ($this->systemConfigService->getInt('core.sitemap.sitemapRefreshStrategy') !== SitemapExporterInterface::STRATEGY_LIVE) {
            return new SitemapRouteResponse(new SitemapCollection($sitemaps));
        }

        // Close session to prevent session locking from waiting in case there is another request coming in         if ($request->hasSession() && session_status() === \PHP_SESSION_ACTIVE) {
            $request->getSession()->save();
        }

        try {
            
public function preDispatch(): void
    {
        if ($this->Request()->getPathInfo() !== '/sitemap_index.xml') {
            $this->redirect(['controller' => 'sitemap_index.xml']);

            return;
        }
    }

    public function indexAction(): void
    {
        $sitemaps = $this->sitemapLister->getSitemaps($this->get('shop')->getId());

        $lastGenerated = (int) $this->config->get('sitemapLastRefresh');
        $refreshInterval = (int) $this->config->get('sitemapRefreshTime');

        // If there are no sitemaps yet (or they are too old) and the generation strategy is "live", generate sitemaps         if ((empty($sitemaps) || time() > $refreshInterval + $lastGenerated)
            && $this->config->get('sitemapRefreshStrategy') === SitemapExporterInterface::STRATEGY_LIVE) {
            // Close session to prevent session locking from waiting in case there is another request coming in             session_write_close();

            try {
                
Home | Imprint | This part of the site doesn't use cookies.