Thank you for the reply.
I already found the answer by myself and I will share it below.
foreach ($products as $product){
$smallImage = $product->getSmallImage();
$imagePath = '/catalog/product' . $product->getImage();
if( $smallImage == 'no_selection' ){
echo 'FIXING ' . $imagePath . "\r\n";
$product->addImageToMediaGallery( $imagePath, array( 'small_image' ), false, false );
$product->save();
}
}
But still, I'm curious to know what are the Boolean variables are here.
$product->addImageToMediaGallery( $imagePath, array( 'small_image' ), false, false );
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
Best Answer
Take a look into talbe
eav_attribute
, you will find out the (image,small_image,thumbnail) attribute. In magento 2.1.8, it take the id (87,88,89)Use this command below:
EDIT: If the query doesn't work, It means you have not had the small and thumbnail before, use this code: