2

I am looking for a way to get a products most child like category. For example if I have

    category1 -> category1.1 -> category1.1.1

I then need category1.1.1

Assuming I have a product that belongs to all three categories is there a specific way to call the most deeply rooted category.

I know I can return all categories belonging to a product by doing this:

    echo $_product->getCategoryIds()

But I need a programmatical way to know which is the deepest child.

1 Answer 1

2

For anyone needing the same solution I managed it like this:

The products deepest category happens to be related to the product through an attribute set up previously. It was simply a case of calling the attribute then to get the category

    $mainCategory = Mage::getModel('catalog/category')->load($_product->getMainCategory());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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