I want to add new Button on Sales order view page. I created below mention code
observer file
<?php
class Ar_Orderstatus_Model_Observer
{
public function addOrderstatusAction($observer)
{
$block = $observer->getEvent()->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
$message = Mage::helper('sales')->__('Are you sure you want to Change Status?');
$block->addButton('rto',
array( 'label' => Mage::helper('sales')->__('RTO'),
'onclick' => "confirmSetLocation('{$message}', '{$block->getUrl('orderstatus/adminhtml_index/rto')}')", 'class' => 'go' ));
$block->addButton('in_shipment',
array( 'label' => Mage::helper('sales')->__('In Shipement'),
'onclick' => "confirmSetLocation('{$message}', '{$block->getUrl('orderstatus/adminhtml_index/in_shipment')}')", 'class' => 'go' ));
}
}
}
controller file
<?php
class Ar_Orderstatus_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
protected function _initOrder()
{
$id = $this->getRequest()->getParam('order_id');
$order = Mage::getModel('sales/order')->load($id);
if (!$order->getId()) {
$this->_getSession()->addError($this->__('This order no longer exists.'));
$this->_redirect('*/*/');
$this->setFlag('', self::FLAG_NO_DISPATCH, true);
return false;
}
Mage::register('sales_order', $order);
Mage::register('current_order', $order);
return $order;
}
public function testAction()
{
if ($order = $this->_initOrder()) {
try {
$order->setState('rto', true)
->save();
$this->_getSession()->addSuccess(
$this->__('The order state has been changed.')
);
}
catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage());
}
catch (Exception $e) {
$this->_getSession()->addError($this->__('The order state has not been changed.'));
Mage::logException($e);
}
$this->_redirect('adminhtml/sales_order/view', array('order_id' => $order->getId()));
}
}
}
Best Answer
Follow bellow steps
Step : 1 app\etc\modules\AR_Orderstatus.xml
Step : 2 app\code\local\AR\Orderstatus\etc\config.xml
Step : 3 app\code\local\AR\Orderstatus\controllers\Adminhtml\IndexController.php
Step : 4 app\code\local\AR\Orderstatus\Model\Observer.php