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();   
1

Change this line

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

To

$product->addImageToMediaGallery($path, array('image','thumbnail'), false);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy