I have to create a simple Magento 1.6.x import agent that suppose to create/update products and their images. Could someone advise me how to add product image without having
I did this in Magento 1.6.1. Just put your image URL paths in the first array and you are good to go.
Also look at Mage_Catalog_Model_Product to become familiar with addImageToMediaGallery() and other methods you'll undoubtedly need to be aware of in the future.
// Add three image sizes to media gallery
$mediaArray = array(
'thumbnail' => $putPathHere,
'small_image' => $putPathHere,
'image' => $putPathHere,
);
// Remove unset images, add image to gallery if exists
$importDir = Mage::getBaseDir('media') . DS . 'import/';
foreach($mediaArray as $imageType => $fileName) {
$filePath = $importDir.$fileName;
if ( file_exists($filePath) ) {
try {
$product->addImageToMediaGallery($filePath, $imageType, false);
} catch (Exception $e) {
echo $e->getMessage();
}
} else {
echo "Product does not have an image or the path is incorrect. Path was: {$filePath}
";
}
}