0

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'
            ));          
        }
    }
}
?>
  • Is there any specific error you are facing? Have you checked your log files? – Jaimin Sutariya Jan 12 '18 at 8:17
  • Custom button Not showing, I want to show a Custom Button and when click custom button then another email id send email without product price. How to fix? Please help... – Mandal Jan 12 '18 at 14:59
0

You should update your module filename to Button_Module.xml with capital letters. Then update the content of the file like below.

<?xml version="1.0"?>
<config>
    <modules>
        <Button_Module> <!-- Capital Letters -->
            <active>true</active>
            <codePool>local</codePool> <!-- Correct codepool from 'core' to 'local' -->
        </Button_Module>
    </modules>
</config>
  • Thanks for your reply.i have try but not showing custom button. – Mandal Jan 12 '18 at 15:11
0

I believe the most correct approach would be by calling \Mage_Adminhtml_Block_Widget_Container::addButton method on your invoice...

So you would need to Create a layout XML file for your module and add the button in your invoice view page, as follows:

<layout>
    <adminhtml_sales_order_invoice_view>
        <reference name="sales_invoice_view">
            <action method="addButton">
                <id>my_btn</id>
                <data>
                    <label>My button</label>
                    <onclick><![CDATA[
                    alert('hello world');
                    ]]></onclick>
                </data>
            </action>
        </reference>
    </adminhtml_sales_order_invoice_view>
</layout>

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.