2

I want to add custom tab to sales order view form. I tried the following code, but nothing happend. (Link 1, Link 2).

My layout module.xml code is

 <adminhtml_sales_order_view>
        <reference name="sales_order_tabs">
            <action method="addTab"><name>my_tab</name><block>mymodule/Adminhtml_Sales_Order_View_Tabs</block></action>
        </reference>
</adminhtml_sales_order_view>

And my block class is :

class Mymodule_Block_Adminhtml_Sales_Order_View_Tabs  extends Mage_Adminhtml_Block_Sales_Order_Abstract
    implements Mage_Adminhtml_Block_Widget_Tab_Interface
{

    protected function _construct()
    {
        Mage::Log("Fraud created");
    }

    /**
     * Retrieve order model instance
     *
     * @return Mage_Sales_Model_Order
     */
    public function getOrder()
    {
        return Mage::registry('current_order');
    }

    /**
     * Retrieve source model instance
     *
     * @return Mage_Sales_Model_Order
     */
    public function getSource()
    {
        return $this->getOrder();
    }


    public function getTabLabel()
    {
        return Mage::helper('sales')->__('Fraud Detection');
    }

    public function getTabTitle()
    {
        return Mage::helper('sales')->__('Fraud Detection');
    }

    public function canShowTab()
    {
        return true;
    }

    public function isHidden()
    {
        return false;
    }
}

Any error in the above code ? thanks in advance

  • so how to add form in newly created tab? if someone can provide code that will be great. because I am confuse with form creation with controller.php or block.php or xml..... I ll really appreciate your help.. thanks – sohaib Apr 5 '16 at 2:29
3

Try

Create: app/code/local/MagePal/OrderFraudDetectionTab/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MagePal_OrderFraudDetectionTab>
            <version>1.0.1</version>
        </MagePal_OrderFraudDetectionTab>
    </modules>
    <global>
        <blocks>
            <orderfrauddetectiontab>
                <class>MagePal_OrderFraudDetectionTab_Block</class>
            </orderfrauddetectiontab>
        </blocks>
    </global>       
    <adminhtml>
       <layout>
            <updates>
                <orderfrauddetectiontab>
                    <file>magpal_orderfrauddetectiontab.xml</file>
                </orderfrauddetectiontab>
            </updates>
        </layout>
    </adminhtml>
</config>

Create: app/code/local/MagePal/OrderFraudDetectionTab/Block/Adminhtml/Order/View/Tab/FraudDetection.php

<?php
class MagePal_OrderFraudDetectionTab_Block_Adminhtml_Order_View_Tab_FraudDetection
    extends Mage_Adminhtml_Block_Template
    implements Mage_Adminhtml_Block_Widget_Tab_Interface
{    
    //change _constuct to _construct()
    public function _construct()
    {
        parent::_construct();
        $this->setTemplate('magpal/orderfrauddetectiontab/order/view/tab/frauddetection.phtml');
    }

    public function getTabLabel() {
        return $this->__('Fraud Detection');
    }

    public function getTabTitle() {
        return $this->__('Fraud Detection');
    }

    public function canShowTab() {
        return true;
    }

    public function isHidden() {
        return false;
    }

    public function getOrder(){
        return Mage::registry('current_order');
    }
} 
?>

Create: app/design/adminhtml/default/default/template/magpal/orderfrauddetectiontab/order/view/tab/frauddetection.phtml

<?php echo 'add your html/php code here'; ?>

Create: app/design/adminhtml/default/default/layout/magpal_orderfrauddetectiontab.xml

<?xml version="1.0"?>
<layout>
    <adminhtml_sales_order_view>
        <reference name="sales_order_tabs">
            <action method="addTab">
                <name>order_view_tab_orderfrauddetectiontab</name>
                 <block>orderfrauddetectiontab/adminhtml_order_view_tab_frauddetection</block>
            </action>
        </reference>
</adminhtml_sales_order_view>
</layout>

Create: app/etc/modules/MagePal_OrderFraudDetectionTab.xml

<?xml version="1.0"?>
<config>
     <modules>
        <MagePal_OrderFraudDetectionTab>
            <active>true</active>
            <codePool>local</codePool>
        </MagePal_OrderFraudDetectionTab>
    </modules>
</config>
| improve this answer | |
  • Thanks for your response.what would be the way if i want to load grid not phtml in costructor ? – MKK Jun 20 '13 at 4:49
  • The way i normal do this is to add `echo $this->getLayout()->createBlock('orderfrauddetectiontab/adminhtml_frauddetection_edit_tab_form')->toHtml();' to my phtml – Renon Stewart Jun 20 '13 at 12:57
  • typo in class MagePal_OrderFraudDetectionTab_Block_Adminhtml_Order_View_Tab_FraudDetection constructor, __construct and scope should be public. code public function __construct() { – Pradeep Sanjaya Aug 21 '14 at 4:12
  • This solution is not working for me. No new tab is showing in Sales >> Order section – Narayan Dec 31 '18 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.