Rohit Goel
Rohit Goel

Reputation: 3554

update product thumbnail ,small image and base image programatically Magento

need to update the product thumbnail , small image and base image programatically

for this i a using a below code

$collection1->addImageToMediaGallery($importDir,$mediaArray,false);

    //$collection1->setStoreId(0);
        $collection1->save();
if (isset($mediaGallery['images'])){
            //loop through the images
            foreach ($mediaGallery['images'] as $image){
            //set the first image as the base image
            Mage::getSingleton('catalog/product_action')->updateAttributes(array($collection1->getId()), array('image'=>$image['file'],'thumbnail'=>$image['file'],'small_image'=>$image['file']), 0);
            //stop
            break;
            }
            }

with this code a

image adding to the gallery

but i need to set the latest image to set as image and base image

.Please suggest how can i achieve this thanks

Upvotes: 2

Views: 3134

Answers (1)

Related Questions