1
votes

I'm trying to crate a custom top menu in magento 1.9.2 by overriding app/code/core/Mage/catalog/Block/Navigation.php by adding custom classes. I created a a new local extension that has this following file on it

app/etc/modules/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>

app/code/local/Customnav/catalog/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>

app/code/local/Customnav/catalog/Helper/Data.php

class Customnav_Catalog_Helper_Data extends Mage_Core_Helper_Abstract {}

app/code/local/Customnav/catalog/Block/Navigation.php

inside this function _renderCategoryMenuItemHtml I add this line of code to add new class but doesn't recognize by magento

$classes[] = 'nav-item ';

I would like to add additional bootstrap class to Navigation.php.

Did I properly override Navigation.php?

Is there other way to customize the top menu?

1

1 Answers

0
votes

No you did not. To properly override Mage_Catalog_Block_Navigation you need to place the rewrite in that specific block-configuration. So instead of:

<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>

You should write:

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

The above snippet 'tells' the confguration that if Mage::app()->getLayout()->createBlock('catalog/navigation') is called (for example) it should not return the original block, but the block as stated in the rewrite-rule (which is yours).