Skip to content

Commit b7d0657

Browse files
MAGETWO-69825: [GITHUB #9891] Subcategory "liquid-hand-soap" is not opened in category "soap"
- Implemented validation URL key during category creation
1 parent b899349 commit b7d0657

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class CategoryUrlPathAutogeneratorObserver implements ObserverInterface
2424
/**
2525
* Reserved endpoint names.
2626
*
27-
* @var array
27+
* @var string[]
2828
*/
29-
private $invalidValues = ['admin', 'soap', 'rest', 'graphql'];
29+
private $invalidValues = [];
3030

3131
/**
3232
* @var \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator
@@ -59,20 +59,23 @@ class CategoryUrlPathAutogeneratorObserver implements ObserverInterface
5959
* @param \Magento\CatalogUrlRewrite\Service\V1\StoreViewService $storeViewService
6060
* @param CategoryRepositoryInterface $categoryRepository
6161
* @param \Magento\Backend\App\Area\FrontNameResolver $frontNameResolver
62+
* @param string[] $invalidValues
6263
*/
6364
public function __construct(
6465
CategoryUrlPathGenerator $categoryUrlPathGenerator,
6566
ChildrenCategoriesProvider $childrenCategoriesProvider,
6667
StoreViewService $storeViewService,
6768
CategoryRepositoryInterface $categoryRepository,
68-
\Magento\Backend\App\Area\FrontNameResolver $frontNameResolver = null
69+
\Magento\Backend\App\Area\FrontNameResolver $frontNameResolver = null,
70+
array $invalidValues = []
6971
) {
7072
$this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
7173
$this->childrenCategoriesProvider = $childrenCategoriesProvider;
7274
$this->storeViewService = $storeViewService;
7375
$this->categoryRepository = $categoryRepository;
7476
$this->frontNameResolver = $frontNameResolver ?: \Magento\Framework\App\ObjectManager::getInstance()
7577
->get(\Magento\Backend\App\Area\FrontNameResolver::class);
78+
$this->invalidValues = $invalidValues;
7679
}
7780

7881
/**
@@ -116,7 +119,7 @@ private function updateUrlKey($category, $urlKey)
116119
if (in_array($urlKey, $this->getInvalidValues())) {
117120
throw new \Magento\Framework\Exception\LocalizedException(
118121
__(
119-
'URL key "%1" conflicts with reserved endpoint names: %2. Try another url key.',
122+
'URL key "%1" matches a reserved endpoint name (%2). Use another URL key.',
120123
$urlKey,
121124
implode(', ', $this->getInvalidValues())
122125
)

app/code/Magento/CatalogUrlRewrite/Test/Mftf/Test/AdminCategoryWithRestrictedUrlKeyNotCreatedTest.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
<argument name="categoryName" value="admin"/>
4646
<argument name="categoryUrlKey" value=""/>
4747
</actionGroup>
48-
<see userInput='URL key "admin" conflicts with reserved endpoint names: admin, soap, rest, graphql. Try another url key.' stepKey="seeAdminFirstErrorMessage"/>
48+
<see userInput='URL key "soap" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.' stepKey="seeAdminFirstErrorMessage"/>
4949
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillAdminSecondCategoryForm">
5050
<argument name="categoryName" value="{{SimpleSubCategory.name}}"/>
5151
<argument name="categoryUrlKey" value="admin"/>
5252
</actionGroup>
53-
<see userInput='URL key "admin" conflicts with reserved endpoint names: admin, soap, rest, graphql. Try another url key.' stepKey="seeAdminSecondErrorMessage"/>
53+
<see userInput='URL key "soap" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.' stepKey="seeAdminSecondErrorMessage"/>
5454
<!--Create category with 'admin' name-->
5555
<comment userInput="Create category with 'admin' name" stepKey="commentAdminCategoryCreation"/>
5656
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillAdminThirdCategoryForm">
@@ -66,12 +66,12 @@
6666
<argument name="categoryName" value="soap"/>
6767
<argument name="categoryUrlKey" value=""/>
6868
</actionGroup>
69-
<see userInput='URL key "soap" conflicts with reserved endpoint names: admin, soap, rest, graphql. Try another url key.' stepKey="seeSoapFirstErrorMessage"/>
69+
<see userInput='URL key "soap" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.' stepKey="seeSoapFirstErrorMessage"/>
7070
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillSoapSecondCategoryForm">
7171
<argument name="categoryName" value="{{ApiCategory.name}}"/>
7272
<argument name="categoryUrlKey" value="soap"/>
7373
</actionGroup>
74-
<see userInput='URL key "soap" conflicts with reserved endpoint names: admin, soap, rest, graphql. Try another url key.' stepKey="seeSoapSecondErrorMessage"/>
74+
<see userInput='URL key "soap" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.' stepKey="seeSoapSecondErrorMessage"/>
7575
<!--Create category with 'soap' name-->
7676
<comment userInput="Create category with 'soap' name" stepKey="commentSoapCategoryCreation"/>
7777
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillSoapThirdCategoryForm">
@@ -87,12 +87,12 @@
8787
<argument name="categoryName" value="rest"/>
8888
<argument name="categoryUrlKey" value=""/>
8989
</actionGroup>
90-
<see userInput='URL key "rest" conflicts with reserved endpoint names: admin, soap, rest, graphql. Try another url key.' stepKey="seeRestFirstErrorMessage"/>
90+
<see userInput='URL key "soap" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.' stepKey="seeRestFirstErrorMessage"/>
9191
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillRestSecondCategoryForm">
9292
<argument name="categoryName" value="{{SubCategoryWithParent.name}}"/>
9393
<argument name="categoryUrlKey" value="rest"/>
9494
</actionGroup>
95-
<see userInput='URL key "rest" conflicts with reserved endpoint names: admin, soap, rest, graphql. Try another url key.' stepKey="seeRestSecondErrorMessage"/>
95+
<see userInput='URL key "soap" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.' stepKey="seeRestSecondErrorMessage"/>
9696
<!--Create category with 'rest' name-->
9797
<comment userInput="Create category with 'rest' name" stepKey="commentRestCategoryCreation"/>
9898
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillRestThirdCategoryForm">
@@ -108,12 +108,12 @@
108108
<argument name="categoryName" value="graphql"/>
109109
<argument name="categoryUrlKey" value=""/>
110110
</actionGroup>
111-
<see userInput='URL key "graphql" conflicts with reserved endpoint names: admin, soap, rest, graphql. Try another url key.' stepKey="seeGraphQlFirstErrorMessage"/>
111+
<see userInput='URL key "soap" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.' stepKey="seeGraphQlFirstErrorMessage"/>
112112
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillGraphQlSecondCategoryForm">
113113
<argument name="categoryName" value="{{NewSubCategoryWithParent.name}}"/>
114114
<argument name="categoryUrlKey" value="graphql"/>
115115
</actionGroup>
116-
<see userInput='URL key "graphql" conflicts with reserved endpoint names: admin, soap, rest, graphql. Try another url key.' stepKey="seeGraphQlSecondErrorMessage"/>
116+
<see userInput='URL key "soap" matches a reserved endpoint name (admin, soap, rest, graphql, standard). Use another URL key.URL key "graphql" conflicts with reserved endpoint names: admin, soap, rest, graphql. Try another url key.' stepKey="seeGraphQlSecondErrorMessage"/>
117117
<!--Create category with 'graphql' name-->
118118
<comment userInput="Create category with 'graphql' name" stepKey="commentGraphQlCategoryCreation"/>
119119
<actionGroup ref="FillCategoryNameAndUrlKeyAndSave" stepKey="fillGraphQlThirdCategoryForm">

app/code/Magento/CatalogUrlRewrite/etc/di.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,15 @@
4545
</argument>
4646
</arguments>
4747
</type>
48+
<type name="Magento\CatalogUrlRewrite\Observer\CategoryUrlPathAutogeneratorObserver">
49+
<arguments>
50+
<argument name="invalidValues" xsi:type="array">
51+
<item name="0" xsi:type="string">admin</item>
52+
<item name="1" xsi:type="string">soap</item>
53+
<item name="2" xsi:type="string">rest</item>
54+
<item name="3" xsi:type="string">graphql</item>
55+
<item name="4" xsi:type="string">standard</item>
56+
</argument>
57+
</arguments>
58+
</type>
4859
</config>

app/code/Magento/CatalogUrlRewrite/i18n/en_US.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
"Product URL Suffix","Product URL Suffix"
66
"Use Categories Path for Product URLs","Use Categories Path for Product URLs"
77
"Create Permanent Redirect for URLs if URL Key Changed","Create Permanent Redirect for URLs if URL Key Changed"
8-
"Generate "category/product" URL Rewrites","Generate "category/product" URL Rewrites"
8+
"Generate "category/product" URL Rewrites","Generate "category/product" URL Rewrites"
9+
"URL key ""%1"" matches a reserved endpoint name (%2). Use another URL key.","URL key ""%1"" matches a reserved endpoint name (%2). Use another URL key."

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ public function testSaveWithCustomBackendNameAction()
592592
$this->assertSessionMessages(
593593
$this->equalTo(
594594
[
595-
'URL key "backend" conflicts with reserved endpoint names: '
596-
. 'admin, soap, rest, graphql, backend. Try another url key.'
595+
'URL key "backend" matches a reserved endpoint name '
596+
. '(admin, soap, rest, graphql, standard, backend). Use another URL key.'
597597
]
598598
),
599599
MessageInterface::TYPE_ERROR

0 commit comments

Comments
 (0)