I am using custom script to import products in magento. product thumbnail or small image set using the code but the base image not set. I am using the below code :
$mediaArray = array(
'image' => $data['image'],
'thumbnail' => $data['image'],
'small_image' => $data['image']
);
// Remove unset images, add image to gallery if exists
$importDir = Mage::getBaseDir('media') . DS . 'import/product/';
//echo $importDir;exit;
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}<br/>";
}
}
What is the missing in the code. Can anyone suggest the solution ?