Magento admin add button in sales invoice view page



Hi Friend's,

Display your custom button on invoice view page in admin side

Please open your config.xml file
Path : app/code/local/Your/Module/etc/
and add this code
Code :
<adminhtml>
    <events>
        <adminhtml_widget_container_html_before>
            <observers>
                <your_module>
                    <class>your_module/observer</class>
                    <method>adminhtmlWidgetContainerHtmlBefore</method>
                </your_module>
            </observers>
        </adminhtml_widget_container_html_before>
    </events>
</adminhtml>

And all show define models and helpers
<global>
    <models>
        <your_module>
            <class>Your_Module_Model</class>
        </your_module>
    </models>
    <helpers>
        <module>
            <class>Your_Module_Helper</class>
        </module>
    </helpers>
</global>

See in Example
<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Your_Module>
            <version>0.0.1</version>
        </Your_Module>
    </modules>
    <adminhtml>
        <events>
            <adminhtml_widget_container_html_before>
                <observers>
                    <your_module>
                        <class>your_module/observer</class>
                        <method>adminhtmlWidgetContainerHtmlBefore</method>
                    </your_module>
                </observers>
            </adminhtml_widget_container_html_before>
        </events>
    </adminhtml>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Your_Module after="Mage_Adminhtml">Your_Module_Adminhtml</Your_Module>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <global>
        <models>
            <your_module>
                <class>Your_Module_Model</class>
            </your_module>
        </models>
        <helpers>
            <paformat>
                <class>Your_Module_Helper</class>
            </paformat>
        </helpers>
    </global>
</config>

Now create Observer.php file in model folder
Path : app/code/local/Your/Module/Model/

And add this code
Code :

<?php
class Your_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'
            ));          
        }
    }
}
?>


Now rewrite invoice controller
Create InvoiceController.php
Path : app/code/local/Your/Module/controllers/Adminhtml/Sales/
And add this code

Code :
<?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');
        // Your code here
        //exit;
    }
}
?>

i hope this helps you :)

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Your post urges me to create a business website, of course I will free download magento as soon as possible. Magento is truly the best platform ever. Its extensions is also awesome. Thank you.

    ReplyDelete
  3. Do you know what is Magento 2. This is the new era of Magento E-commerce

    ReplyDelete
  4. Magento really need Magento banner slider extension because it is the best Magento extension

    ReplyDelete