I have that in my backoffice :
This solution does not work for me :
if($key == 1){
$prod->addImageToMediaGallery($imgPath, array('image', 'small_image','thumbnail'), false, false);
}else{
$prod->addImageToMediaGallery($imgPath, null, false, false);
}
$prod->save();
How can I do ?
Thank you
EDIT : my new implementation, but it is not working :
if(!$productFactory) $productFactory=$objectManager->create('Magento\Catalog\Model\ProductFactory');
$product=$productFactory->create()->load($id_product_for_image);
$product->addImageToMediaGallery($tmpName, $is_cover ? array('image', 'thumbnail', 'small_image') : array(), false, false);
I think it is connected to this problem : https://github.com/magento/magento2/issues/34658