5

I am trying to access request parameters made to the api url which I am setting a response for via a plugin.

The call is to: rest/default/V1/guest-carts/a9e6330920e85d09a123a396f77a9275/shipping-information

Here is the code that I am currently using, however it provides an empty array.

namespace Vendor\Onepage\Plugin;

class ShippingInformationManagementPlugin
{

protected $_request;


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

public function beforeSaveAddressInformation(
    \Magento\Checkout\Model\ShippingInformationManagement $subject,
    $cartId,
    \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation
)
{
    var_dump($this->_request->getParams());
    die('testing');
}

}
10

Looks like you are using wrong class in your construct for $request. Change your construct to following and it should work:

public function __construct(
    \Magento\Framework\Webapi\Rest\Request $request
) {
    $this->_request = $request;
}

After that you can get REST request's parameters in following way:

var_dump($this->_request->getParams());

Do clear necessary caches after the above change.

| improve this answer | |
1

You have to change the line

var_dump($this->_request->getParams());

to

var_dump($subject->_request->getParams());
| improve this answer | |

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.