When creating plugin (http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html) is there a way to get original parameters in after method?
I'm not sure what i can find in the first param (Interceptor)
When creating plugin (http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html) is there a way to get original parameters in after method?
I'm not sure what i can find in the first param (Interceptor)
My own solution: Use around method, and as first call the $proceed. If anyone have another solution, i would like to hear it.
public function aroundFooBar(InterceptorInterface $object, callable $proceed, ..args)
{
$result = $proceed(..args)
// after code
return $result;
}
In Magento 2.1, the answer of @michalhosna is correct: You need to use an around plugin.
From Magento 2.2 onwards, you can access the parameters directly in an after plugin:
public function afterFooBar(InterceptorInterface $object, callable $proceed, $arg1, $arg2, $arg3)
{
// after code; for example:
$result = $arg1 . $arg2 . $arg3;
// return the result
return $result;
}
From Magento 2.2 onwards, it is recommended to use around plugins only if absolutely necessary, and to use after plugins instead if possible. Reference: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/plugins.html