I have to set Base Image,Thumbnail and small image after removing all image programmatically.

I am trying this code to remove all image from product

$productRepository = $this->_objectManager->create('Magento\Catalog\Api\ProductRepositoryInterface');
$product = $this->_objectManager->create('Magento\Catalog\Model\Product')->load($proPaint->getProductId());
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
foreach ($existingMediaGalleryEntries as $key => $entry) {

and this code for add image as base,small and thumbnail

$product->addImageToMediaGallery($imagePath, array('image','small_image','thumbnail','swatch_image'), false, false);

but it is not save as base,small or thumbnail

How can i set base image small and thumbnail after removing all image

  • Just for clarification, are you trying to set "custom placeholder images" to all your products? – Max Nov 24 '16 at 13:55
  • Yes i am changing my product images when my custom attribute change – Newbie Nov 25 '16 at 4:39
  • Aren't there already placeholder images by default in magento? Why dont just override them in the files? – Max Nov 25 '16 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.