This blog clearly explains the steps that help you to change product image in the checkout cart in Magento:
- Create di.xml file
- Create image.php file
Build your Amazon-like multi-vendor marketplace website @ $249/- now!!!
Get your free live demo now: Click here
change the product image in the checkout cart in Magento 2
It’s an easy product with custom selections, where each option has its own color. When they include their modified version of the cart. We have additional set images for chosen option into the final product option. The steps listed below show you how to change product image in the checkout cart in Magento 2:
Step 1: Create a di.xml file
To create a 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 in Magento 2
To create an 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; } }
I hope the above-mentioned steps guide you to change the product image in checkout in Magento 2.
Leave a Reply