Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Magento 1.9.2.1: How to remove product images programtically?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 949
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: