0

I have a question regarding the best practices of model overriding.

For instance if I need to create a Me\MyModule\Catalog\Model\Product.php to replace (by inheritance and di.xml settings) the original Magento\Catalog\Model\Product.php to add new methods (for example for processing custom attributes), what is wise to do?

My concerns are about the risk of conflicts. What will happen if another developper create, in another module, its own version of this file?

1

Instead of overriding the model class, you can you plugin to achieve your goal. Based on the sort order it will work, so we can avoid conflicts.

Useful links to refer,

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

http://alanstorm.com/magento_2_object_manager_plugin_system/

2
  • Yes but with a plugin you can EDIT an already existing method. Not to add new one... – enrico69 Feb 16 '17 at 13:21
  • yes, missed "new" in your question. We have chances of conflicts in overriding the same class in two different modules. before override, the developer have to confirm and use hierarchy inheritance like, Class A extends Class B, Class C extends Class B – seeni Feb 16 '17 at 14: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.