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?

3
  • 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 Sep 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 Sep 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 Sep 27, 2018 at 20:11

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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