Sunday, December 25, 2011

Adding images from third party server or external server to product in magneto programmatically


We can add images to product from 3ed party server programmatically in magneto

thing you will have images URL in array


  $image_url  =$images[$j]; //get external image url from csv
  $image_url  =str_replace("https://", "http://", $image_url); // repalce https tp http
  //echo $image_url;
  $image_type = substr(strrchr($image_url,"."),1); //find the image extension
  $filename   = $sku.$j.'.'.$image_type; //give a new name, you can modify as per your requirement
  $filepath   = Mage::getBaseDir('media') . DS . 'import'. DS . $filename; //path for temp storage folder: ./media/import/
  file_put_contents($filepath, file_get_contents(trim($image_url))); //store the image from external url to the temp storage folder
  //echo $filepath; exit;

  $mediaAttribute = array (
 $product->addImageToMediaGallery($filepath_to_image, $mediaAttribute, true, false);


No comments:

Post a Comment