Magento Version: 2.1.0

We have added the wrong image for some of the products when importing through Magento CSV import. we want to remove the images from those products and add new images or replace the images for the same.

We are trying to import using the normal Magento import functionality by selecting replace option. If we select to delete it will delete the complete product. Same issue we will get if we want to remove any multiselect option and add new for any particular product.

EX: if SKU is xyz456 - we added 3 images before and we want to remove these and add new 3 or 4 images or replace the images for the same SKU then it is not working. It will add new images also and it will keep old images also.

Same way if we have selected multiselect options for attribute lets say material: wood, iron and we want to change it to steel, copper then it is not allowing. It will add Material: wood, iron, steel, copper

Can anyone please explain how we can update these. Magento has not provided clear documentation on product import and export functionality.

1 Answer 1


Use following code to remove image from product in Magento2.

// Instance of object manager

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$productId = Your_Product_Id; // Id of product

$product = $objectManager->create('Magento\Catalog\Model\Product')->load($productId);
$productRepository = $objectManager->create('Magento\Catalog\Api\ProductRepositoryInterface');
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
foreach ($existingMediaGalleryEntries as $key => $entry) {
  • We want to remove or replace the image using magento csv import how we can do this..? Can you please explain....Do we need to write any code for this..? We want to do all product updates, addition, remove etc.... using csv import.
    – Rahul
    Commented Dec 28, 2017 at 6:36
  • magento 2.2.6 this doesnt work. Commented Sep 20, 2018 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.