Skip to content

Commit

Permalink
Added detecting for more url_path mistakes in categories. Sometimes a…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
hostep committed Dec 20, 2021
1 parent be8cd95 commit f875a53
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions Checker/Catalog/Category/UrlPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ public function checkForIncorrectUrlPathAttributeValues(): array
$allCategories = $this->getAllVisibleCategoriesWithStoreId($storeId);

foreach ($allCategories as $category) {
$isOverridden = $this
->attributeScopeOverriddenValueFactory
->create()
->containsValue(CategoryInterface::class, $category, self::URL_PATH_ATTRIBUTE, $storeId)
;
$isOverridden = $this->getIsUrlPathOverridden($category, $storeId);

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

private function getIsUrlPathOverridden(Category $category, int $storeId): bool
{
$isOverridden = $this
->attributeScopeOverriddenValueFactory
->create()
->containsValue(CategoryInterface::class, $category, self::URL_PATH_ATTRIBUTE, $storeId)
;

// if the current category isn't using an overridden url path, the parent category's still could,
// so we need to check those as well ...
if ($isOverridden === false) {
// phpcs:disable Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
try {
$isParentOverridden = false;
$parentCat = $category;

do {
$parentCat = $parentCat->getParentCategory();
$isParentOverridden = $this
->attributeScopeOverriddenValueFactory
->create()
->containsValue(CategoryInterface::class, $parentCat, self::URL_PATH_ATTRIBUTE, $storeId)
;
} while ($isParentOverridden === false && $parentCat->getLevel() > 1);

if ($isParentOverridden === true) {
$isOverridden = true;
}
} catch (\Throwable $ex) {
// do nothing
}
// phpcs:enable Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
}

return $isOverridden;
}

/**
* @return CategoryCollection<Category>
*/
Expand Down

0 comments on commit f875a53

Please sign in to comment.