Get post data in observer magento 2

This tutorial is about Get post data, in observer Magento 2 .i.e how to get post data, in Checkout success observer in Magento 2 or any save after observer action. And in this tutorial, I will try to explain it briefly and in a simple way.

We can add the request to a class through dependency injection and access it via a singleton.

Use the following code:

protected $_request;

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

Inside function get post data in the following way:

$this->_request->getParams();

That’s it from this tutorial. I hope it serves the purpose. Since these are learning tutorials, please feel free to drop any suggestions or queries in the comments section. That will definitely be highly appreciated.

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!

2 thoughts on “Get post data in observer magento 2

  1. Hi,
    Thanks for your codes to get the post params in observer. But using the same method we are unable to get CC form data in this post params when I try to submit order form from admin.
    We are using checkout_submit_all_after event to get order form data.
    Thanks in advance.

Leave a Reply