Skip to content

Commit 70bbd3e

Browse files
committed
Merge branch 'v1-develop' into tryout-phpstan-v1
2 parents 5544917 + 654800a commit 70bbd3e

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) {
@@ -90,6 +86,43 @@ public function checkForIncorrectUrlPathAttributeValues(): array
9086
return $problems;
9187
}
9288

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

0 commit comments

Comments
 (0)