最新消息:Excel无乱码转CSV,由于工作原因很少更新博客和回复大家的评论,非常抱歉。

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

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

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;
}

如果想省劲,直接在继承的类里面直接写,反正做成版本的东西又不升级,稳定才是王道!!

转载请注明:嗨酷哥,有你更酷! » Magento 根据catalog ID得到这个菜单的html代码

与本文相关文章

发表我的评论

取消评论
表情 插代码

Hi,您需要填写昵称和邮箱!

  • 必填项
  • 必填项