I tried to get the order_id from an observer

here is my observer

 public function adminhtmlWidgetContainerHtmlBefore($observer) {
        if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
            $block->addButton('do_something_crazy', array(
                'label'     => Mage::helper('sales')->__('Print Sticker'),
                    'onclick'   => 'setLocation(\'' . $this->getPrintStickerUrl() . '\')',
                    'class'     => 'go'

I got this error:

Call to undefined method Company_extention_Model_Observer::getOrderId(). I tried too $order = $observer->getEvent()->getObject();

but nothing,

Could you help me?


  • Mage::app()->getRequest()->getParam('id') try this you will get order id
    – Keyur Shah
    Commented May 22, 2015 at 5:26

2 Answers 2


The $observer variable contains all the information and methods you need. You were on the right track with $observer->getEvent(), but from there you must figure out what variables are stored in the event and access them appropriately.

A quick grep shows that the event is triggered in Mage_Adminhtml_Block_Widget_Container with the line: Mage::dispatchEvent('adminhtml_widget_container_html_before', array('block' => $this));, so you can access that variable with getBlock(). Now after checking that the block type is the one you want, you can call getOrder() on the Mage_Adminhtml_Block_Sales_Order_View object.

Your method should look something like this:

public function adminhtmlWidgetContainerHtmlBefore($observer) {
  $block = $observer->getEvent()->getBlock();
  if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
    $order = $block->getOrder();
    $block->addButton('do_something_crazy', array('label' => Mage::helper('sales')->__('Print Sticker'), 'onclick' => 'setLocation(\'' . $this->getPrintStickerUrl() . '\')', 'class' => 'go'));
  • hi Nachito, Thanks for your help but, unfortunatly, it is not work. var_dump($observer->getEvent()->getOrder()); give me NULL. Commented May 21, 2015 at 20:09
  • What event are you observing?
    – nachito
    Commented May 21, 2015 at 20:10
  • Mage_Adminhtml_Block_Sales_Order_View, I'm trying to add a button, Commented May 21, 2015 at 20:23
  • @ismo: Updated.
    – nachito
    Commented May 21, 2015 at 20:47
  • Thanks against, I can load the object order. and now how to get the order_id? Commented May 21, 2015 at 20:59

It can better idea to use class match and

Issue: wrong object:

$this mean current class object and but you need Mage_Adminhtml_Block_Sales_Order_View class object .As per $block is object of this Mage_Adminhtml_Block_Sales_Order_View.

$this->getOrderId() should be $block->getOrdeId();

The function getOrderId() is exits in that class but it is given null value henever this does not have value.

for getting Sale model object then try this $block=$block->getOrder();

Then you can use


instead of

$block instanceof Mage_Adminhtml_Block_Sales_Order_View

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.