3/10/2015 - 8:43 PM

Find attribute IDs for mass image import

Find attribute IDs for mass image import

SQL: where 85, 86, and 87 are attribute IDs

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;

Attribute IDs can be found by going to :
Catalog > Attributes > Manage attributes
and write down the attribute IDs

attribute_id attribute_code backend_model
106 image 
109 small_image
493 thumbnail

attribute ids are found on this table:

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.


require 'app/Mage.php';

$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());


I have a Magento store that has around 3,000 products. Almost all of these products have a single image attached to it.

For some reason, even though I set the small image and thumbnail image as the same as the base image in the import CSV file, only the base image is set for each product. This means that when you search for a product you get a placeholder - but once you go into the product page you get the correct image. This can be easily remedied by going into the product admin page and selecting the boxes for small image and thumbnail.

The problem is, with 3,000 images this would take quite a long time to do manually. I have found a SQL command that should make all base, small and thumbnail images map the the first image for each product. As I only have one image for each product this should be perfect.