You can create a plugin in Magento 2 to insert code dynamically without changing the original class behavior. It allows extending the core functionality without any modification to the core files.
In Magento 1, you can rewrite a class to customize different classes and methods, but the drawback of it is, no module could rewrite the same class, and thus it has no flexibility. To overcome the rewrite conflicts and instability, Magento 2 is being introduced with inceptors or plugins!
But in Magento 2, whenever you create a virtual type plugin to override or extend functionality in the catalog search page, you get Magento 2 Plugin Issue in Catalog Search! The methods get overridden on the category page but remain unchanged and show no effect on the catalog search page. To solve the Magento 2 plugin issue in catalog search, I have come up with the following solution:
Guide to Solve Magento 2 Plugin Issue in Catalog Search:
Go to [Namespace]\[Module]\etc\frontend\di.xml and put below code:
<plugin name="[Namespace]_[Module]::ListProduct" type="[Namespace]\[Module]\Plugin\Catalog\Product\ListProduct"/>
<plugin name="[Namespace]_[Module]::VirtualTypeListProduct" type="[Namespace]\[Module]\Plugin\Catalog\Product\ListProduct" />
That’s all about to solve the plugin issue in the catalog search in Magento 2. After overriding the above code, your extended functionality can be easily seen in effect even on the catalog search page.
We implemented the above solution to show assigned product labels on the catalog search page which was previously showing only on the category and product page.
Let me know how have you implemented the above solution to extend the functionality on the catalog search page! Do comment in the below section if you stuck somewhere or having any questions, I would be happy to help my valued readers!
Get Weekly Updates
Never miss Magento tips, tricks, tutorials, and news.
Thank you for subscribing.
Something went wrong.