Make all store images the base, small and thumbnail images in Magento?

i know this is an old post, however in case anyone has the same issue then the problem was with the ev.attribute_id. Updated code below:

UPDATE 
    catalog_product_entity_media_gallery AS mg,
    catalog_product_entity_media_gallery_value AS mgv,
    catalog_product_entity_varchar AS ev
SET 
    ev.value = mg.value
WHERE  
    mg.value_id = mgv.value_id
      AND mg.entity_id = ev.entity_id
      AND ev.attribute_id IN (74, 75, 76)
      AND mgv.position = 1

Thanks.


Just as a warning to anyone (like myself!) who wants to try out this script. I ran this without thinking and it changed all the product names!

  1. Go into your attributes panel, find the image/small image/thumbnail attributes.
  2. Note down the ids (mine in this case were 85,86 and 87)
  3. Change the query to reflect those id's.

So my query looks like:

UPDATE catalog_product_entity_media_gallery AS mg,
       catalog_product_entity_media_gallery_value AS mgv,
       catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE  mg.value_id = mgv.value_id
AND mg.entity_id = ev.entity_id
AND ev.attribute_id IN (85,86,87)
AND mgv.position = 1;

After making a change like that to the database, even if successful, you would need to rebuild the images cache in Cache Management.

You might be able to do it with a script like this and not worry about caching or indexing.

<?php

require 'app/Mage.php';
Mage::app();

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($products as $product) {
    if (!$product->hasImage()) continue;
    if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage());
    if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage());
    $product->save();
}

?>Done!

Save this in your Magento directory and access it by typing the URL into your browser's address bar. I haven't tested this script yet.


I used stereo_world's method on magento 1.7.0.2 and it worked great. (I can't upvote his answer because I'm new to stackoverflow)

I don't know where he is seeing the attribute id in the attribute panel, because I don't see a numerical id there at all. I found the ids (85,86,87) by opening up phpMyAdmin and looking in eav_attribute table.

As clockworkgeek pointed out - reindex/cache flush are necessary.