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) {
unset($existingMediaGalleryEntries[$key]);
}
$product->setMediaGalleryEntries($existingMediaGalleryEntries);
$productRepository->save($product);
-
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– Rahul2017年12月28日 06:36:50 +00:00Commented Dec 28, 2017 at 6:36
-
magento 2.2.6 this doesnt work.TTech IT Solutions– TTech IT Solutions2018年09月20日 14:48:32 +00:00Commented Sep 20, 2018 at 14:48
Explore related questions
See similar questions with these tags.