Magento – Magento remove tabs like invoices,credit memos,shipment in admin sales order view using observer

adminevent-observermagento-1.9sales-ordertabs

I want to remove tabs(invoice,credit memo,shipment) in sales order view using observer
My config.xml file

    <adminhtml_widget_container_html_before>
                        <observers>
                            <package_test_adminhtml_widget_container_html_before>
                                <class>test/observer</class>
                                <method>adminhtmlWidgetContainerHtmlBefore</method>
                            </package_test_adminhtml_widget_container_html_before>
                        </observers>
    </adminhtml_widget_container_html_before>

My observer.php

public function adminhtmlWidgetContainerHtmlBefore($event) 
    {
        $block = $event->getBlock();
        if ($block instanceof Mage_Adminhtml_Block_Widget_Tabs) {
            $block->removeTab('order_tab_info'); // I am trying information tab from sales order view but it doesn't work          
        }
    }

Best Answer

Try this:

In config.xml use core_block_abstract_to_html_before instead adminhtml_widget_container_html_before

<events>
    <core_block_abstract_to_html_before>
        <observers>
            <package_test_adminhtml_widget_container_html_before>
                <class>test/observer</class>
                <method>adminhtmlWidgetContainerHtmlBefore</method>
            </package_test_adminhtml_widget_container_html_before>
        </observers>
    </core_block_abstract_to_html_before>
</events>

and replace your observer adminhtmlWidgetContainerHtmlBefore() with:

public function adminhtmlWidgetContainerHtmlBefore($event) {
    $block = $event->getBlock();
    if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View_Tabs) {
        $block->removeTab('order_transactions');   // Remove tab by id
        $block->removeTab('order_history');        // Remove tab by id
    }
}

Note: Please don't try to remove sales order view current active tab, it will thrown below error:

PHP Fatal error: Call to a member function getId() on a non-object in /var/www/html/magento/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php on line 236, referer: http://127.0.0.1/magento/index.php/admin/sales_order/index/key/47b8c63b239bfb55d90a12088f642fed/
Related Topic