I am using below code to set the image as base,small and thumbnail, but it is not working.
$productRepository = $this->_objectManager->create('Magento\Catalog\Api\ProductRepositoryInterface');
$product = $productRepository->get($sku);
$product->addImageToMediaGallery($imagePath, array('image', 'small_image', 'thumbnail'), true, false);
Can anyone suggest, what is wrong with the code
Best Answer
As far as I know, Magento 2 has a test to set Base, Small and Thumbnail image dev/tests/integration/testsuite/Magento/Sitemap/_files/sitemap_products.php.
We can follow the logic of this and create your own. An simple example:
We can try to test my code with playground and here.