Created
February 10, 2017 16:25
-
-
Save gelanivishal/de61b564bc5d85f82cc10377e7717ee4 to your computer and use it in GitHub Desktop.
Assign first media image as base image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'app/Mage.php'; | |
Mage::app(); | |
$productId = 4299; | |
//load the product | |
$product = Mage::getModel('catalog/product')->load($productId); | |
//get all images | |
$mediaGallery = $product->getMediaGallery(); | |
//if there are images | |
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($product->getId()), array('image'=>$image['file']), 0); | |
//stop | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment