0

Config.xml

    <?xml version="1.0"?>
<config>
  <modules>
    <Manoj_Csv>
      <version>0.1.0</version>
    </Manoj_Csv>
  </modules>
  <global>
   <adminhtml>
        <events>
            <adminhtml_widget_container_html_before>
                <observers>
                    <manoj_csv>
                        <class>csv/observer</class>
                        <method>adminhtmlWidgetContainerHtmlBefore</method>
                    </manoj_csv> 
                </observers>
            </adminhtml_widget_container_html_before>
        </events>
    </adminhtml>
  </global>
</config> 

observer.php

<?php

Class Manoj_Csv_Model_Observer
{
    public function adminhtmlWidgetContainerHtmlBefore($event)
    {
        $block = $event->getBlock();
        $message = Mage::helper('sales')->__('Are you want to Download...?');

        if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
            $block->addButton('do_something_crazy', array(
                'label'     => Mage::helper('Sales')->__('Download...'),
                'onclick'   => "confirmSetLocation('{$message}','{$block->getUrl('*/')}')", // < missed comma
                'class'     => 'go'
            ));
        }
    }
}

1 Answer 1

2

Try this:
observer name should be in lower case (start and end tags)

    <adminhtml>
        <events>
            <adminhtml_widget_container_html_before>
                <observers>
                    <zerobars_approvebutton>
                        <class>test_module/observer</class>
                        <method>adminhtmlWidgetContainerHtmlBefore</method>
                    </zerobars_approvebutton> <!-- should be lowercase here-->
                </observers>
            </adminhtml_widget_container_html_before>
        </events>
    </adminhtml>

Missed "," in observer and unexisting $this->getUrl():

    public function adminhtmlWidgetContainerHtmlBefore($event)
    {
        $block = $event->getBlock();
        $message = Mage::helper('sales')->__('Are you sure you want to Change Status?');

        if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
            $block->addButton('do_something_crazy', array(
                'label'     => Mage::helper('Sales')->__('Download...'),
                'onclick'   => "confirmSetLocation('{$message}','{$block->getUrl('*/')}')", // < missed comma; use $block->getUrl() instead $this->getUrl()
                'class'     => 'go'
            ));
        }
    }

Result (it works fine):

Result with observer

If you still get errors, try to replace the class call <class>csv/observer</class> with the <class>Manoj_Csv_Model_Observer</class> or with the <class>manoj_csv/observer</class>

Complete config.xml :

<?xml version="1.0"?>
<config>
    <modules>
        <Manoj_Csv>
            <version>0.1.0</version>
        </Manoj_Csv>
    </modules>
    <global>
    </global>
    <adminhtml>
        <events>
            <adminhtml_widget_container_html_before>
                <observers>
                    <manoj_csv>
                        <class>Manoj_Csv_Model_Observer</class>
                        <method>adminhtmlWidgetContainerHtmlBefore</method>
                    </manoj_csv>
                </observers>
            </adminhtml_widget_container_html_before>
        </events>
    </adminhtml>
</config> 
7
  • Check my updated question what i missed
    – Magento 2
    Apr 3, 2016 at 14:55
  • @Kothari try change <class>csv/observer</class> to <class>Manoj_Csv_Model_Observer</class> or to <class>manoj_csv/observer</class> Apr 3, 2016 at 14:58
  • I tried but not working
    – Magento 2
    Apr 3, 2016 at 14:59
  • @Kothari It's strange, becouse it works fine for me Apr 3, 2016 at 15:02
  • Ok i will check my end
    – Magento 2
    Apr 3, 2016 at 15:03

Your Answer

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

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