<?php
?>
<?php
 
class Lehui_AllCategoryList_Block_List extends Mage_Core_Block_Template
{
    
    protected $_store;
    protected $_baseUrl;
    
    protected function _construct(){
        parent::_construct();
        $this->_init();
    }
    
    protected function _init(){
        $this->_store=Mage::app()->getStore();
         $this->_baseUrl=Mage::getBaseUrl();
    }
    
    
    public function getAllCategory(){
        
        $parentId = 1;
        
        $tree = Mage::getResourceSingleton('catalog/category_tree')->load();
        $root = $tree->getNodeById($parentId);
        if($root && $root->getId() == 1) {
            $root->setName(Mage::helper('catalog')->__('Root'));
        }
        foreach(get_class_methods($tree) as $item){
           // echo $item,"</br>";
        }
        $collection = Mage::getModel('catalog/category')->getCollection()
                        ->addAttributeToSelect('name')
                        ->addAttributeToSelect('url_path')
                        ->addAttributeToSelect('path')
                        ->addAttributeToSelect('is_active')
                        ->addIsActiveFilter();
        //echo $collection->getSelectSql();//->addPathFilter('1\\/'.$this->_store->getRootCategoryId().'\\/')
        foreach(get_class_methods($collection) as $item){
            //echo $item,"</br>";
        }
        $tree->addCollectionData($collection, true);
        $root=$this->_nodeToArray($root);
        $this->_print_tree($root['children'],0);
    }
    
    
    protected function _print_tree($tree,$level){
        $level++;
        foreach($tree as $item){
            if($level>1&preg_match('/1\\/'.$this->_store->getRootCategoryId().'\\//',$item['path'])){
                echo str_repeat('&nbsp;&nbsp;', $level).'<a href="'.$item['url'].'">'.$item['name']."</a><br>";
            }
            $this->_print_tree($item['children'],$level); 
        }
    }
    
    
    protected function _nodeToArray(Varien_Data_Tree_Node $node){
        $result = array();
        $result['category_id'] = $node->getId();
        $result['parent_id'] = $node->getParentId();
        $result['name'] = $node->getName();
        $result['is_active'] = $node->getIsActive();
        $result['position'] = $node->getPosition();
        $result['level'] = $node->getLevel();
        $result['url']=$this->_baseUrl.$node->getData('url_path');
        $result['path']=$node->getData('path');
        $result['children'] = array();
        
        foreach ($node->getChildren() as $child) {
            $result['children'][] = $this->_nodeToArray($child);
        }
        
        return $result;
    }
    
    
    
}

最新文章

  1. Linux下,使用Git管理 dotfiles(配置文件)
  2. oracle 查询数据库表空间大小和剩余空间
  3. (5)分布式下的爬虫Scrapy应该如何做-windows下的redis的安装与配置
  4. 虚拟机Linux----Ubuntu1204----设置固定Ip
  5. java 21-13 合并
  6. Java 线程并发策略
  7. hdu 5755(高斯消元——模线性方程组模板)
  8. maven项目转eclipse工程的命令:eclipse.bat
  9. mysql关联更新
  10. Android创建启动画面
  11. oracle从备份归档日志的方法集中回收
  12. 使用 pprof 和 Flame-Graph 调试 Golang 应用
  13. Java之CyclicBarrier使用,任务等待
  14. ES6中的解构赋值
  15. [HNOI2018]排列
  16. Redis一次数据丢失
  17. Jenkins插件开发(二)-- HelloWorld
  18. Linus&#39; Law
  19. 认识单点登录cas
  20. 03、同事分享课程的笔记 —《Android应用低功耗设计》

热门文章

  1. libxml2的安装及使用[总结]
  2. 转: git使用时让http记住帐号密码
  3. MFC获得当前用户等信息
  4. 使用Feign时报错Service id not legal hostname
  5. Netcore使用MailKit进行邮件发送
  6. C#随机数字生成的一种方法
  7. Spring-boot加载resources下的文件
  8. tempermonkey相关
  9. JAVA_SE基础——26.[深入解析]局部变量与成员变量的差别
  10. Eclipse远程连接Hadoop