Magento Forum

How do I override customer layout in my custom module? 
 
cooldar
Sr. Member
 
Total Posts:  95
Joined:  2008-05-14
 

I am trying to override the costumer_account layout in customer.xml using another layout in my own module so that it doesn’t get overwritten every time I do a major upgrade in magento connect.

In my own module’s mymodule.xml layout file, I added

<customer_account>
        <!-- 
Mage_Customer -->
        <
reference name="root">
            <
action method="setTemplate"><template>page/2columns-left.phtml</template></action>
        </
reference>

        <
reference name="left">
            <
block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
                <
action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
                <
action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
                <
action method="addLink" translate="label" module="customer"><name>new_link</name><path>mymodule/action/</path><label>New Link</label></action>
                <
action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
            </
block>
            <
block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml">
                <
action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/sidebar/default.phtml</template></action>
                <
action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/sidebar/default.phtml</template></action>
                <
action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/sidebar/default.phtml</template></action>
            </
block>
            <
block type="core/template" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>
            <
block type="sales/reorder_sidebar" name="sale.reorder.sidebar" as="reorder" template="sales/reorder/sidebar.phtml"/>
            <
remove name="tags_popular"/>
            
        </
reference>
    </
customer_account>

The only change is that I added a new link to the My account’s navigation.

<action method="addLink" translate="label" module="customer"><name>new_link</name><path>mymodule/action/</path><label>New Link</label></action>

But the layout is causing problem when I enter My account page, where I get the following error

Warning: SimpleXMLElement::addAttribute() [function.SimpleXMLElement-addAttribute]: Attribute already exists in /home/rchengpc/magento/app/code/core/Mage/Core/Model/Layout.php on line 159

I know the problem is because there are now two customer_account layout, one in customer.xml and one in mymodule.xml. If I remove either one, the problem would go away, but I want to override the one in customer.xml.

How do I do that? What am I doing wrong? I am following the instruction in the Php Arch’s Magento book.
Please Help!!!  shock

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

I believe if you are overriding the xml files, you need to name it the same as the layout xml files you are attempting to overwrite (and use the same folder structure)

(I might not be understanding exactly what you are attempting)

My solutions is basically:

1) Copy customer.xml and make your changes to it (keep it in the layout folder in your own theme folder) <-- easiest!!!

2) Might have to tell magento that you are overriding a certain block via the modules config.php file?? (I know you do this to override classes, not sure about blocks themselves)

 
Magento Community Magento Community
Magento Community
Magento Community
 
cooldar
Sr. Member
 
Total Posts:  95
Joined:  2008-05-14
 

Hi Nike,

Thanks for replying. From the PHP Arch Magento book, the author was able to override “customer_account_index” in rewardpoints.xml. If what you are saying is correct, shouldn’t the author have created another customer.xml in his rewardpoint module and override customer_account_index in it? But apparently the author did not do so.

 
Magento Community Magento Community
Magento Community
Magento Community
 
cooldar
Sr. Member
 
Total Posts:  95
Joined:  2008-05-14
 

as for number 2
I do have

<layout>
                  <
updates>
                          <
mymodule>
                              <
file>mymodule.xml</file>
                          </
mymodule>
                  </
updates>        
        </
layout>

Not sure if there’s more I need to add?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

Is this the points and rewards module?

if it is, it doesn’t look like it’s overwriting, but adding to?

 
Magento Community Magento Community
Magento Community
Magento Community
 
cooldar
Sr. Member
 
Total Posts:  95
Joined:  2008-05-14
 

I am writing a different module that does something similar but different from the point and reward module. I am using the point and reward module from the magento book to see how it overrides the layout. I tried the same thing but get the error I mention in the original post.

I do think the book is trying to override, not add, the action in the layout. In the new action, the author added a new block, but the newly modified action in the new module’s layout overrides the original customer action in the customer.xml layout.

this is so frustrating.... shut eye

 
Magento Community Magento Community
Magento Community
Magento Community
 
cooldar
Sr. Member
 
Total Posts:  95
Joined:  2008-05-14
 

ok, I’ve found the problem to be this line

<remove name="tags_popular"/>

anyone have any idea why?

 
Magento Community Magento Community
Magento Community
Magento Community
 
dkoo761
Jr. Member
 
Total Posts:  8
Joined:  2008-10-10
 

Here’s what I think caused it…

You probably had that same “remove” line included in some other layout file. After Magento removed it once and then came across the same remove element/command again, it didn’t know how to deal with it since there was nothing left to remove so it blew up. I had a similar problem and once I removed the duplicate remove statement, all was well again.

Cheers,
Dave

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top