Skip to content

Commit 102cc0f

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 7bef077 commit 102cc0f

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,31 @@ class CategoryUrlPathAutogeneratorObserver implements ObserverInterface
4848
*/
4949
private $categoryRepository;
5050

51+
/**
52+
* @var \Magento\Backend\App\Area\FrontNameResolver
53+
*/
54+
private $frontNameResolver;
55+
5156
/**
5257
* @param CategoryUrlPathGenerator $categoryUrlPathGenerator
5358
* @param ChildrenCategoriesProvider $childrenCategoriesProvider
5459
* @param \Magento\CatalogUrlRewrite\Service\V1\StoreViewService $storeViewService
5560
* @param CategoryRepositoryInterface $categoryRepository
61+
* @param \Magento\Backend\App\Area\FrontNameResolver $frontNameResolver
5662
*/
5763
public function __construct(
5864
CategoryUrlPathGenerator $categoryUrlPathGenerator,
5965
ChildrenCategoriesProvider $childrenCategoriesProvider,
6066
StoreViewService $storeViewService,
61-
CategoryRepositoryInterface $categoryRepository
67+
CategoryRepositoryInterface $categoryRepository,
68+
\Magento\Backend\App\Area\FrontNameResolver $frontNameResolver = null
6269
) {
6370
$this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
6471
$this->childrenCategoriesProvider = $childrenCategoriesProvider;
6572
$this->storeViewService = $storeViewService;
6673
$this->categoryRepository = $categoryRepository;
74+
$this->frontNameResolver = $frontNameResolver ?: \Magento\Framework\App\ObjectManager::getInstance()
75+
->get(\Magento\Backend\App\Area\FrontNameResolver::class);
6776
}
6877

6978
/**
@@ -102,12 +111,12 @@ private function updateUrlKey($category, $urlKey)
102111
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid URL key'));
103112
}
104113

105-
if (in_array($urlKey, $this->invalidValues)) {
114+
if (in_array($urlKey, $this->getInvalidValues())) {
106115
throw new \Magento\Framework\Exception\LocalizedException(
107116
__(
108117
'URL key "%1" conflicts with reserved endpoint names: %2. Try another url key.',
109118
$urlKey,
110-
implode(', ', $this->invalidValues)
119+
implode(', ', $this->getInvalidValues())
111120
)
112121
);
113122
}
@@ -122,6 +131,16 @@ private function updateUrlKey($category, $urlKey)
122131
}
123132
}
124133

134+
/**
135+
* Get reserved endpoint names.
136+
*
137+
* @return array
138+
*/
139+
private function getInvalidValues()
140+
{
141+
return array_unique(array_merge($this->invalidValues, [$this->frontNameResolver->getFrontName()]));
142+
}
143+
125144
/**
126145
* Update url path for children category.
127146
*

0 commit comments

Comments
 (0)