Magento admin How to add button in sales invoice view page?

by Mandal   Last Updated January 12, 2018 08:09 AM

enter image description here

app\etc\modules\button_module.xml

<config>
    <modules>
        <button_module>
            <active>true</active>
            <codePool>core</codePool>

        </button_module>
    </modules>
</config>

app/code/local/Button/Module/etc/config.xml

<adminhtml>
    <events>
        <adminhtml_widget_container_html_before>
            <observers>
                <button_module>
                    <class>button_module/observer</class>
                    <method>adminhtmlWidgetContainerHtmlBefore</method>
                </button_module>
            </observers>
        </adminhtml_widget_container_html_before>
    </events>
</adminhtml>

app/code/local/Button/Module/controllers/Adminhtml/Sales/InvoiceController.php

<?php
require_once Mage::getModuleDir('controllers', 'Mage_Adminhtml') . DS . 'Sales' . DS . 'InvoiceController.php';
class Your_Module_Adminhtml_Sales_InvoiceController extends Mage_Adminhtml_Sales_InvoiceController
{  
    public function viewinvoicespageAction() {
        $invoiceIds = $this->getRequest()->getParam('invoice_ids');
    }
}
?>

app/code/local/Button/Module/Model/Observer.php

<?php
class Button_Module_Model_Observer
{
    public function adminhtmlWidgetContainerHtmlBefore($event)
    {  
        $paramsarray = Mage::app()->getRequest()->getParams('invoice_id');
        $invoicesid = $paramsarray["invoice_id"];
        $block = $event->getBlock();
        if ($block instanceof Mage_Adminhtml_Block_Sales_Order_Invoice_View) {
            $block->addButton('do_something_crazy', array(
                'label'     => Mage::helper('module')->__('Button'),
                'onclick'   => "setLocation('{$block->getUrl('*/sales_invoice/viewinvoicespage/invoice_ids/'.$invoicesid)}')",
                'class'     => 'go'
            ));          
        }
    }
}
?>


Related Questions