Magento not recognizing custom Topmenu.php

2019-09-10 08:19发布

I have built a custom module to enable changing the Topmenu link text based on a custom attribute in the backend.

The module was tested on Magento CE 1.7.02 and works 100%. Now I am testing on Magento EE 1.12.02 and the menu is not recognizing the rewritten Topmenu class (As-in, I can remove everything from the file, and/or mis-spell the class name in the XML and there are no errors, and the site loads fine).

Something tells me that Enterprise Edition pulls this menu from a different location than Community Edition, but I cannot find the place.

Here is the relevant portion of my config XML:

<blocks>
    <page>
        <rewrite>
            <html_topmenu>WorldSynergy_Seoadditions_Block_Html_Topmenu</html_topmenu>
        </rewrite>
    </page>
</blocks>

And here is the Topmenu.php class:

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条回答
在下西门庆
2楼-- · 2019-09-10 09:15

I'm in 1.11.1.0, but I believe the same exact thing is happening.

If you look at app/design/frontend/base/default/layout/page.xml, you'll see that the top.menu block is missing the page/html_topmenu block that CE has.

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

Then, in app/design/frontend/base/default/layout/catalog.xml, they're inserting the catalog navigation block into the top.menu block:

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

Strange that they did all of this in app/design/frontend/base, and not app/design/frontend/enterprise.

查看更多
登录 后发表回答