Question

I want to change the settings of my imported product images. Now it looks like this:

           Base image   Small image   Thumbnail   highresimages   highresimages2   highresimages3   highresimages4
No image   x            x             x           x               x                x
image1.jpg
image2.jpg
image3.jpg

I want it to look like this:

           Base image   Small image   Thumbnail   highresimages   highresimages2   highresimages3   highresimages4
No image
image1.jpg x                                      x
image2.jpg                                                        x
image3.jpg                                                                         x
image4.jpg                                                                                           x

I want to do it as a bulk operation. All products has the same structure for the image. The first image is always first, second image is always second etc.

Was it helpful?

Solution

I'm not sure about what are you trying to achieve exactly but here are some pieces of code that you can put together.
Here is how you can get the product images sorted by their position.

$productId = 55;
$product = Mage::getModel('catalog/product')->load($productId);
$images = $product->getMediaGalleryImages();
foreach ($images as $image) {
    $imageName = $image->getFile(); //name of the image
    //do something with $imageName;
}

Now here is how you can update an attribute for a product

Mage::getSingleton('catalog/product_action')->updateAttributes(
    array($productId), //product ids to update
    array('image', $imageName), //attributes to update. In your case 'image', 'small_image', ...
    0 //store id - default config = 0
); 

You can use the 2 pieces of code above to identify the images you want to set as 'image', 'small_image' and others based on the position in the image list, then update the specific product attributes.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top