1

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?

2
  • You want to set small image which is already set in base image? Nov 23, 2018 at 12:23
  • I want to set a base image which is already set in the small image.
    – sky
    Nov 23, 2018 at 12:52

3 Answers 3

3

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

0
0

You can use the CSV. Please add two more column 'base_image' and 'thumbnail_image' in the csv file and re import all the products.Then after reindex the process.

1
  • Image Url does not generate When I import via CSV file.I have done this
    – sky
    Nov 23, 2018 at 12:13
0

It does possible with the csv import too.

  1. Get the attribute ids.

Go to admin > stores > attributes > product and search image attributes there. Lets say your image attribute id is 79 , small image is 80 and thumbnail id is 81.

  1. In this case, small image attribute id is 80 so run this query.

SELECT attribute_id,store_id,entity_id,value FROM catalog_product_entity_varchar WHERE attribute_id=80

  1. Export the query result and change the id from 80 to 79 ( 79 is the attribute id of image).

  2. Import the updated csv in database.

  3. Repeat the same step for thumbnail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.