简体   繁体   中英

Magento order view button for id process

I must place a button in order view that will send further the order id. The id will be used for a simple database query then it should return to order view.

I found out how to create the button, I created app/code/local/Mage/Adminhtml/Block/Sales/Order/View.php following the view.php from core.

Here is my code :

class Mage_Adminhtml_Block_Sales_Order_View extends
   Mage_Adminhtml_Block_Widget_Form_Container
    {

    public function __construct()
    {
        $this->_objectId    = 'order_id';
        $this->_controller  = 'sales_order';
        $this->_mode        = 'view';

        parent::__construct();

        $this->_removeButton('delete');
        $this->_removeButton('reset');
        $this->_removeButton('save');
        $this->setId('sales_order_view');
        $order = $this->getOrder();

        $this->_addButton('release_payment', array(
                'label' => Mage::helper('sales')->__('Release Payment'),
                'onclick' => 'setLocation(\'' . $this->getUrl('*/*/release') . '\')',
                'class' => 'go'
            ));
    }

What I want is that this location that should be sales_order/release to actually do something with the order id. I tried to understand how but I can't manage to actually create the controller.

You should probably collect those overrides into a module. The ugly method would otherwise be to copy

app/code/core/Mage/Adminhtml/controllers/OrderController.php

to

app/code/local/Mage/Adminhtml/controllers/OrderController.php

and add the releaseAction() -function to it.

For the more elegant solution you would need to create a module with config options in it's etc/config.xml file to override/overload the specified block and controller code. With this method your changes are better contained and it's easy to switch the module on/off. Also when extending the original block/controller you don't need to include anything other then the modified/added methods, the rest will be executed from the original file.

Actually even the main documentation from Magento has decent examples: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller

And Googling for magento controller overload gives good results too, so I won't give an lengthy example right here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM