How to add new button to order view in Magento admin panel?

后端 未结 4 1959
情书的邮戳
情书的邮戳 2021-02-01 05:02

How to add custom button to order view page near \"Back\" and \"Edit\"?

4条回答
  •  春和景丽
    2021-02-01 05:37

    Instead of core hacks or rewrites, just use an observer to add the button to the order:

    
        
            
                
                    
                        your_module/observer
                        singleton
                        adminhtmlWidgetContainerHtmlBefore
                    
                
            
        
    
    

    Then just check in the observer if the type of the block matches the order view:

    public function adminhtmlWidgetContainerHtmlBefore($event)
    {
        $block = $event->getBlock();
    
        if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
            $message = Mage::helper('your_module')->__('Are you sure you want to do this?');
            $block->addButton('do_something_crazy', array(
                'label'     => Mage::helper('your_module')->__('Export Order'),
                'onclick'   => "confirmSetLocation('{$message}', '{$block->getUrl('*/yourmodule/crazy')}')",
                'class'     => 'go'
            ));
        }
    }
    

    The "getUrl" function of the block will automatically append the current order id to the controller call.

提交回复
热议问题