Remove empty categories from magento menu

前端 未结 3 608
忘掉有多难
忘掉有多难 2020-12-12 06:18

I want my main menu to not include any categories that are empty. I\'ve done this for the layered navigation very easily in the relevant phtml file by using



        
3条回答
  •  我在风中等你
    2020-12-12 06:50

    To do this, go to:

    app/code/core/Mage/Catalog/Block Folder and copy Navigation.php and override it in your local package.

    Open Navigation.php of your package and paste below code in this file:

    if ($category->getIsActive()) {
        $cat = Mage::getModel('catalog/category')->load($category->getId());
        $products = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($cat);
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
        Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products);
        if(count($products)==0)
           return;
    }
    

    I hope my code will help you.

提交回复
热议问题