diff --git a/src/Sitemap/Provider/PageUrlProvider.php b/src/Sitemap/Provider/PageUrlProvider.php index 8bdb12bc3..6ba4c9f77 100644 --- a/src/Sitemap/Provider/PageUrlProvider.php +++ b/src/Sitemap/Provider/PageUrlProvider.php @@ -1,5 +1,13 @@ channelLocaleCodes) { /** @var ChannelInterface $channel */ $channel = $this->channelContext->getChannel(); + $this->channelLocaleCodes = $channel->getLocales()->map(function (LocaleInterface $locale) { return $locale->getCode(); })->toArray(); @@ -152,30 +161,37 @@ private function getLocaleCodes(): array private function createPageUrl(PageInterface $page): SitemapUrlInterface { $pageUrl = $this->sitemapUrlFactory->createNew(); + $pageUrl->setChangeFrequency(ChangeFrequency::daily()); $pageUrl->setPriority(0.7); + if ($page->getUpdatedAt()) { $pageUrl->setLastModification($page->getUpdatedAt()); } elseif ($page->getCreatedAt()) { $pageUrl->setLastModification($page->getCreatedAt()); } + /** @var PageTranslationInterface $translation */ foreach ($this->getTranslations($page) as $translation) { if (!$translation->getLocale()) { continue; } + if (!$this->localeInLocaleCodes($translation)) { continue; } + $location = $this->router->generate('bitbag_sylius_cms_plugin_shop_page_show', [ 'slug' => $translation->getSlug(), '_locale' => $translation->getLocale(), ]); + if ($translation->getLocale() === $this->localeContext->getLocaleCode()) { $pageUrl->setLocalization($location); continue; } + $pageUrl->addAlternative($location, $translation->getLocale()); } diff --git a/tests/Api/Sitemap/Provider/AbstractTestController.php b/tests/Api/Sitemap/Provider/AbstractTestController.php index ff16c3577..63874c5a7 100644 --- a/tests/Api/Sitemap/Provider/AbstractTestController.php +++ b/tests/Api/Sitemap/Provider/AbstractTestController.php @@ -1,5 +1,15 @@ getEntityManager()->persist($this->channel); $this->getEntityManager()->flush(); } - } diff --git a/tests/Api/Sitemap/Provider/SitemapPageControllerApiLocalesTest.php b/tests/Api/Sitemap/Provider/SitemapPageControllerApiLocalesTest.php index 965a4f8e1..db08d6e4c 100644 --- a/tests/Api/Sitemap/Provider/SitemapPageControllerApiLocalesTest.php +++ b/tests/Api/Sitemap/Provider/SitemapPageControllerApiLocalesTest.php @@ -1,16 +1,27 @@ getEntityManager()->flush(); } - public function testShowActionResponse() + public function testShowActionResponse(): void { $this->client->request('GET', '/sitemap/cms_pages.xml'); $response = $this->client->getResponse(); $this->assertResponse($response, 'show_sitemap_pages_locale'); } - } diff --git a/tests/Api/Sitemap/Provider/SitemapPageControllerApiTest.php b/tests/Api/Sitemap/Provider/SitemapPageControllerApiTest.php index a67bcf044..c87864b38 100644 --- a/tests/Api/Sitemap/Provider/SitemapPageControllerApiTest.php +++ b/tests/Api/Sitemap/Provider/SitemapPageControllerApiTest.php @@ -1,16 +1,27 @@ setCode('test-code'); $page->setSlug('test'); $this->getEntityManager()->persist($page); + $page = new Page(); $page->setCurrentLocale('en_US'); $page->setName('Mock'); $page->setCode('mock-code'); $page->setSlug('mock'); $this->getEntityManager()->persist($page); + $page = new Page(); $page->setCurrentLocale('en_US'); $page->setName('Test 2'); @@ -36,11 +49,10 @@ public function setUpDatabase() $this->getEntityManager()->flush(); } - public function testShowActionResponse() + public function testShowActionResponse(): void { $this->client->request('GET', '/sitemap/cms_pages.xml'); $response = $this->client->getResponse(); $this->assertResponse($response, 'show_sitemap_pages'); } - }