tuan
9/11/2015 - 10:08 AM

Get all category id by Level 2 (Level -1 is root category)

Get all category id by Level 2 (Level -1 is root category)

<?php

$getAllIdOfRootCategory = function($catname) {
    $rootCategoryObj = Mage::getModel('catalog/category')->loadByAttribute('name', $catname);
    $collection = Mage::getModel('catalog/category')
        ->getCollection()
        ->addPathsFilter($rootCategoryObj->getPath().'/');

    $arr = array();
    foreach($collection as $catObj) {
        $arr[] = $catObj->getId();
    }

    return implode(",", $arr);
};
//echo $getAllIdOfRootCategory('AcerEMEA Root');