1

I Create a new custom module. My requirement is to add new link after Address Book in Customer My Account. when click on that new link a new page show on right as address book.

What I do I'll Explain here, Please let me know what is going wrong.. No Link is shown after doing all..

Step 1. Create new file in app/etc/modules named Customerserviceaddress_Serviceaddresses.xml Having below code :

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

Step 2. app/code/local/Customerserviceaddress/Serviceaddresses/etc create new file named config.xml with below code :

<?xml version="1.0"?>
<config>
    <modules>
        <Customerserviceaddress_Serviceaddresses>
            <version>0.1.0</version>    <!-- Version number of your module -->
        </Customerserviceaddress_Serviceaddresses>
    </modules>
    <frontend>
        <routers>
            <serviceaddresses>
                <use>standard</use>
                <args>
                    <module>Customerserviceaddress_Serviceaddresses</module>
                    <frontName>serviceaddresses</frontName>
                </args>
            </serviceaddresses>
        </routers>
    </frontend>
</config>

Step 3.

Create Controller File app/code/local/Customerserviceaddress/Serviceaddress/controllers named IndexController.php

<?php
class Customerserviceaddress_Serviceaddresses_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        echo "Hello tuts World";
    }
    public function testAction()
    {
        echo "test action";
    }
}

?>

After all this I type yoursite.com/index.php/serviceaddresses/index/index in url to check is my module working or not.. It is working...
. . After this Creating Custom Module's Layout and Block Files :
Step 4. app > code > local > Customerserviceaddress > serviceaddresses > etc > config.xml and add the below line of code:

<frontend>
<layout>
        <updates>
            <serviceaddresses>
                <file>serviceaddresses.xml</file> <!-- Our layout file name-->
            </serviceaddresses>
        </updates>
</layout>
</frontend>
<global>
        <blocks>
            <serviceaddresses>
                <class>Customerserviceaddress_Serviceaddresses_Block</class>
            </serviceaddresses>
        </blocks>
</global>

So the updated config.xml is look like this :

<?xml version="1.0"?>
<config>
    <modules>
        <Customerserviceaddress_Serviceaddresses>
            <version>0.1.0</version>    <!-- Version of module -->
        </Customerserviceaddress_Serviceaddresses>
    </modules>
    <frontend>
        <routers>
            <serviceaddresses>
                <use>standard</use>
                <args>
                    <module>Customerserviceaddress_Serviceaddresses</module>
                    <frontName>serviceaddresses</frontName>
                </args>
            </serviceaddresses>
        </routers>
         <layout>
            <updates>
                <serviceaddresses>
                    <file>serviceaddresses.xml</file> <!-- Our layout file name-->
                </serviceaddresses>
            </updates>
         </layout>
    </frontend>
    <global>
        <blocks>
            <serviceaddresses>
                <class>Customerserviceaddress_Serviceaddresses_Block</class>
            </serviceaddresses>
        </blocks>
    </global>
</config>


Step 5.
app > code > local > Customerserviceaddresses > Serviceaddresses > Block and create the file Serviceaddresses.php that contains below lines of code :

<?php
class Customerserviceaddresses_Serviceaddresses_Block_Serviceaddresses extends Mage_Core_Block_Template
{
    public function myfunction()
    {
        return "Hello new world";
    }
}
?>

Step 6.

app > design > frontend > rwd > default > layout and create the serviceaddresses.xml file which contains below lines of code :

<?xml version="1.0"?>
<layout version="0.1.0">
    <serviceaddresses_index_index>
        <reference name="content">
            <block type="serviceaddresses/serviceaddresses" name="serviceaddresses" template="serviceaddresses/serviceaddresses.phtml" />
        </reference>
    </serviceaddresses_index_index>
</layout>

Step 7.

app > design > frontend > rwd > default > template > serviceaddresses and create the serviceaddresses.phtml file.

<?php
    echo $this->myfunction();
?>


After doing template, layout and block files nothing change.. What can I do to see the changes, that why My function in block is not call.. How can see the new output on screen.


Now The Code/Files I add to create New Link in Customer My Account Navigation

Step 8. Code added in my module's app/code/local/Customerserviceaddress/Serviceaddresses/etc/config.xml

<layout version="0.1.0">
    <customer_account>
        <reference name="customer_account_navigation">
            <action method="addLink">
                <name>customer_service_address</name>
                <path>serviceaddresses/controller</path>
                <label>Service Addresses</label>
            </action>
        </reference>
    </customer_account>
</layout>


Updated Config.xml will look like this :

<?xml version="1.0"?>
<config>
    <modules>
        <Customerserviceaddress_Serviceaddresses>
            <version>0.1.0</version>    <!-- Version number of your module -->
        </Customerserviceaddress_Serviceaddresses>
    </modules>
    <frontend>
        <routers>
            <serviceaddresses>
                <use>standard</use>
                <args>
                    <module>Customerserviceaddress_Serviceaddresses</module>
                    <frontName>serviceaddresses</frontName>
                </args>
            </serviceaddresses>
        </routers>
     <layout>
            <updates>
                <serviceaddresses>
                    <file>serviceaddresses.xml</file> <!-- Our layout file name-->
                </serviceaddresses>
            </updates>
         </layout>
    </frontend>
    <global>
        <blocks>
            <serviceaddresses>
                <class>Customerserviceaddress_Serviceaddresses_Block</class>
            </serviceaddresses>
        </blocks>
    </global>
</config>

<!--New Section for My Account New Link -->
<layout version="0.1.0">
    <customer_account>
        <reference name="customer_account_navigation">
            <action method="addLink">
                <name>customer_service_address</name>
                <path>serviceaddresses/controller</path>
                <label>Service Addresses</label>
            </action>
        </reference>
    </customer_account>
</layout>


Step 9. Create New file in my custom module's controllers folder named ControllerController.php having below code :

<?php
class Customerserviceaddress_Serviceaddresses_ControllerController extends Mage_Core_Controller_Front_Action
{   
    public function indexAction()
    {
        if (!Mage::getSingleton('customer/session')->isLoggedIn()):
            $this->_redirect('customer/account/login');
            return;
        endif;

        $this->loadLayout();
        $this->renderLayout();
    }
}
?>


Step 10. create new file in app/design/frontend/rwd/default/layout folder named serviceaddresses.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <serviceaddresses_index_index>
        <reference name="content">
            <block type="serviceaddresses/serviceaddresses" name="serviceaddresses" template="serviceaddresses/serviceaddresses.phtml" />
        </reference>
    </serviceaddresses_index_index>

 <serviceaddresses_controller_index> <!-- module here matches node directly beneath <routers> in config.xml -->
       <update handle="customer_account"/> <!-- include existing customer account layout -->
       <reference name="my.account.wrapper"> <!-- target parent block -->
           <block type="serviceaddresses/customaddress" name="customer_service_address" template="serviceaddresses/serviceaddresses.phtml"/>
           <block type="customer/account_dashboard" name="customer.account.link.back" template="customer/account/link/back.phtml" /> <!-- add a back link -->
       </reference>
   </serviceaddresses_controller_index>

</layout>

Step 10. Create New Controller file Named in controllers folder of my custom module Customaddress.php having below code :

<?php

class Customerserviceaddress_Serviceaddresses_Block_Customaddress extends Mage_Core_Block_Template
{
    public function getCustomer()
    {
        $customer = Mage::getSingleton('customer/session')->getCustomer();
        if ($customer->getId()):
            return $customer;
        endif;

        return false;
    }
}
?>

Step 11. Old template file of my custom module's template folder. file named : serviceaddresses.phtml

<?php
    //echo $this->myfunction();
?>
<div class="page-title">
    <h1><?php echo $this->__('Service Addresses') ?></h1>
</div>
<?php if ($customer = $this->getCustomer()): ?>
    <div>Hello <?php echo $customer->getName(); ?></div>
<?php else: ?>
    <div>No customer here</div>
<?php endif; ?>


After doing all this no new link shown in customer my account navigation. Let me know what was wrong in this flow.

1

The following XML block should be in your extension's app/design/frontend/rwd/default/layout/serviceaddresses.xml file, not app/code/local/Customerserviceaddress/Serviceaddresses/etc/config.xml.

<layout version="0.1.0">
    <customer_account>
        <reference name="customer_account_navigation">
            <action method="addLink">
                <name>customer_service_address</name>
                <path>serviceaddresses/controller</path>
                <label>Service Addresses</label>
            </action>
        </reference>
    </customer_account>
</layout>

Your serviceaddresses.xml file should look something like this:

<?xml version="1.0"?>
<layout version="0.1.0">
    <serviceaddresses_index_index>
        <reference name="content">
            <block type="serviceaddresses/serviceaddresses" name="serviceaddresses" template="serviceaddresses/serviceaddresses.phtml" />
        </reference>
    </serviceaddresses_index_index>
    <customer_account>
        <reference name="customer_account_navigation">
            <action method="addLink">
                <name>customer_service_address</name>
                <path>serviceaddresses/controller</path>
                <label>Service Addresses</label>
            </action>
        </reference>
    </customer_account>
</layout>

P.S. I recommend creating a child theme of RWD instead of modifying it directly.

  • Yes this is working for me.. Can you please let me know what is unnecessary code or files .. that not affect my account new link... so I can remove that. Thanks. – Yogita Sep 28 '16 at 13:17
  • Everything looks good to me, my only recommendation is to move everything in ControllerController to IndexController. – Joseph Leedy Sep 28 '16 at 13:50

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.