Magento 1.9 – How to Add Custom Template in Admin Order

adminhtmlmagento-1.9template

I am currently creating a button for a single order in Magento(next to invoice, ship, reorder etc.). I would like the button to be inside a template to allow for php variables from that order and external js files to be added.

I am currently trying to override the sales order view page and add code from their, this seems to be the best/simplest way. It's reading the new template, but everything else is getting messed up. How do i fix this?

app\code\local\MyApp\OrderButton\etc\config.xml

<config>
<modules>
    <MyApp_OrderButton>
        <version>0.0.1</version>
    </MyApp_OrderButton>
</modules>
<global>
    <models>
        <myapp_orderbutton>
            <class>MyApp_OrderButton_Model</class>
        </myapp_orderbutton>
    </models>
    <blocks>
        <adminhtml>
            <rewrite>
                <sales_order_view_info>ShipRush_OrderButton_Block_Sales_Order_View_Info</sales_order_view_info>
            </rewrite>
        </adminhtml>
    </blocks>
</global>
</config>

app\code\local\MyApp\OrderButton\Block\Sales\Order\View\info.php:

class MyApp_OrderButton_Block_Sales_Order_View_Info extends Mage_Adminhtml_Block_Sales_Order_View_Info
{
    protected function _construct()
    {
       $this->setTemplate('myapp/sales/order/view/myinfo.phtml');
    }
}

Potential template, php, and js:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
function connect() {
    var allsongs = '<?php echo $x ?>';
    lib = {
        songs: allsongs,
        albums: 20
    };
    alert(lib);
}
</script>

This is read by magento, but it messes up the whole page:
enter image description here

Best Answer

I believe your first question is you are not able to override info.phtml file. If that's the case then

Change your layout this way:

<?xml version="1.0"?>
<layout>
    <adminhtml_sales_order_view>
        <reference name="order_tab_info">
            <action method="setTemplate">
                <template>myapp/sales/order/view/info.phtml</template>
            </action>
        </reference>
    </adminhtml_sales_order_view>
</layout>

IMP

Remember if you using layout file to override template then you don't need to rewrite block in config.xml, unless you are also overriding some function or adding new function to it.

       <adminhtml>
            <rewrite>
                <sales_order_view_info>MyApp_OrderButton_Block_Sales_Order_View_Info</sales_order_view_info>
            </rewrite>
        </adminhtml>

Magento layout setTemplate is so powerful that it will handle the work for you.