4

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)

2 Answers 2

4

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;
}
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.