Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5553

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

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

Facebook Twitter Email Reddit Stumbleupon

Viewing all articles
Browse latest Browse all 5553

Trending Articles