Your shopping cart is empty. Browse our Store

Magento

Open Source eCommerce Evolved

How to? Customize backend template (F.e. Sales order information)

Last modified by FetchDesigns on Sat, May 3, 2008 03:10
Source|Old Revisions  

This how to explains by a short example how developers can customize backend templates by overloading a block.

Scenario: We have collected additional data during the checkout process and saved them into the order. Now we want to display these datas within the order overview in backend.

The block displaying order data is located in app/code/core/Mage/Adminhtml/Sales/Order/View/Info.php. If we take a look at this class we see following code setting the template:

  1. protected function _construct()
  2. {
  3.    $this->setTemplate('sales/order/view/info.phtml');
  4. }

Easiest way to change template would be to change code of info.phtml. But we should protect our code from being overwritten by Magento updates. The solution? Overloading the block.

1st Step: We create our own extension

2nd Step We create our own block. For example: Mymodule/Block/Sales/Order/View/Info.php

  1. class Mage_Mymodule_Block_Sales_Order_View_Info extends Mage_Adminhtml_Block_Sales_Order_View_Info
  2. {
  3.     protected function _construct()
  4.     {
  5.         $this->setTemplate('mymodule/sales/order/view/info.phtml');
  6.     }     
  7. }

3rd Step We create our own .phtml file in design/adminhtml/default/default/template/mymodule/sales/order/view/info.phtml and customize it.

4th Step Overload Mage_Adminhtml_Block_Sales_Order_View_Info with own block out of own module. We add to config.xml within <default> node:

  1. <blocks>
  2.             <adminhtml>
  3.                 <rewrite>
  4.                     <sales_order_view_info>Mage_Mymodule_Block_Sales_Order_View_Info</sales_order_view_info>
  5.                 </rewrite>
  6.             </adminhtml>
  7.         </blocks>



 

Popular Wiki Tags  |  View all

Professional Services from the Magento Team

Professional Installation from the Magento Team

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs
© Copyright 2008 Varien. Magento is a trademark of Irubin Consulting Inc. DBA Varien