3

In magento1 we are able to set Post value like following

$this->getRequest()->setPost('super_attribute', null)

So how can we set post in magento2?

2

You can setpost value in magento 2 like this, In magento 2 setPost() is deprecated and its use setPostValue()

If you want to use observer then,

public function addOrder(\Magento\Framework\Event\Observer $observer)
    {
    $request = $observer->getRequestModel();

    $orderData = array();
    $request->setPostValue('order', $orderData);
}

in normal you can use,

 $orderData = array();
$this->getRequest()->setPostValue('order', $orderData);
  • Do we need to get object of \Magento\Framework\App\RequestInterface $request or anythingelse because i tried with setParams but did not work. I am trying it in observer model – Bhupendra Jadeja Jul 14 '16 at 14:00
  • When i add this... it wont add to cart product so it is not working – Bhupendra Jadeja Jul 15 '16 at 5:43
1

I am not Sure but you can also use $_POST like $_POST['super_attribute'] = null;

  • 2
    But $_POST we can not use direct global array in magento2 as per the standard. – Bhupendra Jadeja Jul 14 '16 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.