Magento – Custom button to set custom order status

magento-1.9moduleorder-status

I created a custom module to add a button to the order view page.

The button shows up and now it is time to create the action attached. When clicking the button I want 2 things to happen:

Set the order status to: Ready for Pickup (pickup_ready) which I defined in order statusses
Send a transactional email to the client to inform them it is ready

My button looks like this for now:

{
public function  __construct() {

    parent::__construct();

        $this->_addButton('inform_pickup', array(
            'label'     => Mage::helper('sales')->__('Custom Pickup Button'),
            'onclick'   => 'setLocation(\'' . $this->getPickupUrl() . '\')',
        ));
    }

public function getPickupUrl()
{
    Not a clue what to put here......;
}
}

Any help is appreciated

Best Answer

In construct function you will need to pass order object in your

public function  __construct() {

    parent::__construct();

    $order = $this->getOrder();

        $this->_addButton('inform_pickup', array(
            'label'     => Mage::helper('sales')->__('Custom Pickup Button'),
            'onclick'   => 'setLocation(\'' . $this->getPickupUrl($order) . '\')',
        ));
    }

You will need to create your controller to handle the action

public function getPickupUrl($order)
{
   return $this->getUrl('your_adminhtml_controller_action', array('order_id' => $order->getId()));
}

In your controller class create your action for example

public function pickupAction()
{
  $orderId = $this->getRequest()->getParam('order_id');
  $order = Mage::getModel('sales/order')->load($orderId);
  $order->setStatus("pickup_ready");
  $order->save();
  // redirect to your sales order view page back
}
Related Topic