1

There are a few answers related to this but the problem I am facing is a little different. I'm only getting categories that are set as visible in Navigation Menu

It happens, for example, when I try to get all categories I have to show them with Mage::helper('catalog/category')->getStoreCategories();

It seemed to give me all categories but it didn't. There are like 10 main categories that I don't include in Navigation Menu with that option to avoid too many categories on the top of the page. Instead, I have an static cms named more where I add those 10 manually at the end of the navigation menu.

So, what I'm asking is if there is a way to get all categories or another way to add these 10 categories in a single menu tab with the navigation menu activated.

2 Answers 2

3

Copy this code on your magento root dir and run it from url.

 <html>
    <body>
    <?php
    error_reporting(E_ALL | E_STRICT);
    $mageFilename = 'app/Mage.php';
    require_once $mageFilename;
    Mage::setIsDeveloperMode(true);
    ini_set('display_errors', 1);
    ini_set('memory_limit', '600M');
    ini_set('max_execution_time', 1800);
    umask(0);
    Mage::app('admin'); 
    ?>
    <?php
    $cat = Mage::getModel('catalog/category')->load(2);
    $subcats = $cat->getChildren();
       $products_row = array();
    foreach(explode(',',$subcats) as $subCatid)
    {
        $data = array();
        $_category = Mage::getModel('catalog/category')->load($subCatid);
        if($_category->getIsActive()) {
            $data[] =   $_category->getName();
            $data[] =   str_replace('/getCat.php','',$_category->getURL()); 
            $sub_cat = Mage::getModel('catalog/category')->load($_category->getId());
            $sub_subcats = $sub_cat->getChildren();
            foreach(explode(',',$sub_subcats) as $sub_subCatid)
            {
                $_sub_category = Mage::getModel('catalog/category')->load($sub_subCatid);
                if($_sub_category->getIsActive()) {
                    $data[] = $_category->getName().' >> '.$_sub_category->getName();           
                    $data[] =   str_replace('/getCat.php','',$_sub_category->getURL()); 

                    $sub_sub_cat = Mage::getModel('catalog/category')->load($sub_subCatid);
                    $sub_sub_subcats = $sub_sub_cat->getChildren();
                    foreach(explode(',',$sub_sub_subcats) as $sub_sub_subCatid)
                    {
                        $_sub_sub_category = Mage::getModel('catalog/category')->load($sub_sub_subCatid);
                        if($_sub_sub_category->getIsActive()) {
                            $data[]= $_category->getName().' >> '.$_sub_category->getName().' >> '.$_sub_sub_category->getName();
                            $data[] = str_replace('/getCat.php','',$_sub_sub_category->getURL());   

                        }
                    }
                }
            }

        }

        $products_row[] = $data; 
    }
     echo '<pre>';
    print_r($products_row);
     echo '<pre>';
    ?>
    </body>
    </html>
3
  • erm mind going into a bit more details on what it should achieve? I assume it is for testing purpose only. Otherwise I don't see why you'd have to put it in your root dir instead of creating a page/template. Aug 6, 2015 at 10:15
  • you can also create template file using this code.
    – Kanika
    Aug 6, 2015 at 10:20
  • This worked, it shows all categories even if they are on navigation menu or not. Thank you very much, and thank you for your fast answer too. :)
    – danibg
    Aug 6, 2015 at 10:42
2

Try this. It will load all the categories even if they are not visible in the main menu.

$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();

foreach($categories as $cat) {
    echo $cat->getName() . "<br>";
}

Your Answer

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

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