0

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 Shah Sep 27 '18 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 Shah Sep 27 '18 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 Rovatti Sep 27 '18 at 20:11
0

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.

| improve this answer | |

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.