1

I want to add a custom field to the order info page in the admin section. Based on all the tutorials I read this should be a simple task. However I found out that my custom template gets overwritten by the default one.

Here is my config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <MyCompany_MyModule>
            <version>0.1.1</version>    <!-- Version number of your module -->
        </MyCompany_MyModule>
    </modules>
    <global>
        <models>
            <mymodule>
                <class>MyCompany_MyModule_Model</class>
            </mymodule>
        </models>
        <helpers>
            <mymodule>
                <class>MyCompany_MyModule_Helper</class>
            </mymodule>
        </helpers>
        <resources>
            <mymodule_attributes_setup>
                <setup>
                    <module>MyCompany_MyModule</module>
                    <class>Mage_Eav_Model_Entity_Setup</class>
                </setup>
            </mymodule_attributes_setup>
        </resources>
        <blocks>
            <mymodule>
                <class>MyCompany_MyModule_Block</class>
            </mymodule>
            <adminhtml>
                <rewrite>
                    <sales_order_view_info>MyCompany_MyModule_Block_Sales_Order_View_Info</sales_order_view_info>
                </rewrite>
            </adminhtml>
        </blocks>
     </global>
    <frontend>
        <routers>
            <mymodule>
                <use>standard</use>
                <args>
                    <module>MyCompany_MyModule</module>
                    <frontName>mymodule</frontName>
                </args>
            </mymodule>
        </routers>
    </frontend>
    <adminhtml>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <mymodule_options>
                                            <title>MyModule Options</title>
                                        </mymodule_options>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
        <layout>
            <updates>
                <mymodule>
                    <file>mymodule.xml</file>
                </mymodule>
            </updates>
        </layout>
    </adminhtml>
</config>

In the config.xml, I defined my module's Block to rewrite the Mage_AdminHtml_Block_Sales_Order_View_Info.

Here is my MyCompany_MyModule.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <MyCompany_MyModule>
            <active>true</active>
            <codePool>community</codePool>
        </MyCompany_MyModule>
    </modules>
</config>

Here is my custom block file: ../mycompany/mymodule/Block/Sales/Order/View/Info.php

<?php

class MyCompany_MyModule_Block_Sales_Order_View_Info extends Mage_Adminhtml_Block_Sales_Order_View_Info
{
    public function _construct()
    {
        $this->setTemplate('mymodule/sales/order/view/info.phtml');
    }
}

In my Block file I override the parent's template.

Here is my layout file mymodule.xml:

<?xml version="1.0"?>
<layout>
    <adminhtml_sales_order_view>
        <reference name="order_info">
            <action method="setTemplate">
                <template>mymodule/sales/order/view/info.phtml</template>
            </action>
            <block type="mymodule/sales_order_view_info" name="mymodule_sales_order_view_info" template="mymodule/sales/order/view/info.phtml"/>
        </reference>
    </adminhtml_sales_order_view>
</layout>

In my template file info.phtml, simply print out <p>Hello</p>

My template file symlinks to magento/app/design/adminhtml/default/default/template/mymodule/sales/order/view/info.phtml My layout file symlinks to magento/app/design/adminhtml/default/default/layout/mymodule.xml

I have turned on Allow Symlink in the system configuration.

Now that's should be everything I need to do based on all the posts and tutorials I read. However my custom module doesn't show.

I checked Exception log, nothing in there. So I logged out the templates name in class Mage_Core_Block_Template located at magento/app/code/core/Mage/Core/Block/Template.php:

/**
 * Set path to template used for generating block's output.
 *
 * @param string $template
 * @return Mage_Core_Block_Template
 */
public function setTemplate($template)
{
    Mage::log("template: $template");
    $this->_template = $template;
    return $this;
}

Now in the system.log, I see the following:

2015-05-07T23:56:16+00:00 DEBUG (7): template: mymodule/sales/order/view/info.phtml
2015-05-07T23:56:16+00:00 DEBUG (7): template: sales/order/view/info.phtml

So my custom Block gets called, but right after it loads my custom template, it gets overwritten by the default one.

What am I doing wrong here? Btw I'm using Magento CE 1.9

1 Answer 1

0

The tag should be used if you create a module that impacts an other one. and your declaration file (app/etc/modules/Namespace_Module.xml) this:

<?xml version="1.0"?>
<config>
    <modules>
        <MyCompany_MyModule>
            <active>true</active>
            <codePool>community</codePool>
            <depends>
                <Mage_Sales />
            </depends>
        </MyCompany_MyModule>
    </modules>
</config>

so finally your xml will look like

EDIT

to use adminhtml custom theme

if you are using like this in frontend design\frontend\default\yourtheme

then in admin you can also use design\adminhtml\default\yourtheme

you it should work like your custom in admin area please don't put in base else when you going to upgrade your magento version it may create issue.

i hope it will work for you.

5
  • Hey I tried this, but same result. Is there any other Mage modules that should be added into the depends section in order to overwrite Sales_Order_View_Info block? May 10, 2015 at 7:49
  • @BboyJeans, it's enough to give Mage_sales. You should have to debug in detail though.:(
    – liyakat
    May 10, 2015 at 12:46
  • Hey I finally figured it out. I needed to put my layout in magento/app/design/adminhtml/base/default/layout/mymodule.xml, and put my template in magento/app/design/adminhtml/base/default/template/mymodule/sales/order/view/info.phtml I found this by directly changing the default layout file and log the info out. Then I saw it tries to load my template from that directory. Wried thing is I don't have app/design/adminhtml/base directory, I only have app/design/adminhtml/default directory, I ended up creating it by myself. May 11, 2015 at 2:59
  • @BboyJeans, use my updated answer.if its useful to you pls dont forget to acpt it
    – liyakat
    May 11, 2015 at 4:56
  • Thanks for the reminder. I think this time I finally got it solved, I adde the following in my config.xml: <admin> <routers> <adminhtml> <args> <modules> <mymodule after="Mage_Adminhtml">MyModule_FruugoApi</mymodule> </modules> </args> </adminhtml> </routers> </admin> And put my stuff back in .../default/default, it's working now. Also I noticed that symlinks to the layout file isn't working, I had to copy the file to that directory, very odd. May 12, 2015 at 4:11

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.