Hello, you can do the following:
$image =$imagePath."image.png"; $product->setMediaGallery(array('images'=>array (), 'values'=>array ())); if(is_file($image)) { $product->addImageToMediaGallery($image, array ('image', 'small_image', 'thumbnail'), false, false); }
To do this, you first need to install a media gallery, PS This is a necessary step.
then add all the images to the gallery using addImageToMediaGallery, where 'image' ref to 'base_image'
In the above example, we set image.png to base_image, small_image and a thumbnail in one call.
Hope this helps you.
Sunil verma
source share