Back to Top

Remove Existing Images And Add New Image To Magento Product ( Programmatically )

Updated 27 February 2024

$productid=10; // Product id of that product which image you want to update
//for remove existing Images
$loadpro=Mage::getModel('catalog/product')->load($productid);
$mediaApi = Mage::getModel("catalog/product_attribute_media_api");
$mediaApiItems = $mediaApi->items($loadpro->getId());

foreach($mediaApiItems as $item) {
	$datatemp=$mediaApi->remove($loadpro->getId(), $item['file']);
}
$loadpro->save(); //before adding need to save product

//for add new images
$loadpro=Mage::getModel('catalog/product')->load($loadpro->getId());
$loadpro->addImageToMediaGallery($loadpro, array ('image','small_image','thumbnail'), true, false);

Start your headless eCommerce
now.
Find out More
. . .

Leave a Comment

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


1 comments

  • Muhammad Azeem
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home