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
$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->addImageToMediaGallery($loadpro, array ('image','small_image','thumbnail'), true, false);

Start your headless eCommerce
Find out More
. . .

Leave a Comment

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


  • 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