Book Image

Mastering Magento 2 - Second Edition

By : Bret Williams, Andre Gugliotti, Jonathan Bownds
Book Image

Mastering Magento 2 - Second Edition

By: Bret Williams, Andre Gugliotti, Jonathan Bownds

Overview of this book

The long-awaited release of the world's most popular online solution, Magento 2, is now out with an all new interface and several enhancements. This book offers you advanced guidance on managing, optimizing, and extending your store while taking advantage of the new features of Magento 2. This is a comprehensive guide to using the all new features and interface of Magento 2 to build, extend, and design online stores. From planning your Magento installation through to advanced techniques designed to make your store as successful as possible, this book is your roadmap to managing your Magento store. Focusing on Magento's Community version, the book covers everything from creating and managing multiple stores to fine-tuning Magento for speed and performance. You’ll learn how to manage categories, products, design themes, extensions, and more.
Table of Contents (18 chapters)
Mastering Magento 2 Second Edition
About the Authors
About the Reviewer

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:

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

In this example...