We are uploading same image 2 times to Programatically created product & we are selecting one image as Thumbinal & another one as Base Image in backend.
Instead we want to create single image and we want to assign that image to both Base & Thumbinal.
if ($doSave) {
$images = array(
'thumbnail' => 'image.png', // cart page
'image' => 'image.png' // my design & product view page
);
//print_r(array_merge($images));
$imag_data = Mage::getSingleton('core/session')->getProductImage();
$newImagePath = $imag_data;
foreach ($images as $imageType => $imageFileName) {
$path = '';
if ($newImagePath != "") {
$dir = Mage::getBaseDir('media') . DS . 'custom_product_preview/quote/';
$path = $dir . $newImagePath;
} else {
$dir = Mage::getBaseDir('media') . DS . 'example/amasty/';
$path = $dir . $imageFileName;
}
if (file_exists($path)) {
try {
$product->addImageToMediaGallery($path, $imageType, false);
} catch (Exception $e) {
echo $e->getMessage();
}
} else {
echo "Can not find image by path: `{$path}`<br/>";
}
}
}
$product->save();
asked May 29, 2017 at 7:31
user52996
1 Answer 1
Change this line
$product->addImageToMediaGallery($path, $imageType, false);
To
$product->addImageToMediaGallery($path, array('image','thumbnail'), false);
answered May 29, 2017 at 7:37
Jaimin Sutariya
11.2k5 gold badges38 silver badges72 bronze badges
default