In this topic we will show you How to Change Product Image in Checkout Cart in Magento 2 through 2 steps:
- Step 1: Create di.xml file
- Step 2: Create Image.php file
It’s basically a simple product with custom options, where every option has its own color. Once they add their customized version of the cart, we bundle images for chosen options into a final product image. This is what we want to display in Checkout cart page, and not the default product image. Let’s see the most crucial part of the solution I came up with. I have created a separate extension for this, so I suggest you do the same.
Step 1: Create di.xml file
Create di.xml file in app/code/[Name_Space]/[Your_Module]/etc/frontend
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<plugin name="Change_Product_Image_In_Checkout_Cart" type="[Name_Space]\[Your_Module]\Plugin\CheckoutCart\Image" sortOrder="1"/>
Step 2: Create Image.php file
Create Image.php file in app/code/[Name_Space]\[Your_Module]\Plugin\CheckoutCart
public function afterGetImage($item, $result)
$result->setImageUrl( YOUR_IMAGE_URL );
The 2 steps I mention above is the shortest process for you to Change Product Image in Checkout Cart in Magento 2. With this guide, you can manage the Product Image in Checkout Cart in Magento 2 easily. Every store has a Change Product Image in Checkout Cart in Magento 2 with many attributes.
Thank you for reading this post and see you in other posts from Magestore!
Ready to foster your knowledge
Is your site still a mess and Magento extensions are not enough to save your site? Save your site with Magento Web Development Services now