Add a new item to the navigation menu in Magento

New Wave New Thinking

Adding a new item to the navigation menu is fairly simple.

We will add this ability to a custom module. There is no need to modify core Magento files or templates and layouts.

First, we need to rewrite the block that is responsible for menu drawing; however, we will not be using a <rewrite> tag. The reason for this is, if the module is disabled, Magento will break. Instead, will will use an observer for it.

At global scope, in your config.xml file, add the following code:

<events><controller_action_layout_generate_blocks_after>

<observers>

<allproducts>

<type>singleton</type>

<class>Company_ModuleName_Model_Observer</class>

<method>regeneratemenu</method>

</allproducts>

</observers>

</controller_action_layout_generate_blocks_after>

</events>

You can also use other events instead of controller_action_layout_generate_blocks_after. Next, you must create Observer.php in the Model folder using method regenerateMenu

class Company_ModuleName_Model_Observer{public function regenerateMenu($observer)

{

// if module is active

if (!Mage::getStoreConfig(‘advanced/modules_disable_output/Company_ModuleName’))

{

$layout = Mage::getSingleton(‘core/layout’);

// remove all the blocks you don’t want

$layout->getUpdate()->addUpdate(‘<remove name=”catalog.topnav”/>’);

// load layout updates by specified…

View original post 20 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s