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