I am using $request = $observer->getRequest();
in my observer method but it is not returning anything. i am using sales_order_place_before
event.
6 Answers
To get Request parameters in the Observer, use following code
Mage::app()->getRequest()->getParams();
To get post variable
Mage::app()->getRequest()->getPost('your-param');
-
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.– veduCommented Nov 24, 2015 at 6:39
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');
-
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.– veduCommented Nov 24, 2015 at 6:53
-
-
<select name="delivery_day" id='emq_del_day'> <option value="">--Select Day--</option> <option value="Today">Today</option> <option value="Tomorrow">Tomorrow</option> </select>– veduCommented 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').– veduCommented 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
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
}
You may also try with below code to read all the parameters
$orders = $observer->getData();
echo '<pre>'; print_r($orders); echo '</pre>';
-
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.– veduCommented Nov 24, 2015 at 6:39
-
You may use $data = Mage::app()->getRequest()->getParams(); to get the data– VickCommented Nov 24, 2015 at 6:47
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();
-
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.– veduCommented 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.– fmrngCommented 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.– veduCommented Nov 24, 2015 at 6:46
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
}