0

I am trying to add a simple generic button to the Sales Order View page using the adminhtml_widget_container_html_before event but no matter what I try the button will not appear.

Here is my code:

/app/etc/modules/ZeroBars_Approvebutton.xml

<?xml version="1.0"?>
<config>
    <modules>
        <ZeroBars_Approvebutton>
            <active>true</active>
            <codePool>local</codePool>
        </ZeroBars_Approvebutton>
    </modules>
</config> 

/app/code/local/ZeroBars/Approvebutton/etc/config.xml

<config>
    <modules>
        <ZeroBars_Approvebutton>
            <version>0.0.1</version>
        </ZeroBars_Approvebutton>
    </modules>
    <global>
    <models>
        <zerobars_approvebutton>
            <class>ZeroBars_Approvebutton_Model</class>
        </zerobars_approvebutton>
    </models>
    <helpers>
        <zerobars_approvebutton>
            <class>ZeroBars_Approvebutton_Helper</class>
        </zerobars_approvebutton>
    </helpers>
    <adminhtml>
    <events>
        <adminhtml_widget_container_html_before>
            <observers>
                <zerobars_approvebutton>
                    <class>zerobars_approvebutton/observer</class>
                    <method>adminhtmlWidgetContainerHtmlBefore</method>
                </zeroBars_approvebutton>
            </observers>
        </adminhtml_widget_container_html_before>
    </events>
</adminhtml>
</config>

/app/code/local/ZeroBars/Approvebutton/Model/Observer.php

<?php

Class ZeroBars_Approvebutton_Model_Observer
{
    public function adminhtmlWidgetContainerHtmlBefore($event) {

        $block = $event->getBlock();
        if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
            $block->addButton('do_something_crazy', array(
                'label'     => Mage::helper('module')->__('Button'),
                'onclick'   => "setLocation('{some location}')",
                'class'     => 'go'
            ));           
        }
    }
}

The method for adding a button on the page seems pretty straightforward so I am not sure why it is not working. Is there a possibility that another extension is overriding it?

3
  • Is your observer (method adminhtmlWidgetContainerHtmlBefore) being invoked?
    – laketuna
    Mar 25, 2015 at 1:00
  • Your module files seems ok for me except for the observer definition. You need to use class instead of Class in your Observer.php. Also clear the cache and then try again. Mar 25, 2015 at 1:09
  • I don't think the function adminhtmlWidgetContainerHtmlBefore is being called. I added a var_dump / die line to it and nothing happens at all on the front end. Also changed "class" to lowercase and the problem persists.
    – Kray
    Mar 25, 2015 at 22:31

1 Answer 1

1

In your config.xml you have a <global> node however that is never closed out add </global> before <adminhtml> and it should work everything else looks OK to me.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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