How to change product image in checkout cart in Magento 2

The following steps help you to change product image in checkout cart in Magento 2:

  • Create di.xml file
  • Create image.php file

It is a simple product with custom options, where every option has its own color. Once they add their modified version of the cart. We have more collection images for chosen option in to final product option. Listed steps show to how to change product image in checkout cart in magento:

Step 1: create di.xml file

To create di.xml file use

app/code/[Name_Space]/[Your_Module]/etc/frontend
<?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\Checkout\Block\Cart\Item\Renderer">

 <plugin name="Change_Product_Image_In_Checkout_Cart" type="[Name_Space]\[Your_Module]\Plugin\CheckoutCart\Image" sortOrder="1"/>

</type>

</config>

Step 2: create image.php

To create image.php file use

 app/code/[Name_Space]\[Your_Module]\Plugin\CheckoutCart
<?php

namespace [Name_Space]\[Your_Module]\Plugin\CheckoutCart;

class Image

{

    public function afterGetImage($item, $result)

    {

     if(YOUR_CONDITION) {

     $result->setImageUrl( YOUR_IMAGE_URL );

     }

     return $result;

    }

}

The above mention steps helps you to change product image in checkout in Magento 2.

Last Update: April 9, 2018  

February 6, 2018   235   Nandini R    Products    
Total 1 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Google+
http://www.webnexs.com/blog/kb/change-product-image-checkout-cart-magento-2
Twitter
LinkedIn