Example: add a string to getName() of Product class.
You have to create app/code/vendorName/moduleName/etc/di.xml:
<?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="plugin_name" type="VendorName\ModuleName\Plugin\Catalog\ProductAfter" />
</type>
</config>
and app/code/VendorName/ModuleName/Plugin/Catalog/ProductAfter.php:
<?php
namespace VendorName\ModuleName\Plugin\Catalog;
class ProductAround
{
public function afterGetName(\Magento\Catalog\Model\Product $product, $result)
{
return $result." string";
}
}
The result is: the name of product + " string".