-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
633781f
commit c6a6b2c
Showing
4 changed files
with
59 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* another great project. | ||
* You can find more information about us on https://bitbag.shop and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusCmsPlugin\Sitemap\Provider; | ||
|
@@ -136,6 +144,7 @@ private function getLocaleCodes(): array | |
if (null === $this->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()); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* another great project. | ||
* You can find more information about us on https://bitbag.shop and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\BitBag\SyliusCmsPlugin\Api\Sitemap\Provider; | ||
|
||
use Lakion\ApiTestCase\XmlApiTestCase; | ||
|
@@ -12,7 +22,6 @@ | |
|
||
abstract class AbstractTestController extends XmlApiTestCase | ||
{ | ||
|
||
/** | ||
* @var ChannelInterface | ||
*/ | ||
|
@@ -35,8 +44,10 @@ abstract class AbstractTestController extends XmlApiTestCase | |
|
||
/** | ||
* @before | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
public function setupDatabase() | ||
public function setupDatabase(): void | ||
{ | ||
parent::setUpDatabase(); | ||
|
||
|
@@ -68,5 +79,4 @@ public function setupDatabase() | |
$this->getEntityManager()->persist($this->channel); | ||
$this->getEntityManager()->flush(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* another great project. | ||
* You can find more information about us on https://bitbag.shop and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\BitBag\SyliusCmsPlugin\Api\Sitemap\Provider; | ||
|
||
use BitBag\SyliusCmsPlugin\Entity\Page; | ||
|
||
class SitemapPageControllerApiLocalesTest extends AbstractTestController | ||
{ | ||
|
||
/** | ||
* @before | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
public function setUpDatabase() | ||
public function setUpDatabase(): void | ||
{ | ||
parent::setUpDatabase(); | ||
|
||
|
@@ -63,11 +74,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_locale'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* another great project. | ||
* You can find more information about us on https://bitbag.shop and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\BitBag\SyliusCmsPlugin\Api\Sitemap\Provider; | ||
|
||
use BitBag\SyliusCmsPlugin\Entity\Page; | ||
|
||
class SitemapPageControllerApiTest extends AbstractTestController | ||
{ | ||
|
||
/** | ||
* @before | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
public function setUpDatabase() | ||
public function setUpDatabase(): void | ||
{ | ||
parent::setUpDatabase(); | ||
|
||
|
@@ -20,12 +31,14 @@ public function setUpDatabase() | |
$page->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'); | ||
} | ||
|
||
} |