在magento 1.9.2中创建自定义顶部菜单


Creating a custom top menu in magento 1.9.2

我试图通过添加自定义类重写app/code/core/Mage/catalog/Block/Navigation.php,在magento 1.9.2中创建一个自定义顶部菜单。我创建了一个新的本地扩展名,其中包含以下文件

应用程序/etc/模块/Customnav_Catalog.xml

<?xml version="1.0"?>
<config>
  <modules>
<Customnav_Catalog>
  <active>true</active>
  <codePool>local</codePool>
  <version>0.1.0</version>
</Customnav_Catalog>
  </modules>
</config>

应用程序/代码/地方/Customnav/目录/etc/config . xml

<?xml version="1.0"?>
<config>
<modules>
    <Customnav_Catalog>
        <version>0.1.0</version>
    </Customnav_Catalog>
</modules>
<global>
    <helpers>
      <Customnav_Catalog>
        <class>Customnav_Catalog_Helper</class>
      </Customnav_Catalog>
    </helpers>
    <blocks>
        <Customnav_Catalog>
            <class>Customnav_Catalog_Block</class>
        </Customnav_Catalog>
        <Customnav_Catalog>
            <class>Customnav_Catalog_Block</class>
            <rewrite>
                <navigation>Customnav_Catalog_Block_Catalog_Navigation</navigation>
            </rewrite>
        </Customnav_Catalog>
    </blocks>
</global>
</config>

应用程序/代码/地方/Customnav/目录/帮助/Data.php

class Customnav_Catalog_Helper_Data extends Mage_Core_Helper_Abstract {}

app/代码/地方/Customnav/目录/块/Navigation.php

我添加了这行代码来添加新类,但不被magento识别
$classes[] = 'nav-item ';

我想添加额外的引导类导航。php。

我是否正确地重写了Navigation.php?

是否有其他方法来自定义顶部菜单?

没有。要正确覆盖Mage_Catalog_Block_Navigation,您需要将重写放置在特定的块配置中。所以不是:

<blocks>
    <Customnav_Catalog>
        <class>Customnav_Catalog_Block</class>
    </Customnav_Catalog>
    <Customnav_Catalog>
        <class>Customnav_Catalog_Block</class>
        <rewrite>
            <navigation>Customnav_Catalog_Block_Catalog_Navigation</navigation>
        </rewrite>
    </Customnav_Catalog>
</blocks>

你应该写:

<blocks>
    <Customnav_Catalog>
        <class>Customnav_Catalog_Block</class>
    </Customnav_Catalog>
    <catalog>
        <rewrite>
            <navigation>Customnav_Catalog_Block_Catalog_Navigation</navigation>
        </rewrite>
    </catalog>
</blocks>

上面的代码片段'告诉'配置,如果调用Mage::app()->getLayout()->createBlock('catalog/navigation')(例如),它不应该返回原始块,而是返回重写规则中规定的块(这是您的)。