function megamenu(){
$children = Mage::getModel('catalog/category')->getCategories(2);
if(count($children) > 0){
$i=0;
$level=1;
foreach ($children as $category) {
//echo $category->getName();
if($category->getName()){
$id = $category->getId();
$data[$i]['id'] = $category->getId();
$data[$i]['name'] = $category->getName();
$data[$i]['level'] = $level;
//$data[$i]['subcategory'] = array();
$data[$i]['subcategory'] = mycategory($id,$level);
$i++;
}
}
}
//echo "<pre>";print_r($data);
return $data;
}
function mycategory($id,$parent_level){
$sub = array();
$children = Mage::getModel('catalog/category')->getCategories($id);
if(count($children) > 0){
$i=0;
$level=1;
foreach ($children as $category) {
//echo $category->getName();
$id = $category->getId();
$sub[$i]['id'] = $category->getId();
$sub[$i]['name'] = $category->getName();
$sub[$i]['level'] = $parent_level.''.$level;
$sub[$i]['subcategory'] = mycategory($id,$parent_level.''.$level);
$i++;
$level++;
}
}
return $sub;
}
获得magento分类树
最新推荐文章于 2024-06-13 13:37:29 发布