Showing posts with label remove product image magento. Show all posts
Showing posts with label remove product image magento. Show all posts

Thursday 24 October 2013

Remove product image magento

$_product = Mage::getModel('catalog/product')->setStoreId($storeId)->load(2);
$removes[0] = a/b/aaa.png;
$removes[1] = a/c/bbb.png;
if(count($remove)>0){
 $attributes = $_product->getTypeInstance ()->getSetAttributes ();
 $gallery = $attributes ['media_gallery'];
$galleryData = $_product->getMediaGallery();
foreach($removes as $remove) {
foreach($galleryData['images'] as $image) {
if($remove==$image['file']){
$gallery->getBackend ()->removeImage( $_product, $image ['file'] );
}
}
}
$_product->save ();
}