0

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

2
  • in which file did you added this code? Nov 5, 2015 at 4:40
  • I have this code under app/code/local/MyModule/Pickup/Block/Adminhtml/Sales/Order/View.php
    – Jacco
    Nov 5, 2015 at 6:44

2 Answers 2

0

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
}
5
  • Ok, I assume that would be a new file located in app/code/local/MyModule/Pickup/controllers/action.php?
    – Jacco
    Nov 5, 2015 at 7:13
  • yes you will need to create controller class MyModule/Pickup/controllers/ like IndexController.php Nov 5, 2015 at 7:14
  • Almost there, sorry for the amount of ignorance from my side. I now created the file /Mymodule/Pickup/controllers/Action.php and in the getPickupUrl($order) I have return $this->getUrl('Mymodule_Pickup_controller_Action', array('order_id' => $order->getId())); Now if I click the button I am redirected to the frontend 404
    – Jacco
    Nov 5, 2015 at 7:24
  • you are doing it in wrong way. it should be like $this->getUrl('yourrouter/adminhtml_yourcontroller/youraction', array('order_id' => $order->getId())); Nov 5, 2015 at 7:34
  • Not sure I know what to make of that in my case. What should be in yourrouter yourcontroller youraction?
    – Jacco
    Nov 5, 2015 at 7:37
-1

admin side:

public function  __construct() {

    parent::__construct();

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

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

Fronted side:

public function getPickupUrl($order)
{
   return $this->getUrl('sales/order/view', array('order_id' => $order->getId()));
}
3
  • But this does not change the status of the order, or am I seeing it wrong?
    – Jacco
    Nov 5, 2015 at 6:46
  • can you add your module controller code in ques? Please add order status change code in your module
    – Abdul
    Nov 5, 2015 at 6:55
  • I was expecting something like this: (this does not work) public function getPickupUrl() { return $this->setState('processing', 'pickup_ready', 'test', false); return $this->save(); }
    – Jacco
    Nov 5, 2015 at 7:09

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.