根据catalog ID,得到这个菜单的html代码。

由的时候,我们需要对单独一个菜单进行操作,所以我们需要自由定制,自由的得到magneto的数据代码,这里介绍的就是通过catelog ID直接得到它的子菜单。

1

PHTML

$this->renderCategoriesMenuHtml_ter(0,'level-top')

2

phtml对应的block文件

继承

Mage_Catalog_Block_Navigation

编写方法:

 
public function renderCategoriesMenuHtml_ter($level = 0, $outermostItemClass = '', $childrenWrapClass = '')
    {
        $activeCategories = array();
        foreach ($this->getStoreCategories_ter() as $child) {
            if ($child->getIsActive()) {
                $activeCategories[] = $child;
            }
        }
        $activeCategoriesCount = count($activeCategories);
        $hasActiveCategoriesCount = ($activeCategoriesCount > 0);

        if (!$hasActiveCategoriesCount) {
            return '';
        }

        $html = '';
        $j = 0;
        foreach ($activeCategories as $category) {
            $html .= $this->_renderCategoryMenuItemHtml(
                $category,
                $level,
                ($j == $activeCategoriesCount - 1),
                ($j == 0),
                true,
                $outermostItemClass,
                $childrenWrapClass,
                true
            );
            $j++;
        }

        return $html;
    }

public function getStoreCategories_ter()
    {
        $helpers = Mage::helper('catalog/category');
        return $helpers->getStoreCategories_ter();
    }

3

help类

继承

Mage_Catalog_Helper_Category

public function getStoreCategories_ter($sorted=false, $asCollection=false, $toLoad=true)
    {
        $parent     = 889;  //此处为:catelog ID!!!!!
        $cacheKey   = sprintf('%d-%d-%d-%d', $parent, $sorted, $asCollection, $toLoad);
        if (isset($this->_storeCategories[$cacheKey])) {
            return $this->_storeCategories[$cacheKey];
        }

        /**
         * Check if parent node of the store still exists
         */
        $category = Mage::getModel('catalog/category');
        /* @var $category Mage_Catalog_Model_Category */
        if (!$category->checkId($parent)) {
            if ($asCollection) {
                return new Varien_Data_Collection();
            }
            return array();
        }

        $recursionLevel  = max(0, (int) Mage::app()->getStore()->getConfig('catalog/navigation/max_depth'));
        $storeCategories = $category->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);

        $this->_storeCategories[$cacheKey] = $storeCategories;
        return $storeCategories;
    }
这些都是通过系统的方式,然后分析代码得到的,你也可以通过这种方式顺藤摸瓜得到相应的数据,也可以自己做成插件的形式,呵呵

转载请标明地址:MagentoWater:http://www.magentowater.com/blog/catalog-ids