cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with image order

Problem with image order

Hi!
I uploaded 16000 products with SOAP api and I have a problem with images.
The images are not shown in the fronted because they are not set as default. I tried to make them default but unfortunately all of them are set in order 0

image.jpg

 

How Can i set the all to 1 or set them as default?

2 REPLIES 2

Re: Problem with image order

Hi @Alfapromo,



You have to loop through all the products and set the first image as the image to be displayed for the product.


Here is a sample code:

 

$productId = 1;
//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;
    }
}

Best regards.

Gabriel

Welcome to the Magento Forums. Remember to introduce yourself and read the Magento Forums Guidelines.

Re: Problem with image order

Hello and thanks for the response.
In which file I will add this code?