Reading list Switch to dark mode

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

    Updated 26 June 2013

    $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
    Read More
    . . .
    Discuss on Helpdesk

    Leave a Comment

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


  • Muhammad Azeem
    Thanks. Work for me.
  • Back to Top

    Message Sent!

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

    Back to Home