Showing posts with label Add multiple product images Magento. Show all posts
Showing posts with label Add multiple product images Magento. Show all posts

Wednesday 30 July 2014

Add multiple product images Magento

$newProduct = Mage::getModel(''catalog/product'')->load(productid)
$artworkhid = "image1.jpg,image2.jpg,image3.jpg";
$newProduct->setMediaGallery (array('images'=>array (), 'values'=>array ()));
$imgs = explode(',',$artworkhid);
 $i = 1;
foreach($imgs as $ims){
$previewImage = '/image_path/'.$ims;
     if(file_exists($previewImage)){
 if($i==1){
            $newProduct->addImageToMediaGallery ($previewImage, array ('thumbnail','small_image','image'), false, false);
      }else{
            $newProduct->addImageToMediaGallery ($previewImage, null, false, false);
  }
 $i++;
 }
}