We have been asked to add a functionality that flags every new product shown on the storefront category view and product view pages with a [NEW] prefix in front of its name. New implies anything within the 5 days of the product's created_at value.
Luckily for us, we can easily control a product's name via an after plugin on a product's getName method. All it takes is to define an afterGetName plugin with a category view and product view pages constraint, further filtered by a created_at constraint.
To register the plugin, we start by creating the <MODULE_DIR>/etc/frontend/di.xml file with content, as follows:
<config>
<type name="Magento\Catalog\Api\Data\ProductInterface">
<plugin name="newProductFlag" type="Magelicious\Catalog\Plugin\NewProductFlag"/>
</type>
</config>
We...