0

I am overriding Mage_Catalog_Model_Product method getProductUrl($useSid = null). how to check whether the product is assigned to specific "Root Category A" or its sub categories or not?

1

You can get the categories a product is assigned to by using the method getCategoryIds() on your product object. In your case, since you have extended the product model, $this->getCategoryIds() will work.

You will get an array of category ids.

From further comments, an update to the answer.

Once you have the category ids you would need to load the categories, and form the category object, get the Path of the category. ($category->getPath())

This will result in a values like such : 2/4/56/78/90 - the ids listed is the category ids up to the category you are currently looking at. The path values = the category tree path of that category all the way up to the root category.

Does that help?

| improve this answer | |
  • thanks, i already got getCategoryIds. how do I check if a product has a subcategory which is a child from a specific Root Category even though that product is not assigned to a Root Category? Basically i just need to know whether a product is under Root Category A or not. – Doni Wibowo Oct 7 '14 at 6:18
  • Ok, so you are talking about Anchor root categories, which is not the same thing as having a product assigned to that category. I have updated my answer a bit. – ProxiBlue Oct 7 '14 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.