1

As the title states, I need to add a link to the customer account navigation menu just for one store view of the website.

I tried doing it in this way, in the customer.xml file, with no luck:

<customer_account translate="label">
    <label>Customer My Account (All Pages)</label>
    ...
    <reference name="left">
        <block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
            <action method="addLink" ...
        </block>
    </reference>
    <STORE_english>
        <reference name="customer_account_navigation">
            <action method="addLink" translate="label">
                    <label>returns</label>
                    <path>returns</path>
                    <title>returns</title>
           </action>
        </reference>
    </STORE_english>

</customer_account>
  • Could you add a class to the link and then use CSS to show/hide for the relevant store? – gazjoy Mar 4 '16 at 17:55
2

Creating Custom Layout Handles

So ideally, we need a way to define a layout handle for customer nav link. Something like the following:

<CUSTOMER_NAV_LINK_STORE_english>
       <reference name="customer_account_navigation">
           <action method="addLink" translate="label" module="customer"><name>returns</name><path>returns</path><label>Returns</label></action>
       </reference>
</CUSTOMER_NAV_LINK_STORE_english>

So, we have to follow the steps below:

Step : 1 First, we will create app/etc/modules/AR_Customhandle.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <AR_Customhandle>
            <active>true</active>
            <codePool>local</codePool>
        </AR_Customhandle>
    </modules>
</config>

Step : 2 Now, we will create a config.xml file: app/code/local/AR/Customhandle/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <AR_Customhandle>
            <version>0.1.0</version>
        </AR_Customhandle>
    </modules>
     <frontend>
        <routers>
            <customhandle>
                <use>standard</use>
                <args>
                    <module>AR_Customhandle</module>
                    <frontName>customhandle</frontName>
                </args>
            </customhandle>
        </routers>
        <layout>
            <updates>
                <customhandle>
                    <file>customhandle.xml</file>
                </customhandle>
            </updates>
        </layout>
    </frontend>
    <global>
        <events>
            <controller_action_layout_load_before>
                <observers>
                    <customer_nav_link_handle>
                        <type>singleton</type>
                        <class>customhandle/observer</class>
                        <method>addCustomerNavLinkHandle</method>
                    </customer_nav_link_handle>
                </observers>
            </controller_action_layout_load_before>
        </events>
    </global>
</config>

Step : 3 Now, we will create a class: AR_Customhandle_Model_Observer and a method: addCustomerNavLinkHandle() in app/code/local/Magebse/Customhandle/Model/Observer.php

<?php
class AR_Customhandle_Model_Observer
{
    public function addCustomerNavLinkHandle(Varien_Event_Observer $observer)
    {
        $storeCode = Mage::app()->getStore()->getCode();
        $update = $observer->getEvent()->getLayout()->getUpdate();
        $update->addHandle('CUSTOMER_NAV_LINK_STORE_' . $storeCode);
    }
}

Step : 4 Now, we will create a layout file : app/design/frontend/{your_package}/{your_theme}/layout/customhandle.xml

<?xml version="1.0"?>
<layout version="0.1.0">
 <CUSTOMER_NAV_LINK_STORE_english>
       <reference name="customer_account_navigation">
           <action method="addLink" translate="label" module="customer"><name>returns</name><path>returns</path><label>Returns</label></action>
       </reference>
 </CUSTOMER_NAV_LINK_STORE_english>
</layout>
0

You have only two options to achieve this

  1. Create your own layout handler like Abdul explained in his answer
  2. Create a new layout theme for your store view and add the link there.

Background

Magento layout handles will be processed in a certain order. If you take a look at the handles on the customer_account_page you'll notice that the STORE_english [STORE_default] handle gets fired right after all the default handles have ran. Only then Magento processes the customer_account_index handle which loads the customer_account_navigation.

So your layout update with <STORE_english> can't work because the reference blocks do not exist.

Since we can't nest any layout updates we have to go with option #1 or #2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.