I am having image url as
http://www.yakshinfotech.com/wp-content/uploads/2016/03/Laptop-Repair.jpg
which I need to set for my products. I have tried by setting product image url:
$productId = 1;
$product = $this->_product->load(1);
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
foreach ($existingMediaGalleryEntries as $key => $entry) {
unset($existingMediaGalleryEntries[$key]);
}
$product->setMediaGalleryEntries($existingMediaGalleryEntries);
$this->_productRepository->save($product);
public function saveImg()
{
$imageUrl = 'http://s6.favim.com/610/150425/adorable-animal-cat-cute-Favim.com-2680526.jpg';
$product->addImageToMediaGallery($imageUrl, array('image','small_image', 'thumbnail'), false, false);
$product->save();
}
But this code displays error as image not found.
What I need to do to set product image as url?
Best Answer
Pleaes try with following code