One of the major things that has changed in Magento 2 is that there is no Mage
class. To replace this, all objects are passed to the classes with dependency injection.
Dependency injection is a powerful tool that adds a lot of flexibility to add or change behavior in Magento.
To explore the possibilities of dependency injection of Magento 2, we need the module that we created in the previous recipes.
The following steps describe how we can modify the behavior of some classes, which is a new concept in Magento 2 that replaces the rewriting of classes in Magento 1:
Create the
app/code/Packt/HelloWorld/etc/di.xml
file and paste the following content in it:<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Catalog\Model\Product"> <plugin name="Packt_HelloWorld::productName" type...