Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento getPost empty array

I have the following code (please excuse the bad coding, it's like that to debug):

$postData = Mage::app()->getRequest()->getPost();
if(!$postData)
{
    $postData = $this->getRequest()->getPost(); 
}
if(!$postData)
{
    $postData = $_POST; 
}

As you can see, I am simply trying to get the HTTP POST values.

Here's the scenario:

  1. From a HTTP POST Simulator, the data comes through
  2. From the Shopify webhook, nothing comes through (just "Array()")
  3. Shopify posting to PostCatcher shows a lot of data

Shopify is posting in JSON format.

Any ideas as to ahy I can't catch the POST array?

like image 722
dhardy Avatar asked Jul 11 '26 07:07

dhardy


2 Answers

You cant get JSON post values by using simply $_POST or Mage::app()->getRequest()->getPost();. Just try this,

$value = json_decode(file_get_contents('php://input'));
print_r($value);
like image 199
Elavarasan Avatar answered Jul 13 '26 16:07

Elavarasan


In one of my project I got the same error

Mage::app()->getRequest()->getPost(); was giving the blank values.

I was using one extension when I was submitting the form there was one description field for the manufacturer.

If it was having text content like from , select or some content similar to SQL commands. It was not posting the form data.

The reason was the hosting provider had some settings for sanitizing the data to prevent the SQL injection.

I raised the ticket to the hosting provider and the problem was solved.

Before this I tried lot of coding stuff which was not required.

like image 33
Mukesh Avatar answered Jul 13 '26 16:07

Mukesh