Skip to main content
added 788 characters in body
Source Link
Nero Phung
  • 1.3k
  • 4
  • 12
  • 24

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) enter image description here

Use this command below:

 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; 

EDIT: If the query doesn't work, It means you have not had the small and thumbnail before, use this code:

use Magento\Catalog\Model\ProductFactory;

protected $_productFactory;

public function __construct(ProductFactory $productFactory){
     $this->_productFactory   = $productFactory;
}

//Change the image
$productCollection = $this->_productFactory->create()->getCollection();

foreach($productCollection as $product) {
    $imagePath = $product->getMediaGalleryImages()->getFirstItem()->getFile();
    if ($imagePath) {
       $this->_objectManager->get('Magento\Catalog\Model\Product\Action')->updateAttributes([0 => $product->getId()], array("thumbnail" => $imagePath,"small_image" => $imagePath), 0);
    }
}

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) enter image description here

Use this command below:

 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; 

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) enter image description here

Use this command below:

 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; 

EDIT: If the query doesn't work, It means you have not had the small and thumbnail before, use this code:

use Magento\Catalog\Model\ProductFactory;

protected $_productFactory;

public function __construct(ProductFactory $productFactory){
     $this->_productFactory   = $productFactory;
}

//Change the image
$productCollection = $this->_productFactory->create()->getCollection();

foreach($productCollection as $product) {
    $imagePath = $product->getMediaGalleryImages()->getFirstItem()->getFile();
    if ($imagePath) {
       $this->_objectManager->get('Magento\Catalog\Model\Product\Action')->updateAttributes([0 => $product->getId()], array("thumbnail" => $imagePath,"small_image" => $imagePath), 0);
    }
}
added 176 characters in body
Source Link
Nero Phung
  • 1.3k
  • 4
  • 12
  • 24

MaybeTake a look into talbe eav_attribute, you canwill find out your answer inthe Set the small & thumbnail image the same as the base(image,small_image,thumbnail) attribute. In magento 2.1.8, it take the id (87,88,89) enter image description here

Use this command below:

 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; 

Maybe you can find out your answer in Set the small & thumbnail image the same as the base

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) enter image description here

Use this command below:

 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; 
Source Link
Nero Phung
  • 1.3k
  • 4
  • 12
  • 24

Maybe you can find out your answer in Set the small & thumbnail image the same as the base