Skip to content

Commit fb116a3

Browse files
committed
ACP2E-2964: [Cloud] URL update only for store_id=0
1 parent f9aa312 commit fb116a3

File tree

2 files changed

+35
-27
lines changed
  • app/code/Magento/CatalogUrlRewrite

2 files changed

+35
-27
lines changed

app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Category/Move.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,16 @@ public function afterChangeParent(
7373
$afterCategoryId
7474
) {
7575
$categoryStoreId = $category->getStoreId();
76+
foreach ($category->getStoreIds() as $storeId) {
77+
$category->setStoreId($storeId);
78+
$this->removeObsoleteUrlPathEntries($category, $categoryStoreId);
79+
$this->updateCategoryUrlKeyForStore($category);
80+
$category->unsUrlPath();
81+
$category->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
82+
$category->getResource()->saveAttribute($category, 'url_path');
83+
$this->updateUrlPathForChildren($category);
84+
}
7685
$category->setStoreId($categoryStoreId);
77-
$this->removeObsoleteUrlPathEntries($category);
78-
$this->updateCategoryUrlKeyForStore($category);
79-
$category->unsUrlPath();
80-
$category->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
81-
$category->getResource()->saveAttribute($category, 'url_path');
82-
$this->updateUrlPathForChildren($category);
8386

8487
return $result;
8588
}
@@ -120,7 +123,7 @@ private function updateUrlPathForChildren(Category $category): void
120123
* @param Category $category
121124
* @return void
122125
*/
123-
private function removeObsoleteUrlPathEntries(Category $category): void
126+
private function removeObsoleteUrlPathEntries(Category $category, $categoryStoreId): void
124127
{
125128
if ($this->storeManager->hasSingleStore()) {
126129
return;
@@ -129,6 +132,10 @@ private function removeObsoleteUrlPathEntries(Category $category): void
129132
$path = $category->getData('path');
130133
if ($origPath != null && $path != null && $origPath != $path) {
131134
$category->unsUrlPath();
135+
if( $category->getStoreId() !== $categoryStoreId ) {
136+
$category->setStoreId($categoryStoreId);
137+
$category->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
138+
}
132139
$category->getResource()->saveAttribute($category, 'url_path');
133140
foreach ($this->childrenCategoriesProvider->getChildren($category, true) as $childCategory) {
134141
$childCategory->unsUrlPath();

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/Plugin/Category/MoveTest.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,40 +114,41 @@ protected function setUp(): void
114114
public function testAfterChangeParent()
115115
{
116116
$urlPath = 'test/path';
117-
$storeId = 0;
117+
$storeIds = [0, 1];
118118

119-
$this->storeManagerMock->expects($this->once())->method('hasSingleStore')->willReturn(false);
120-
$this->categoryMock->expects($this->exactly(3))->method('getStoreId')
121-
->willReturn($storeId);
122-
$this->categoryMock->expects($this->exactly(2))->method('setStoreId')
123-
->willReturnOnConsecutiveCalls($storeId);
119+
$this->storeManagerMock->expects($this->exactly(2))->method('hasSingleStore')->willReturn(false);
120+
$this->categoryMock->expects($this->exactly(6))->method('getStoreId')
121+
->willReturnOnConsecutiveCalls(0, 0, 1, 0, 1, 0);
122+
$this->categoryMock->expects($this->once())->method('getStoreIds')->willReturn($storeIds);
123+
$this->categoryMock->expects($this->exactly(5))->method('setStoreId')
124+
->willReturnOnConsecutiveCalls(0, 0, 1, 0, 1);
124125

125-
$this->categoryMock->expects($this->once())->method('getData')
126+
$this->categoryMock->expects($this->exactly(2))->method('getData')
126127
->willReturnOnConsecutiveCalls('1/3/5', '1/3/5');
127-
$this->categoryMock->expects($this->once())->method('getOrigData')
128+
$this->categoryMock->expects($this->exactly(2))->method('getOrigData')
128129
->willReturnOnConsecutiveCalls('1/2/5', '1/2/5');
129-
$this->categoryMock->expects($this->exactly(4))->method('unsUrlPath')->willReturnSelf();
130-
$this->childrenCategoriesProviderMock->expects($this->exactly(2))->method('getChildren')
130+
$this->categoryMock->expects($this->exactly(6))->method('unsUrlPath')->willReturnSelf();
131+
$this->childrenCategoriesProviderMock->expects($this->exactly(4))->method('getChildren')
131132
->with($this->categoryMock, true)
132133
->willReturnOnConsecutiveCalls([$this->categoryMock], [$this->categoryMock], [], []);
133134

134-
$this->categoryMock->expects($this->exactly(4))->method('getResource')->willReturn($this->subjectMock);
135-
$this->subjectMock->expects($this->exactly(4))->method('saveAttribute')
135+
$this->categoryMock->expects($this->exactly(6))->method('getResource')->willReturn($this->subjectMock);
136+
$this->subjectMock->expects($this->exactly(6))->method('saveAttribute')
136137
->with($this->categoryMock, 'url_path')->willReturnSelf();
137-
$this->categoryMock->expects($this->once())->method('getId')->willReturnSelf();
138+
$this->categoryMock->expects($this->exactly(2))->method('getId')->willReturnSelf();
138139

139140
$originalCategory = $this->getMockBuilder(Category::class)->disableOriginalConstructor()->getMock();
140-
$originalCategory->expects($this->once())->method('getUrlKey')->willReturn('url-key');
141-
$originalCategory->expects($this->once())->method('setStoreId')->willReturnSelf();
142-
$originalCategory->expects($this->once())->method('load')->willReturnSelf();
143-
$this->categoryFactory->expects($this->once())->method('create')
141+
$originalCategory->expects($this->exactly(2))->method('getUrlKey')->willReturn('url-key');
142+
$originalCategory->expects($this->exactly(2))->method('setStoreId')->willReturnSelf();
143+
$originalCategory->expects($this->exactly(2))->method('load')->willReturnSelf();
144+
$this->categoryFactory->expects($this->exactly(2))->method('create')
144145
->willReturn($originalCategory);
145-
$this->categoryMock->expects($this->once())->method('setUrlKey')->with('url-key')
146+
$this->categoryMock->expects($this->exactly(2))->method('setUrlKey')->with('url-key')
146147
->willReturnSelf();
147148

148-
$this->categoryUrlPathGeneratorMock->expects($this->exactly(2))->method('getUrlPath')
149+
$this->categoryUrlPathGeneratorMock->expects($this->exactly(4))->method('getUrlPath')
149150
->with($this->categoryMock)->willReturn($urlPath);
150-
$this->categoryMock->expects($this->exactly(2))->method('setUrlPath')->with($urlPath);
151+
$this->categoryMock->expects($this->exactly(4))->method('setUrlPath')->with($urlPath);
151152

152153
$this->assertSame(
153154
$this->subjectMock,

0 commit comments

Comments
 (0)