We can add images to product from 3ed party server programmatically in magneto
thing you will have images URL in array
$product=Mage::getModel('catalog/product')->load($productId);
$images=array('http://p.imgci.com/db/PICTURES/CMS/140500/140554.icon.jpg','http://p.imgci.com/db/PICTURES/CMS/140500/140553.icon.jpg');
for($j=0;$j<count($images);$j++){
$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;
$filepath_to_image=$filepath;
$mediaAttribute = array (
'thumbnail',
'small_image',
'image'
);
$product->addImageToMediaGallery($filepath_to_image, $mediaAttribute, true, false);
}
No comments:
Post a Comment