Which is teh best way to extend a block with a custom method? Should I use a preference to override the whole class or is enough to declare the extended class with the new method inside the XML layout that contains the block?
-
Magento2 gave very good concept called Plugin we can do what ever after and before core function and also we have one more called around which will do both before and after below is code which will cover all info– Aditya ShahSep 27, 2018 at 19:30
-
or one module one plugin file is enough in that you can extend all module , all model and blocks and controller of complete Magento it self– Aditya ShahSep 27, 2018 at 19:32
-
I know what plugin are, but i don't want to change behaviour of a method but add a new method– Daniele RovattiSep 27, 2018 at 20:11
1 Answer
Avoid Preference until you haven't another option.
Because it's override your core file.
And when you update your magento version there changes will not reflect in your overridden file.
So i suggest used your custom file or plugin.