Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort if category is not a child of the root category #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Observers/UrlRewriteObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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]);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a category is not yet present but created on the fly by pacemaker $category[MemberNames::PATH]) is empty and the method will return false.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We somehow have to catch this case and find a different solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanieliMi Sorry, but I think I can't really follow you here. When Pacemaker will create a category on-the-fly, this will happen before this observer will be invoked. Can you please describe in more details how this case can come about?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will improve the Steps to reproduce

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this similar to techdivision/import#209 ?


// load the root category
$rootCategory = $this->getRootCategory();

return $categoryPathParts[1] === $rootCategory[MemberNames::ENTITY_ID];
}

/**
* Adds the entity product relation if necessary.
*
Expand Down