Magento 2 – Set Base Image as Small Image

magento2product-images

I have nearly 40k products and all images have been set to small only. If I go into the backend and then set each image one by one to the base, it will take me forever. Is there any way to do it via the database?

Best Answer

If you want to do by MySQL way follow below way

First, run below query to know the query is actually working and you will get a list of images

select  ev.value, mg.value from catalog_product_entity_media_gallery AS mg,
catalog_product_entity_media_gallery_value AS mgv,
catalog_product_entity_varchar AS ev
WHERE  mg.value_id = mgv.value_id
AND mgv.entity_id = ev.entity_id
AND ev.attribute_id IN (87, 88, 89)
AND mgv.position = 1; 

After that run below query to update small image path with a thumbnail image

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 mgv.entity_id = ev.entity_id
AND ev.attribute_id IN (87, 88, 89)
AND mgv.position = 1; 

You should run first in test ENV, after making sure you can run on other ENV.

Hope It will solve your issue

Related Topic