0

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

1 Answer 1

1

Change this line

$product->addImageToMediaGallery($path, $imageType, false);

To

$product->addImageToMediaGallery($path, array('image','thumbnail'), false);
answered May 29, 2017 at 7:37
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.