Question

<?php

namespace Maxime\Helloworld\Observer;


use Magento\Framework\Event\ObserverInterface;

class Productsaveafter implements ObserverInterface
{

 public function execute(\Magento\Framework\Event\Observer $observer)

 {
  $post = $this->getRequest()->getPostValue();
    }

}

Used this code. But it didin't gives the post values.

Was it helpful?

Solution

In your observer constructor do:

public function __construct(
    \Magento\Framework\App\RequestInterface $request
)
{
    $this->_request = $request;
}

Then in your code use $this->_request to fetch post params, like below :

$post = $this->_request->getPost();

OTHER TIPS

$data = $this->getRequest()->getParams();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top