简体   繁体   中英

update product thumbnail ,small image and base image programatically Magento

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

for this ia 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM