Magento: Remove Product Images in Magento through programming:
There is a case when we need to create our own extensions or we have to customize the module, then in that case we need to write custom code for deleting images. Following code will delete the images from the product.
First step is to define $product:
$product = Mage::getModel('catalog/product')->load($id);
We are going to call product_attribute_media_api
to get images from the product.
if ($product->getId()){
$mediaApi = Mage::getModel("catalog/product_attribute_media_api");
$items = $mediaApi->items($product->getId());
foreach($items as $item)
$mediaApi->remove($product->getId(), $item['file']);
}
All done!. Product images will be deleted.
Thanks for reading the blog.
0 Comment(s)