我已经构建了一个自定义模块,可以根据后端的自定义属性更改 Topmenu 链接文本。
该模块在 Magento CE 1.7.02 上进行了测试,并且可以 100% 运行。现在我正在 Magento EE 1.12.02 上进行测试,并且菜单无法识别重写的 Topmenu 类(因为,我可以从文件中删除所有内容,和/或在 XML 中拼错类名并且没有错误,并且网站加载正常)。
有些东西告诉我,企业版从与社区版不同的位置提取此菜单,但我找不到该位置。
这是我的配置 XML 的相关部分:
<blocks>
<page>
<rewrite>
<html_topmenu>WorldSynergy_Seoadditions_Block_Html_Topmenu</html_topmenu>
</rewrite>
</page>
</blocks>
这是 Topmenu.php 类:
class WorldSynergy_Seoadditions_Block_Html_Topmenu extends Mage_Page_Block_Html_Topmenu
{
/**
* Recursively generates top menu html from data that is specified in $menuTree
*
* @param Varien_Data_Tree_Node $menuTree
* @param string $childrenWrapClass
* @return string
*/
protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass)
{
$html = '';
$children = $menuTree->getChildren();
$parentLevel = $menuTree->getLevel();
$childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;
$counter = 1;
$childrenCount = $children->count();
$parentPositionClass = $menuTree->getPositionClass();
$itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';
foreach ($children as $child) {
$child->setLevel($childLevel);
$child->setIsFirst($counter == 1);
$child->setIsLast($counter == $childrenCount);
$child->setPositionClass($itemPositionClassPrefix . $counter);
$outermostClassCode = '';
$outermostClass = $menuTree->getOutermostClass();
if ($childLevel == 0 && $outermostClass) {
$outermostClassCode = ' class="' . $outermostClass . '" ';
$child->setClass($outermostClass);
}
$childId = explode( "-" , $child->getId() );
$childId = $childId[2];
$attrs = Mage::getModel("catalog/category")->getAttributes();
$altName = $attrs['ws_menutitle']->getFrontEnd()->getValue( Mage::getModel("catalog/category")->load( $childId ) );
if( empty($altName) ){ $altName = $child->getName(); }
$html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>ABC'
. $this->escapeHtml($altName) . '</span></a>';
if ($child->hasChildren()) {
if (!empty($childrenWrapClass)) {
$html .= '<div class="' . $childrenWrapClass . '">';
}
$html .= '<ul class="level' . $childLevel . '">';
$html .= $this->_getHtml($child, $childrenWrapClass);
$html .= '</ul>';
if (!empty($childrenWrapClass)) {
$html .= '</div>';
}
}
$html .= '</li>';
$counter++;
}
return $html;
}
}