- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Add Image to Compare Sidebar
Is there any way to add the product image to the compare sidebar on the category page? I've tried the following (https://gist.github.com/rubenRP/002d06c7b8d6c6eb44d43e102f86ec38) however it doesn't seem to be working. I'm on Magento version 2.3.4.
Any help is greatly appreciated!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Add Image to Compare Sidebar
Hello @jazz_singh
Please follow the below steps:
- Add di.xml to your custom module app\code\[Vendor]\[Module]\etc\di.xml
- Add AddImageToCompareProductsPlugin.php to
app\code\[Vendor]\[Module]\Plugin\AddImageToCompareProductsPlugin.php - Add sidebar.phtml to your theme path like :
app/design/frontend/[VENDOR_NAME]/[THEME_NAME]/Magento_Catalog/templates/product/compare/sidebar.phtml
OR
Add sidebar.phtml to your custom module
app\code\[Vendor]\[Module]\view\frontend\layout\default.xml
default.xml<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <referenceContainer name="sidebar.additional"> <block class="Magento\Framework\View\Element\Template" name="catalog.compare.sidebar" template="Vendor_Module::product/compare/sidebar.phtml"> <arguments> <argument name="jsLayout" xsi:type="array"> <item name="components" xsi:type="array"> <item name="compareProducts" xsi:type="array"> <item name="component" xsi:type="string">Magento_Catalog/js/view/compare-products</item> </item> </item> </argument> </arguments> </block> </referenceContainer> </page>
Note: After following the above 3 steps, clear cache and remove generate/code folder.
Hope it helps.
200+ Magento 2 Extensions for Enhanced Shopping Experience.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Add Image to Compare Sidebar
Hi @Sanjay Jethva,
I've done those steps before but I did them again and it's still not working, it breaks the compare sidebar - no product is loaded in. Do I need to add the module.xml/registration.php files to the module? I tried doing this before too but it didn't work.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Add Image to Compare Sidebar
Hey @jazz_singh again,
Are you implementing this code in a custom module or anywhere else?
Moreover, check if your plugin and sidebar.phtml are called properly using log
Thanks.
200+ Magento 2 Extensions for Enhanced Shopping Experience.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Add Image to Compare Sidebar
Hi @Sanjay Jethva,
Yeah, I'm creating a module which includes the files that you mentioned. The sidebar I'm using is the default 2.3.4 sidebar with the extra image line included.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Add Image to Compare Sidebar
Please check your custom module installation.
Also, when you check if the files plugins and sidebar.phtml are called properly, put log and check it's working in Magento 2.3.4.
Thanks.
200+ Magento 2 Extensions for Enhanced Shopping Experience.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Add Image to Compare Sidebar
Hi @Sanjay Jethva,
I've fixed the module and it's pulling the image correctly now.
Thanks for your quick replies!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Add Image to Compare Sidebar
Hi @jazz_singh can you share the solution I am trying to add Image to Compare Sidebar in Magento 2.4.5-p1 version