Skip to content

Commit 0cc6020

Browse files
committed
Exclude CMS pages by URL key not config value
1 parent 81340cb commit 0cc6020

File tree

2 files changed

+18
-4
lines changed
  • app/code/Magento/Sitemap

2 files changed

+18
-4
lines changed

app/code/Magento/Sitemap/Model/ResourceModel/Cms/Page.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,17 @@ public function getCollection($storeId)
103103
'main_table.is_active = 1'
104104
)->where(
105105
'main_table.identifier NOT IN (?)',
106-
$this->getUtilityPageIdentifiers->execute()
106+
array_map(
107+
// When two CMS pages have the same URL key (in different
108+
// stores), the value stored in configuration is 'url-key|ID'.
109+
// This function strips the trailing '|ID' so that this where()
110+
// matches the url-key configured.
111+
// See https://github.com/magento/magento2/issues/35001
112+
static function ($urlKey) {
113+
return explode('|', $urlKey, 2)[0];
114+
},
115+
$this->getUtilityPageIdentifiers->execute()
116+
)
107117
)->where(
108118
'store_table.store_id IN(?)',
109119
[0, $storeId]

app/code/Magento/Sitemap/Test/Unit/Model/ResourceModel/Cms/PageTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ public function testGetCollection()
104104
$pageId = 'testPageId';
105105
$url = 'testUrl';
106106
$updatedAt = 'testUpdatedAt';
107-
$pageIdentifiers = ['testCmsHomePage', 'testCmsNoRoute', 'testCmsNoCookies'];
107+
$pageIdentifiers = [
108+
'testCmsHomePage|ID' => 'testCmsHomePage',
109+
'testCmsNoRoute' => 'testCmsNoRoute',
110+
'testCmsNoCookies' => 'testCmsNoCookies',
111+
];
108112
$storeId = 1;
109113
$linkField = 'testLinkField';
110114
$expectedPage = new DataObject();
@@ -147,7 +151,7 @@ public function testGetCollection()
147151
->method('where')
148152
->withConsecutive(
149153
[$this->identicalTo('main_table.is_active = 1')],
150-
[$this->identicalTo('main_table.identifier NOT IN (?)'), $this->identicalTo($pageIdentifiers)],
154+
[$this->identicalTo('main_table.identifier NOT IN (?)'), $this->identicalTo(array_values($pageIdentifiers))],
151155
[$this->identicalTo('store_table.store_id IN(?)'), $this->identicalTo([0, $storeId])]
152156
)->willReturnSelf();
153157

@@ -176,7 +180,7 @@ public function testGetCollection()
176180

177181
$this->getUtilityPageIdentifiers->expects($this->once())
178182
->method('execute')
179-
->willReturn($pageIdentifiers);
183+
->willReturn(array_keys($pageIdentifiers));
180184

181185
$this->resource->expects($this->exactly(2))
182186
->method('getTableName')

0 commit comments

Comments
 (0)