I wanted to know when should I use observers instead of a plugin.
Asked
Active
Viewed 1,382 times
1
-
Refer this answer: https://magento.stackexchange.com/a/161504/35758 – Prince Patel Feb 22 '18 at 05:02
1 Answers
1
IMO, you should prefer using plugins and "fallback" to observers when you can't modify some arbitrary functionality; either because it's isolated within a protected method (plugins do not work on protected or private methods), or because the observer provides access to an object that is otherwise inaccessible because of the nature of the code. The latter is rather rare, but Magento explicitly passes objects into an observer.
Ethan Yehuda
- 685
- 5
- 12