Вопрос

About use of each kind of interceptor (plugin) was answered here: Is it better to use solely around function instead of before+after combined? But in Magento docs says:

Avoid using around method plugins when they are not required because they increase stack traces and affect performance

With that in mind... I know in some cases we must use it because is the only way, but when it is possible to use before and after instead around should I always do it? Before and after together have better performance than around?

In my case for example, I just want to test if a plugin changed a Object that is not received as parameter, so in beforeMethod I would get its object status and check if was modified in afterMethod. Should I use before+after or around?

Update Magento docs answer this question somehow:

The only use case for around method plugins is when the execution of all further plugins and original methods need termination

Это было полезно?

Решение

"Using the Around plugin in your code isn’t the best practice. Magento recommends avoiding this method and using the before and after plugins instead." - Amasty

So use After and before but if you want to completely override the public method then you can use around that is why it gets introduced to us right.

but it might cause issues in the future. So Avoid it as much you can

Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top