0

It will be great if someone provides me a small example of any core functionality overwrite.

0

1 Answer 1

0

It depends on what you're trying to do and what scope of effect you want it to have, but generally there are two types of customisation technique which you can use (there are others, but these are the 'best practice' approach):

Plugins

An implementation of the Aspect-Oriented Programming Design Pattern. They basically allow you to modify the behaviour of individual methods in a class. They are defined in XML (as are most things in Magento) and allow you to add/replace/customise the behaviour of individual methods before, during and after the method is executed. The Magento 2 Dev Docs have a very comprehensive overview of how they work and examples of how to use them:

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

Preferences

This technique allows you to replace one implementation of a class with your own. This is the closest thing Magento 2 has to the Magento 1 style 'class rewrite' feature and, just like when using that feature, defining a Preference will allow you to override an entire class. Once again, the Magento 2 Dev Docs has comprehensive explanations and examples, so I won't repeat what they've written here:

https://devdocs.magento.com/guides/v2.2/extension-dev-guide/build/di-xml-file.html#abstraction-implementation-mappings

There is also the event/observer system, but I haven't included that above because you only need to observe an event to use them, you don't need to override any part of the core and you specifically mentioned 'core functionality overwrite' in your answer.

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