diff --git a/src/Observers/UrlRewriteObserver.php b/src/Observers/UrlRewriteObserver.php index 11c311e..a2b9860 100644 --- a/src/Observers/UrlRewriteObserver.php +++ b/src/Observers/UrlRewriteObserver.php @@ -405,6 +405,11 @@ protected function resolveCategoryIds($categoryId, $topLevel = false, $storeView // load the data of the category with the passed ID $category = $this->getCategory($categoryId, $storeViewCode); + // if the category is not a child of the root category we have to skip it + if (!$this->isChildOfRootCategory($category)) { + return; + } + // create the product category relation for the current category $this->createProductCategoryRelation($category, $topLevel); @@ -417,6 +422,24 @@ protected function resolveCategoryIds($categoryId, $topLevel = false, $storeView } } + /** + * Check if category is a child of the root category + * + * @param array $category The category to check + * + * @return bool + */ + protected function isChildOfRootCategory($category) + { + // split the path into its segments + $categoryPathParts = explode('/', $category[MemberNames::PATH]); + + // load the root category + $rootCategory = $this->getRootCategory(); + + return $categoryPathParts[1] === $rootCategory[MemberNames::ENTITY_ID]; + } + /** * Adds the entity product relation if necessary. *