Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting POST data in Magento observer

Tags:

php

magento

So, I'm struggling with this, I've got an observer set up to trigger whenever customer/account/login is hit. Firebug clearly shows that I'm POSTing data to this URL and I'm not able to read said POST data in my observer method.

Observer method:

public function checkCustomerLogin($observer) {
    Mage::log("event observed");
    $controller = $observer->getControllerAction();
    Mage::log(print_r($controller->getRequest()->getPost(), true));
    return $this;
}

Example log result:

2014-03-11T11:46:38+00:00 DEBUG (7): event observed
2014-03-11T11:46:38+00:00 DEBUG (7): Array
(
)

My observer is configured to trigger on controller_action_predispatch_customer_account_login. Clearly I'm doing something wrong here seeing as how I just can't get my POST data (I've tried a few other desperate approaches but from what I can tell this is how you're "supposed" to get a controller and the POST data in an observer method).

like image 352
mludd Avatar asked Mar 11 '14 11:03

mludd


2 Answers

instead of controller use app so

instead of

Mage::log(print_r($controller->getRequest()->getPost(), true));

change to

Mage::log(print_r(Mage::app()->getRequest()->getPost(), true));

So that instead of controller you are using $app to get post details.

like image 87
Oscprofessionals Avatar answered Oct 21 '22 09:10

Oscprofessionals


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

It will return array of all parameters sent to called controller's action

Hope this helps you

like image 44
Mohit Kumar Arora Avatar answered Oct 21 '22 10:10

Mohit Kumar Arora