Skip to content

Commit c7e04b5

Browse files
committed
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-2964' into Tier4-Kings-PR-06-12-2024
2 parents 6a18520 + 832d1ea commit c7e04b5

File tree

2 files changed

+13
-8
lines changed
  • app/code/Magento/CatalogUrlRewrite

2 files changed

+13
-8
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function afterChangeParent(
7575
$categoryStoreId = $category->getStoreId();
7676
foreach ($category->getStoreIds() as $storeId) {
7777
$category->setStoreId($storeId);
78-
$this->removeObsoleteUrlPathEntries($category);
78+
$this->removeObsoleteUrlPathEntries($category, $categoryStoreId);
7979
$this->updateCategoryUrlKeyForStore($category);
8080
$category->unsUrlPath();
8181
$category->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
@@ -121,9 +121,10 @@ private function updateUrlPathForChildren(Category $category): void
121121
* Clean obsolete entries
122122
*
123123
* @param Category $category
124+
* @param int $categoryStoreId
124125
* @return void
125126
*/
126-
private function removeObsoleteUrlPathEntries(Category $category): void
127+
private function removeObsoleteUrlPathEntries(Category $category, $categoryStoreId): void
127128
{
128129
if ($this->storeManager->hasSingleStore()) {
129130
return;
@@ -132,6 +133,10 @@ private function removeObsoleteUrlPathEntries(Category $category): void
132133
$path = $category->getData('path');
133134
if ($origPath != null && $path != null && $origPath != $path) {
134135
$category->unsUrlPath();
136+
if ($category->getStoreId() !== $categoryStoreId) {
137+
$category->setStoreId($categoryStoreId);
138+
$category->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
139+
}
135140
$category->getResource()->saveAttribute($category, 'url_path');
136141
foreach ($this->childrenCategoriesProvider->getChildren($category, true) as $childCategory) {
137142
$childCategory->unsUrlPath();

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ public function testAfterChangeParent()
117117
$storeIds = [0, 1];
118118

119119
$this->storeManagerMock->expects($this->exactly(2))->method('hasSingleStore')->willReturn(false);
120-
$this->categoryMock->expects($this->exactly(4))->method('getStoreId')
121-
->willReturnOnConsecutiveCalls(0, 0, 1, 0);
120+
$this->categoryMock->expects($this->exactly(6))->method('getStoreId')
121+
->willReturnOnConsecutiveCalls(0, 0, 1, 0, 1, 0);
122122
$this->categoryMock->expects($this->once())->method('getStoreIds')->willReturn($storeIds);
123-
$this->categoryMock->expects($this->exactly(4))->method('setStoreId')
124-
->willReturnOnConsecutiveCalls(0, 0, 1, 0);
123+
$this->categoryMock->expects($this->exactly(5))->method('setStoreId')
124+
->willReturnOnConsecutiveCalls(0, 0, 1, 0, 1);
125125

126126
$this->categoryMock->expects($this->exactly(2))->method('getData')
127127
->willReturnOnConsecutiveCalls('1/3/5', '1/3/5');
@@ -146,9 +146,9 @@ public function testAfterChangeParent()
146146
$this->categoryMock->expects($this->exactly(2))->method('setUrlKey')->with('url-key')
147147
->willReturnSelf();
148148

149-
$this->categoryUrlPathGeneratorMock->expects($this->exactly(3))->method('getUrlPath')
149+
$this->categoryUrlPathGeneratorMock->expects($this->exactly(4))->method('getUrlPath')
150150
->with($this->categoryMock)->willReturn($urlPath);
151-
$this->categoryMock->expects($this->exactly(3))->method('setUrlPath')->with($urlPath);
151+
$this->categoryMock->expects($this->exactly(4))->method('setUrlPath')->with($urlPath);
152152

153153
$this->assertSame(
154154
$this->subjectMock,

0 commit comments

Comments
 (0)