Skip to content

Commit 5a92658

Browse files
ENGCOM-6124: Fixes magento#25120 stores the attribute url_path for non-default Stores magento#25143
2 parents 8568cc9 + fb473b3 commit 5a92658

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

app/code/Magento/CatalogUrlRewrite/Observer/CategoryUrlPathAutogeneratorObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
9494
$resultUrlKey = $this->categoryUrlPathGenerator->getUrlKey($category);
9595
$this->updateUrlKey($category, $resultUrlKey);
9696
} elseif ($useDefaultAttribute) {
97-
if (!$category->isObjectNew()) {
97+
if (!$category->isObjectNew() && $category->getStoreId() === Store::DEFAULT_STORE_ID) {
9898
$resultUrlKey = $category->formatUrlKey($category->getOrigData('name'));
9999
$this->updateUrlKey($category, $resultUrlKey);
100100
}

app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/CategoryUrlPathAutogeneratorObserverTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ public function testShouldThrowExceptionIfUrlKeyIsEmpty($useDefaultUrlKey, $isOb
159159
$this->expectExceptionMessage('Invalid URL key');
160160
$categoryData = ['use_default' => ['url_key' => $useDefaultUrlKey], 'url_key' => '', 'url_path' => ''];
161161
$this->category->setData($categoryData);
162+
$this->category
163+
->method('getStoreId')
164+
->willReturn(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
162165
$this->category->isObjectNew($isObjectNew);
163166
$this->assertEquals($isObjectNew, $this->category->isObjectNew());
164167
$this->assertEquals($categoryData['url_key'], $this->category->getUrlKey());

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
use Magento\Framework\Message\MessageInterface;
1616
use Magento\Framework\Serialize\Serializer\Json;
1717
use Magento\Store\Api\StoreRepositoryInterface;
18-
use Magento\TestFramework\TestCase\AbstractBackendController;
1918
use Magento\TestFramework\Helper\Bootstrap;
19+
use Magento\TestFramework\TestCase\AbstractBackendController;
2020

2121
/**
2222
* Test for category backend actions
@@ -63,6 +63,7 @@ protected function setUp()
6363
* @param array $defaultAttributes
6464
* @param array $attributesSaved
6565
* @return void
66+
* @throws \Magento\Framework\Exception\NoSuchEntityException
6667
*/
6768
public function testSaveAction(array $inputData, array $defaultAttributes, array $attributesSaved = []): void
6869
{
@@ -107,6 +108,8 @@ public function testSaveAction(array $inputData, array $defaultAttributes, array
107108
* @magentoDbIsolation enabled
108109
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories.php
109110
* @return void
111+
* @throws \Magento\Framework\Exception\CouldNotSaveException
112+
* @throws \Magento\Framework\Exception\NoSuchEntityException
110113
*/
111114
public function testDefaultValueForCategoryUrlPath(): void
112115
{
@@ -125,19 +128,20 @@ public function testDefaultValueForCategoryUrlPath(): void
125128
// set default url_path and check it
126129
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
127130
$postData = $category->getData();
128-
$postData['use_default'] = [
129-
'available_sort_by' => 1,
130-
'default_sort_by' => 1,
131-
'url_key' => 1,
132-
];
131+
$postData['use_default'] =
132+
[
133+
'available_sort_by' => 1,
134+
'default_sort_by' => 1,
135+
'url_key' => 1,
136+
];
133137
$this->getRequest()->setPostValue($postData);
134138
$this->dispatch('backend/catalog/category/save');
135139
$this->assertSessionMessages(
136140
$this->equalTo([(string)__('You saved the category.')]),
137141
MessageInterface::TYPE_SUCCESS
138142
);
139143
$category = $this->categoryRepository->get($categoryId);
140-
$this->assertEquals($defaultUrlPath, $category->getData('url_path'));
144+
$this->assertEquals($defaultUrlPath, $category->getData('url_key'));
141145
}
142146

143147
/**

0 commit comments

Comments
 (0)