I have imported a number of products at once, but the problem is: the Base Image, Small Image, Thumbnail are all set to the same image.
On the catalog page, I'm trying to change the image shown when you hover over a product. I believe, to do this, the small image and thumbnail image would need to be set to different images for the same product.
How can I achieve this?
I found below query, but I do not understand how to modify it to meet my requirement.
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 (70, 71, 72)
AND
 mgv.position = 1;
Please, can you help me find the right modifications.
- 
 anyone please..?Joey River– Joey River2013年11月26日 09:30:24 +00:00Commented Nov 26, 2013 at 9:30
 - 
 3Golden rule of Magento: Don't touch Magento DB directly. If you want I can give you solution how programmatically change media imagesmageUz– mageUz2013年11月26日 11:37:56 +00:00Commented Nov 26, 2013 at 11:37
 - 
 @mageUz PLease provide me a solution for my above problem? I need to change the product image on hover on the catalog pageJoey River– Joey River2013年11月26日 12:39:00 +00:00Commented Nov 26, 2013 at 12:39
 - 
 For some reason this is not working for me even if I checked the attribute_id:s from database and made corrections. It only set the images for 3 products. All the rest of the hundreds of products remain unchanged.Webninja– Webninja2017年04月12日 12:37:26 +00:00Commented Apr 12, 2017 at 12:37
 
2 Answers 2
Here is given programmatically adding media images to product, you can adjust this code to your own importing script:
 $mediaGalleryAttribute = Mage::getModel('catalog/resource_eav_attribute')
 ->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'media_gallery');
 $mediaGallery = $mediaGalleryAttribute->getBackend();
 $attrCode = $mediaGalleryAttribute->getAttributeCode();
 $product = Mage::getModel('catalog/product')->load($productId);
 $mediaGalleryData = $product->getData($attrCode);
 /**
 * If you want to remove old images use this code
 */
 if (isset($mediaGalleryData['images'])) {
 foreach ($mediaGalleryData['images'] as &$image) {
 $image['removed'] = 1;
 }
 $product->setData($attrCode, $mediaGalleryData);
 }
 /**
 * Here is real image file path
 */
 $thumbnailFile = 'real/path/to/thumbnail/file.jpg';
 $imageFile = 'real/path/to/image/file.jpg';
 try {
 //Set thumbnail
 $imageFileUri = $mediaGallery->addImage($product, $thumbnailFile, null, false, false);
 $mediaGallery->setMediaAttribute($product, 'thumbnail', $imageFileUri);
 //Set image (or base image, small image whatever you want
 $imageFileUri = $mediaGallery->addImage($product, $imageFile, null, false, false);
 $mediaGallery->setMediaAttribute($product, 'image', $imageFileUri);
 $product->save();
 } catch (Exception $e) {
 Mage::logException($e);
 }
 - 
 Perfect, did exactly what I need to do. Thanks a lot:)Chiragit007– Chiragit0072014年11月19日 09:06:17 +00:00Commented Nov 19, 2014 at 9:06
 
May my solution works for you:
I would introduce an attribute (image) called for example "hover_image"
Use this function from Marius to set for example every second media-image as your hover-image https://stackoverflow.com/questions/19153891/magento-how-to-programatically-set-the-base-image-to-the-first-image-in-the-lis Take care - you have to modify it to use the second image.