Skip to content

Instantly share code, notes, and snippets.

@tuanphpvn
Last active August 4, 2016 00:30
Show Gist options
  • Save tuanphpvn/afe1c63ec50cf7d763da to your computer and use it in GitHub Desktop.
Save tuanphpvn/afe1c63ec50cf7d763da to your computer and use it in GitHub Desktop.
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment