Magento无法识别自定义Topmenu.php

时间:2012-08-07 18:07:44

标签: magento navigation rewrite

我已经构建了一个自定义模块,可以根据后端的自定义属性更改Topmenu链接文本。

该模块在Magento CE 1.7.02上进行了测试,工作率为100%。 现在我正在测试Magento EE 1.12.02并且菜单没有识别重写的Topmenu类(As-in,我可以删除文件中的所有内容,和/或错误拼写XML中的类名,并且没有错误,网站加载很好。)

Something告诉我,Enterprise Edition从与Community Edition不同的位置提取此菜单,但我找不到该位置。

以下是我的配置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;
}
}

1 个答案:

答案 0 :(得分:0)

我在1.11.1.0,但我相信同样的事情正在发生。

如果查看app/design/frontend/base/default/layout/page.xml,您会看到top.menu块缺少CE所拥有的page/html_topmenu块。

<block type="core/text_list" name="top.menu" as="topMenu" translate="label">
    <label>Navigation Bar</label>
</block>

然后,在app/design/frontend/base/default/layout/catalog.xml中,他们将目录导航块插入top.menu块:

<reference name="top.menu">
    <block type="catalog/navigation" name="catalog.topnav" template="catalog/navigation/top.phtml"/>
</reference>

奇怪他们在app/design/frontend/base而不是app/design/frontend/enterprise完成了所有这些工作。