How to get the current request parameters in an observer?

Am trying to get the request parameters on my “checkout_cart_update_items_before” Observer.

public function execute(EventObserver $observer)
$request = $observer->getRequest();

The above code does not work. Can anyone explain me how to get request parameters on observer ??

Use \Magento\Framework\App\RequestInterface::getParams().


Thanks @dmitry_fedyuk , that was helpful. I managed to fix it by adding it to the constructor.
Full Observer code below.

<?php namespace Beack\Checkout\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Framework\Event\Observer as EventObserver; class UpdateItemBefore implements ObserverInterface { /** * @var \Magento\Framework\App\RequestInterface */ protected $_request; /** * @param \Magento\Framework\App\RequestInterface $request */ public function __construct( \Magento\Framework\App\RequestInterface $request ) { $this->_request = $request; } /** * @param EventObserver $observer * @return void */ public function execute(EventObserver $observer) { $cart = $observer->getEvent()->getCart(); $reqeustParams = $this->_request->getParams(); } }
1 Like