1

What could be the best method to override the core classes for the following scenario?.

I just want to change the error message thrown from a controller or from a model. For example, I want to change the login error message as 'Please sign in correctly' instead 'Invalid username or password'.

For this simple case should I use preference or plugin? Plugins may be used so that we can simply override the method itself. But is there any way which even simplifies the process for those kind of simple ovverriding?

3
  • For just change error or success message you should not use overriding or plugins. just change it with i18n translation files. – Prince Patel Sep 21 '17 at 6:21
  • Thanks Prince Patel. But if the case is like, need to change in only one place means, what should I do? Since the method of changing in i18n overrides message in all the places. – sabarivenkatesankrish Sep 21 '17 at 7:15
  • For that, you have only one way, use preference or plugin – Prince Patel Sep 21 '17 at 8:33
1

If your purpose for override the core classes is to only Change the Error Message. You can use the Locale Translation to change the error message. As all error messages can be update from i18n locale CSV file.

Updated: As you mentioned, If it is required to change the message in only one particular file. Use Plugins instead of rewriting core files again. There are so many good resource available for the same:

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

How to override cartcontroller in magento 2?

How to Override Core Block, Model and controller in Magento2

1
  • Thanks for your post pankaj. But this is not applicable for all the cases. May be I want to override a particular controller's message. But this will override that message entirely. – sabarivenkatesankrish Sep 21 '17 at 5:29

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.