Skip to content

Commit f875a53

Browse files
committed
Added detecting for more url_path mistakes in categories. Sometimes a parent category overrides the url_path on storeview level while the child category isn't. This logic wasn't been used in the verification of correct url_paths yet.
1 parent be8cd95 commit f875a53

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

Checker/Catalog/Category/UrlPath.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ public function checkForIncorrectUrlPathAttributeValues(): array
6161
$allCategories = $this->getAllVisibleCategoriesWithStoreId($storeId);
6262

6363
foreach ($allCategories as $category) {
64-
$isOverridden = $this
65-
->attributeScopeOverriddenValueFactory
66-
->create()
67-
->containsValue(CategoryInterface::class, $category, self::URL_PATH_ATTRIBUTE, $storeId)
68-
;
64+
$isOverridden = $this->getIsUrlPathOverridden($category, $storeId);
6965

7066
// we don't care about non overwritten values
7167
if (!$isOverridden && $storeId !== Store::DEFAULT_STORE_ID) {
@@ -88,6 +84,43 @@ public function checkForIncorrectUrlPathAttributeValues(): array
8884
return $problems;
8985
}
9086

87+
private function getIsUrlPathOverridden(Category $category, int $storeId): bool
88+
{
89+
$isOverridden = $this
90+
->attributeScopeOverriddenValueFactory
91+
->create()
92+
->containsValue(CategoryInterface::class, $category, self::URL_PATH_ATTRIBUTE, $storeId)
93+
;
94+
95+
// if the current category isn't using an overridden url path, the parent category's still could,
96+
// so we need to check those as well ...
97+
if ($isOverridden === false) {
98+
// phpcs:disable Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
99+
try {
100+
$isParentOverridden = false;
101+
$parentCat = $category;
102+
103+
do {
104+
$parentCat = $parentCat->getParentCategory();
105+
$isParentOverridden = $this
106+
->attributeScopeOverriddenValueFactory
107+
->create()
108+
->containsValue(CategoryInterface::class, $parentCat, self::URL_PATH_ATTRIBUTE, $storeId)
109+
;
110+
} while ($isParentOverridden === false && $parentCat->getLevel() > 1);
111+
112+
if ($isParentOverridden === true) {
113+
$isOverridden = true;
114+
}
115+
} catch (\Throwable $ex) {
116+
// do nothing
117+
}
118+
// phpcs:enable Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
119+
}
120+
121+
return $isOverridden;
122+
}
123+
91124
/**
92125
* @return CategoryCollection<Category>
93126
*/

0 commit comments

Comments
 (0)