Magento无法识别自定义Topmenu.php [英] Magento not recognizing custom Topmenu.php
问题描述
我已经构建了一个自定义模块,可以基于后端中的自定义属性来更改Topmenu链接文本.
I have built a custom module to enable changing the Topmenu link text based on a custom attribute in the backend.
该模块已在Magento CE 1.7.02上进行了测试,可100%运行. 现在,我正在Magento EE 1.12.02上进行测试,并且菜单无法识别重写的Topmenu类(按原样,我可以从文件中删除所有内容,并且/或者在XML中拼写错误的类名称,并且没有错误,并且网站加载正常).
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.
这是我的配置XML的相关部分:
Here is the relevant portion of my config XML:
<blocks>
<page>
<rewrite>
<html_topmenu>WorldSynergy_Seoadditions_Block_Html_Topmenu</html_topmenu>
</rewrite>
</page>
</blocks>
这是Topmenu.php类:
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.11.1.0,但是我相信确实发生了同样的事情.
I'm in 1.11.1.0, but I believe the same exact thing is happening.
如果查看app/design/frontend/base/default/layout/page.xml
,您会发现top.menu
块缺少CE拥有的page/html_topmenu
块.
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>
然后,在app/design/frontend/base/default/layout/catalog.xml
中,他们将目录导航块插入到top.menu
块中:
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>
奇怪的是,他们在app/design/frontend/base
中而不是在app/design/frontend/enterprise
中完成了所有这些操作.
Strange that they did all of this in app/design/frontend/base
, and not app/design/frontend/enterprise
.
这篇关于Magento无法识别自定义Topmenu.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!