【问题标题】:Menu of categories "not included in navigation bar"类别菜单“未包含在导航栏中”
【发布时间】:2012-07-26 07:01:21
【问题描述】:

如果我是对的,在 Magento 中,renderCategoriesMenuHtml() 函数有助于显示“导航菜单栏中包含的类别”菜单。

我想修改 renderCategoriesMenuHtml() 函数以显示“导航菜单栏中不包含的类别”的菜单。

简而言之,我需要在管理面板中显示一个将属性 "Include in navigation menu" 设置为 no 的类别菜单。

提前致谢。

【问题讨论】:

    标签: magento magento-1.4 magento-1.5


    【解决方案1】:

    Magento 具有更改或添加类功能的工具,称为类覆盖或类重写。以下示例假定命名空间为“Custom”,模块名称为“Nav”。

    首先,注册一个模块:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- app/etc/modules/whatever.xml -->
    <config>
        <modules>
            <Custom_Nav><!-- must match your namespace & module folder names -->
                <active>true</active>
                <codePool>local</codePool>
            </Custom_Nav>
        </modules>
    </config>
    

    根据上述情况,应用程序将为您的模块查找配置文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- app/code/local/Custom/Nav/etc/config.xml -->
    <config>
        <global>
            <blocks>
                <catalog>
                    <rewrite>
                        <navigation>Custom_Nav_Block_Rewrite_Navigation</navigation>
                    </rewrite>
                </catalog>
            </blocks>
        </global>
    </config>
    

    这样做是在块创建工厂方法中重写类名。目录导航块添加到catalog.xml 布局更新 XML (&lt;block type="catalog/navigation" .../&gt;)。上面的 xpath 会导致类名映射到Custom_Nav_Block_Rewrite_Navigation,而不是通常的Mage_Catalog_Block_Navigation,而正是这个类将被实例化。

    最后一步是创建类定义,为了可维护性和遵守 DRY,从原始类扩展:

    <?php
    /* app/code/local/Custom/Nav/Block/Rewrite/Navigation.php */
    
    class Custom_Nav_Block_Rewrite_Navigation extends Mage_Catalog_Block_Navigation
    {
        //custom method overrides & additions belong here
    }
    

    清除 config 和 block_html 缓存,更改应该可见。要验证,请通过管理面板启用模板路径提示 + 块类名称,或在站点根目录中创建一个简单的脚本:

    <?php
    /* test.php in Magento root folder */
    ini_set('display_errors',true);
    
    include 'app/Mage.php';
    Mage::setIsDeveloperMode(true);
    Mage::app();
    
    var_dump(Mage::getConfig()->getBlockClassName('catalog/navigation'));
    

    将浏览器指向http://site.com/test.php,输出应显示重写后的类名。

    【讨论】:

      猜你喜欢
      • 2014-09-26
      • 2012-03-30
      • 2023-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-08
      相关资源
      最近更新 更多