4

I am using $request = $observer->getRequest();in my observer method but it is not returning anything. i am using sales_order_place_beforeevent.

1
  • $request = $observer->getEvent()->getRequest(); $params = $request->getParams();
    – LinoPham
    Commented Nov 24, 2015 at 7:43

6 Answers 6

5

To get Request parameters in the Observer, use following code

Mage::app()->getRequest()->getParams();

To get post variable

Mage::app()->getRequest()->getPost('your-param');
1
  • Thank you for your answer. In starting, I was using checkout_controller_onepage_save_shipping_method this event and, I was able to get request object by $request = $observer->getRequest(); and then I was accessing parameter by $request->getParam('parameter_name'). Can you tell me how to access this parameter by using sales_order_place_before event.
    – vedu
    Commented Nov 24, 2015 at 6:39
1

you can get shipping and billing array with below code

$shipping=Mage::app()->getRequest()->getPost('shipping');
$billing=Mage::app()->getRequest()->getPost('billing');
$yourfieldname=Mage::app()->getRequest()->getPost('yourfieldname');
15
  • Thank you for your answer. My field name is delivery_day and I am printing Mage::log(Mage::app()->getRequest()->getPost('delivery_day')); but, it is not printing anything.
    – vedu
    Commented Nov 24, 2015 at 6:53
  • can you post the input field so i can check that? Commented Nov 24, 2015 at 6:55
  • <select name="delivery_day" id='emq_del_day'> <option value="">--Select Day--</option> <option value="Today">Today</option> <option value="Tomorrow">Tomorrow</option> </select>
    – vedu
    Commented Nov 24, 2015 at 6:56
  • I was using checkout_controller_onepage_save_shipping_method this event and, I was able to get request object by $request = $observer->getRequest(); and then i was accessing parameter by $request->getParam('delivery_day').
    – vedu
    Commented Nov 24, 2015 at 6:58
  • use this event checkout_type_onepage_save_order_after use in billing array <select name="billing[delivery_day]" id='emq_del_day'> <option value="">--Select Day--</option> <option value="Today">Today</option> <option value="Tomorrow">Tomorrow</option> </select> and get it $billing['delivery_day']; Commented Nov 24, 2015 at 7:03
1

Use the following code to resolve your query:

public function yourFunction(Varien_Event_Observer $observer)
{
    $order = $observer->getEvent();
    echo $order->getOrder()->getPayment()->getMethod(); // get selected paymante method

    $quote = Mage::getSingleton('checkout/session')->getQuote();
    echo $quote->getBillingAddress()->getTelephone(); // get billing address phone number

}
0

You may also try with below code to read all the parameters

 $orders = $observer->getData();
 echo '<pre>'; print_r($orders); echo '</pre>';
2
  • Thank you for your answer. In starting, I was using checkout_controller_onepage_save_shipping_method this event and, I was able to get request object by $request = $observer->getRequest(); and then I was accessing parameter by $request->getParam('parameter_name'). Can you tell me how to access this parameter by using sales_order_place_before event.
    – vedu
    Commented Nov 24, 2015 at 6:39
  • You may use $data = Mage::app()->getRequest()->getParams(); to get the data
    – Vick
    Commented Nov 24, 2015 at 6:47
0

As you can see from Mage_Sales_Model_Order::place(), the only available data for this event is order. To access the request object inside your event observer, you can do something like:

$request = Mage::app()->getRequest();
3
  • Thank you for your answer. In starting, I was using checkout_controller_onepage_save_shipping_method this event and, I was able to get request object by $request = $observer->getRequest(); and then I was accessing parameter by $request->getParam('parameter_name'). Can you tell me how to access this parameter by using sales_order_place_before event.
    – vedu
    Commented Nov 24, 2015 at 6:39
  • See my answer above: you don't have access to the request from the observer data, but you can still get the request object by calling $request = Mage::app()->getRequest(); in your event observer.
    – fmrng
    Commented Nov 24, 2015 at 6:42
  • That code is returing : Mage_Core_Controller_Request_Http Object array but there are different parameters present and parameters those I want are not present.
    – vedu
    Commented Nov 24, 2015 at 6:46
0
public function yourFunction(Varien_Event_Observer $observer)
{
    $order = $observer->getEvent();
    echo $order->getOrder()->getPayment()->getMethod(); // get selected paymante method

    $quote = Mage::getSingleton('checkout/session')->getQuote();
    echo $quote->getBillingAddress()->getTelephone(); // get billing address phone number
}

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.