2

I can not override a protected function using plugin. iS there any other way to override the same function?

2
  • you can use override like as controller model we did without plugin Commented Sep 24, 2018 at 4:33
  • Check this stack, it explains how you can override a protected function in the correct way stackoverflow.com/questions/44241663/…
    – Korbin
    Commented Sep 24, 2018 at 6:29

1 Answer 1

2

You can not override protected function using plugin.

Plugin Limitations:

Plugins cannot be used with any of the following:

Final methods
Final classes
Non-public methods
Static methods
__construct
Virtual types
Objects that are instantiated before Magento\Framework\Interception is bootstrapped
Objects that are not instantiated by the ObjectManager (e.g. by using new directly).

For More Details refer Magento Devdoc

https://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html

In your case, you can use Preference to override these classes which have protected mathod.

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.