cancel
Showing results for 
Search instead for 
Did you mean: 

Add Image to Compare Sidebar

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!

7 REPLIES 7

Re: Add Image to Compare Sidebar

Hello @jazz_singh 

Please follow the below steps:

  1. Add di.xml to your custom module app\code\[Vendor]\[Module]\etc\di.xml

  2. Add AddImageToCompareProductsPlugin.php to
    app\code\[Vendor]\[Module]\Plugin\AddImageToCompareProductsPlugin.php

  3. 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.

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

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.

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.

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

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!

Re: Add Image to Compare Sidebar

@jazz_singh 

 

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.

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

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!

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