2

These are my categories :

Root category
---> Shoes
---- ---> Red    shoes
---- ---> Green  shoes
---- ---> Yellow shoes
---> Shirts
---- ---> Black shirts
---- ---> White shirts
---- ---> Blue  shirts

and my top menu would be like:

-Shoes -Shirts

But I only want to show my shoes in the top menu, Like this :

-Red shoes -Green shoes -Yellow shoes

How can I do that?

1 Answer 1

1

The categories are added in the top menu using this method Mage_Catalog_Model_Observer::addCatalogToTopmenuItems.
buy default the method looks like this:

public function addCatalogToTopmenuItems(Varien_Event_Observer $observer)
{
    $this->_addCategoriesToMenu(Mage::helper('catalog/category')->getStoreCategories(), $observer->getMenu());
}

This means that it adds to the top menu the result of Mage::helper('catalog/category')->getStoreCategories() recursively.
All you need to do is to rewrite this method and make it show only the child categories you need.

Something like this. Let's say that your shoes category id is 5.

public function addCatalogToTopmenuItems(Varien_Event_Observer $observer)
{
    $parent = 5;
    $recursionLevel  = max(0, (int) Mage::app()->getStore()->getConfig('catalog/navigation/max_depth') - 1) //subtract 1 from the set recursion level because we skip a level;
    $categories= Mage::getModel('catalog/category')->getCategories($parent, $recursionLevel, false, false, true);
    $this->_addCategoriesToMenu($categories, $observer->getMenu());
}

I haven't tested it, but I think the idea is there.

7
  • It didn't change anything. Nov 5, 2014 at 12:56
  • 1
    wait...I think I got you question wrong. You mean you want to see in the menu only -Red shoes -Green shoes -Yellow shoes or the parent category shoes also?
    – Marius
    Nov 5, 2014 at 12:57
  • no, not parent category, just subcategories of a specific category ( Shoes ) Nov 5, 2014 at 13:02
  • @AlirezaFallah. Then it means I got it right. My answer should help you achieve what you need.
    – Marius
    Nov 5, 2014 at 13:07
  • I put a die() on the first line o that function in Catalog/Model/Observer.php , It didn't die. Nov 5, 2014 at 13:11

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.