Back to Top

Magento Set default image from product images

Updated 16 July 2021

Get filename from here
<?php
$_product = Mage::getModel('catalog/product')->load($ProductId)->getMediaGalleryImages();
foreach ($_product as $value) {
     if($value->getFile() == $yourfilename){
        $newimage = $value->getFile(); //get your file you want to set
     }
}
?>
Now set your default image
<?php
$objprod=Mage::getModel('catalog/product')->load($ProductId);
$objprod->setSmallImage($newimage); //newimage is filename you want to set
$objprod->setImage($newimage);
$objprod->setThumbnail($newimage);
$objprod->save();
?>

Searching for an experienced
Magento Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home