A talk I gave at Mage Titans Italy 2018: http://www.magetitans.it/speakers/joke-puts/
How can you make Magento do what you want? In Magento 2 there are a lot of ways to add customizations. What are your options? Can you do a rewrite like in Magento 1? Should you use an event to add that business-critical logic when your invoice reaches state paid? Or is a plugin a better option? Maybe it’s the only option. What’s the deal with dependency injection and why do I need interfaces? In this talk we’re going to explore all the possibilities.
6. Dependency injection
“Dependency injection is the concept
of the external environment injecting
dependencies for an object instead
of that object manually creating them
internally.”
23. Not calling the callable
✖Other around plugins (sort order)
✖Other after plugins (sort order)
✖Original method
24. Call order prior original
1. Sort order from low to high
2. Order of the uasort() array
3. Before plugins
4. Around plugins (before calling the
callable)
25. Call order post original
1. Sort order from high to low*
2. Reversed order of the uasort()
array
3. Around plugins (after calling the
callable)
4. After plugins
* Only if an around plugin exists
26. PHPro/AModule/etc/di.xml à after plugin
<type
name="MagentoStoreModelAddressRenderer">
<plugin name="renderer_a"
type="PHProAModulePluginRenderer"
sortOrder="10"/>
</type>
PHPro/ZModule/etc/di.xml à after plugin
<type
name="MagentoStoreModelAddressRenderer">
<plugin name="renderer_z"
type="PHProZModulePluginRenderer"
sortOrder="20"/>
</type>
39. Dispatch order
1. Observers in the global area
a. Module sequence order
b. Order in events.xml
2. Observers in adminhtml or frontend area
a. Module sequence order
b. Order in events.xml
43. Preferences
• (+) Replace entire class or interface
implementation
• (-) Only one preference can be active
• (-) Replace entire class to replace one
line of code
45. Plugins
• (+) Manipulate behavior before, after
and around one method
• (+) Access to arguments and output
• (+) Multiple plugins for one method
• (-) Only public methods