Wednesday 17 June 2015

Remove Customer Account Navigation Links using Layout XML - Magento

Magento gives big and expansive library of features and some of us we don't need all features.If we keep all the features provided by magento then it could create a frustrating experience for site users as some features might not do anything.One of this type feature is customer account navigation menu



I will show you how to remove some of these links by implementing a layout XML method to remove them via a class rewrite. As an example of a link we're going to remove, let's take a look at the Recurring Profiles link in that list.

That link is added with this layout XML declaration in app/design/frontend/base/default/layout/sales/recurring_profile.xml:

<customer_account>
<reference name="customer_account_navigation" >
<action method="addLink" translate="label">
<name>recurring_profiles</name>
<path>sales/recurring_profile/</path>
<label>Recurring Profiles</label>
</action>
</reference>
</customer_account>

So removing or commenting the above code makes us to get rid of the links in the customer navigation links but in how many files you do same thing (commenting) and it will many xml files to do so. and you need to copy the xml file into the your theme directory and comment.

So best approach is to make a small module and remove all this links from one xml file. to do so follow the following steps

Step 1) Create module's xml file 'Prasan_CustomerNavigationLinks.xml' at app/etc/modules/ with following code in it.

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

Step 2) Create module's config.xml file at app/code/local/Prasan/CustomerNavigationLinks/etc/ with the following code in it

<?xml version="1.0"?>
<config>
<modules>
<Prasan_CustomerNavigationLinks>
<version>0.0.1</version>
</Prasan_CustomerNavigationLinks>
</modules>
<frontend>
<layout>
<updates>
<customernavigationlinks>
  <file>prasan_customernavigationlinks.xml</file>
</customernavigationlinks>
</updates>
</layout>
</frontend>
<global>
<blocks>
<customer>
<rewrite>
<account_navigation>Prasan_CustomerNavigationLinks_Block_Account_Navigation</account_navigation>
</rewrite>
</customer>
</blocks>
</global>
</config>

Step 3) Now create module's block file 'Navigation.php' at app/code/local/Prasan/CustomerNavigationLinks/Block/Account/ with the following code in it

<?php
class Prasan_CustomerNavigationLinks_Block_Account_Navigation extends Mage_Customer_Block_Account_Navigation
{
/**
* Description : Unset the Link by name in the customer Navigation
* @author Author Name
* @param Name of the link to be removed
* @return link is removed.
*/
public function removeLinkByName($name)
{
unset($this->_links[$name]);
return $this;
}
}

Step 4) Now create prasan_customernavigationlinks.xml file at app/design/frontend/base/default/layout/ with the following content in it

<?xml version="1.0"?>
<layout>
<!-- Removes Customer Navigation Links from My Account -->
<customer_account>
<reference name="customer_account_navigation">
<action method="removeLinkByName">
<name>account</name> <!-- Removes Account Dashboard Link -->
</action>
<action method="removeLinkByName">
<name>account_edit</name> <!-- Removes Account Information Link -->
</action>
<action method="removeLinkByName">
<name>address_book</name> <!-- Removes Address Book Link -->
</action>
<action method="removeLinkByName">
<name>orders</name> <!-- Removes My Orders Link -->
</action>
<action method="removeLinkByName">
<name>billing_agreements</name> <!-- Removes Billing Aggrements Link -->
</action>
<action method="removeLinkByName">
<name>recurring_profiles</name> <!-- Removes Recurring Profiles Link -->
</action>
<action method="removeLinkByName">
<name>reviews</name> <!-- Removes My Product Reivews Link -->
</action>
<action method="removeLinkByName">
<name>tags</name> <!-- Removes My Tags Link -->
</action>
<action method="removeLinkByName">
<name>wishlist</name> <!-- Removes My Wishlist Link -->
</action>
<action method="removeLinkByName">
<name>OAuth Customer Tokens</name> <!-- Removes My Applications Link -->
</action>
<action method="removeLinkByName">
<name>newsletter</name> <!-- Removes Newsletter Subscriptions Link -->
</action>
<action method="removeLinkByName">
<name>downloadable_products</name> <!-- Removes My Downloadable Products Link -->
</action>
</reference>
</customer_account>
</layout>

Note: Add only that links which you want to remove from the customer account navigation links and then clear cache.link will be removed

No comments:

Post a Comment