Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Magento 2

You're reading from   Mastering Magento 2 Maximize the power of Magento 2 to create productive online stores

Arrow left icon
Product type Paperback
Published in Jun 2016
Publisher Packt
ISBN-13 9781785882364
Length 340 pages
Edition 2nd Edition
Languages
Tools
Concepts
Arrow right icon
Authors (3):
Arrow left icon
Bret Williams Bret Williams
Author Profile Icon Bret Williams
Bret Williams
Jonathan Bownds Jonathan Bownds
Author Profile Icon Jonathan Bownds
Jonathan Bownds
Andre Gugliotti Andre Gugliotti
Author Profile Icon Andre Gugliotti
Andre Gugliotti
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Planning for Magento FREE CHAPTER 2. Installing Magento 2 3. Managing Products 4. Designs and Themes 5. Configuring to Sell 6. Managing Non-Product Content 7. Marketing Tools 8. Extending Magento 9. Optimizing Magento 10. Advanced Techniques 11. Pre-Launch Checklist Index

Extending Magento functionality with Magento plugins


We'll review a simple example of extending Magento functionality to give you an idea of what's involved and get you on your way. Magento 2.0 has introduced the concept of plugins that rely on dependency injection. While it's tempting to think of a plugin as interchangeable with extension or module, a plugin actually plays a significantly different role. It listens to any public method call on another object. As long as the class or method doesn't use the final keyword, any class and any public method is fair game, including methods in your classes, third-party classes and Magento classes. That's pretty impressive!

Start by declaring the plugin in the di.xml file, in the app/code/(vendor)/(modulename)/Plugins/ path, with the following XML code:

<config>
    <type name="ObservedType">
        <plugin name="pluginName" type="PluginClassName" sortOrder="1" disabled="false"/>
    </type>
</config>

In this example...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image