How to overwrite sales view order phtml file in magento

If you need to customize sales view order or customize your view order phtml page for admin , then you need to overwrite this phtml file. You don’t should customize the core phtml file. You should customize your own file. So lets start.
Suppose namespace is “Exercise” and module name is “CustomSales”

Step 1 : Create a module config file into app/etc/modules/Exercise_CustomSales.xml

<config>
    <modules>
        <Exercise_CustomSales>
            <active>true</active>
            <codePool>local</codePool>
        </Exercise_CustomSales>
    </modules>
</config>

Step 2: Create a config file under app/code/local/Exercise/CustomSales/etc/config.xml

<config>
    <modules>
        <Exercise_CustomSales>
            <version>1.7.0.2</version>
        </Exercise_CustomSales>
    </modules>
    <adminhtml>
        <layout>
            <updates>
                <customsales>
                    <file>exercise_customsales.xml</file>
                </customsales>
            </updates>
        </layout>
    </adminhtml>
    <global>
        <blocks>
            <customsales>
                <class>Exercise_CustomSales_Block</class>
            </customsales>
            <adminhtml>
                <rewrite>
                    <sales_order_view_info>Exercise_CustomSales_Block_Sales_Order_View_Info</sales_order_view_info>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

Step 3 : Create a php file which is overwrite the actual order info file, app/code/local/Exercise/CustomSales/Block/Sales/Order/View/Info.php

class Exercise_CustomSales_Block_Sales_Order_View_Info extends Mage_Adminhtml_Block_Sales_Order_View_Info
{
}

Step 4 : you should create a xml file inside layout folder(Possible path: app/design/adminhtml/default/default/layout).

For example : exercise_customsales.xml

Your code should be:

<layout version="0.1.0">
    <adminhtml_sales_order_view>
        <reference name="order_info">
            <action method="setTemplate"><template>customsales/sales/order/view/info.phtml</template></action>
        </reference>
    </adminhtml_sales_order_view>
</layout>

Step 5 : Then you need to create a file inside template folder (Possible path: app/design/adminhtml/default/default/template), customsales/sales/order/view/info.phtml.

copy all content from sales/order/view/info.phtml into customsales/sales/order/view/info.phtml, and you can change here and related block file is now app/code/local/Exercise/CustomSales/Block/Sales/Order/View/Info.php

Change those file as you required.

Step 6: Clear the cache

Enjoy!

13 thoughts on “How to overwrite sales view order phtml file in magento

  1. some syntax highlighting and code formating would be a great “update” for this article. But still a nice article! Thanks

  2. Hello Sohel,
    It works well.
    But can you tell me how to add it on top of all the blocks like, I wanna add my custom block above the billing and shipping address blocks.

    1. You can place a custom block any where in side ‘info.phtml’. add a block something like
      <block type=”customsales/sales_order_view_custom” name=”customsales_sales_order_view_custom” template=”customsales/sales/order/view/custom.phtml”/>
      and call this block inside phtml -> echo $this->getChildHtml(‘customsales_sales_order_view_custom’);

      here is an example -> https://sohelrana09.wordpress.com/2014/03/05/how-to-add-custom-block-after-items-block-into-order-view-page-in-magento/

  3. I want to override sales order grid and filter by order id, I want display only few order ids not all, How can I do this ?

  4. Hi there,

    i followed the above mentioned steps, after applying all, i am getting en error now, here it is:

    class Kulvinder_Singh_Block_Sales_Order_View_Info extends Mage_Adminhtml_Block_Sales_Order_View_Info { }
    Fatal error: Class ‘Kulvinder_Singh_Block_Sales_Order_View_Info’ not found in /home/xxx/public_html/mytest.space/sartajmage19-2/app/code/core/Mage/Core/Model/Layout.php on line 491

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s