Is there any way to find out - to get in some variable, information about category from which the products that shows up from search result are.

For example my specific situation: In advance search I insert one searchable attribute and for result I get 5 products. This 5 products share same attribute and it is also for sure from same category ( webshop have just two root category and ever category has specific and unique range of attributes ) .

So I need ( in code ) the category name or ID from which this listed products are.

1 Answer 1


Will it work for you?

    $collection = $product->getCategoryCollection();
    $collection->getSelect()->order('LENGTH(path) DESC');

    $categoryItems = $collection->load()->getIterator();
    $category      = current($categoryItems);
    if ($category) {
        $category = Mage::getModel('catalog/category')->load($category->getId());
        return $category;

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.