Search code examples
magentomagento-1.9

How to add a tab on (adminhtml) order->view (Magento CE 1.9.1)


I need to add a new tab on (adminhtml) order->view on Magento CE 1.9.1. I've tried with some guides found on Google but nothing worked. Anybody can help me?


Solution

  • Here is the example module.

    file: app/code/local/Namespace/Newtab/Block/Adminhtml/Order/View/Tab/Contents.php

    <?php
    class Namespace_Newtab_Block_Adminhtml_Order_View_Tab_Contents
        extends Mage_Adminhtml_Block_Template
        implements Mage_Adminhtml_Block_Widget_Tab_Interface
    {    
        public function _construct()
        {
            parent::_construct();
            $this->setTemplate('namespace/newtab/order/view/tab/contents.phtml');
    
        }
    
        public function getTabLabel() {
            return $this->__('New Tab');
        }
    
        public function getTabTitle() {
            return $this->__('New Tab');
        }
    
        public function canShowTab() {
            return true;
        }
    
        public function isHidden() {
            return false;
        }
    
        public function getOrder(){
            return Mage::registry('current_order');
        }
    }
    

    file: app/code/local/Namespace/Newtab/etc/config.xml

    <?xml version="1.0"?>
    <config>
        <modules>
            <Namespace_Newtab>
                <version>1.0.1</version>
            </Namespace_Newtab>
        </modules>
        <global>
            <blocks>
                <namespace_newtab>
                    <class>Namespace_Newtab_Block</class>
                </namespace_newtab>
            </blocks>
        </global>       
        <adminhtml>
           <layout>
                <updates>
                    <namespace_newtab>
                        <file>namespace_newtab.xml</file>
                    </namespace_newtab>
                </updates>
            </layout>
        </adminhtml>
    </config>
    

    file: app/design/adminhtml/default/default/layout/namespace_newtab.xml

    <?xml version="1.0"?>
    <layout>
        <adminhtml_sales_order_view>
            <reference name="sales_order_tabs">
                <action method="addTab">
                    <name>namespace_newtab_order_view_tab</name>
                     <block>namespace_newtab/adminhtml_order_view_tab_contents</block>
                </action>
            </reference>
    </adminhtml_sales_order_view>
    </layout>  
    

    file: app/design/adminhtml/default/default/template/namespace/newtab/order/view/tab/contents.phtml

    <?php echo 'Hello World!';?>  
    

    file: app/etc/modules/Namespace_Newtab.xml

    <?xml version="1.0"?>
    <config>
         <modules>
            <Namespace_Newtab>
                <active>true</active>
                <codePool>local</codePool>
            </Namespace_Newtab>
        </modules>
    </config>