What I've done:

  • I've imported all my products once (without any problems regarding the images)
  • Deleted all of them and then deleted all files under media/catalog/products
  • imported all my products again
    • Now it creates two image entries in my product while only the first exists
      • 1234.jpg (only this file exists)
      • 1234_1.jpg (selected as default)

So i assume there is an cache, db entry, something which remembers the file which was there at some point.

Line which triggers the image import: $this->product->addImageToMediaGallery($this->filepath, array('image', 'small_image', 'thumbnail'), true, false);

  • You deleted all files in media/products or in media/catalog/product ? – Prateek Sep 29 '15 at 7:00
  • My fault deleted catalog/product of course – Marvin Oßwald Sep 29 '15 at 7:02
  • If you have followed all the above steps in same order, check in admin configuration, if media folder is mapped somewhere else. – Prateek Sep 29 '15 at 9:15

Take a look at this answer - addImageToMediaGallery and getMediaGalleryImages
You might be saving the product multiple times, after each addImageToMediaGallery call. In this case, duplicate image paths (the ones with '_1' appended) will be created and added to the product, without the files actually being there. Moving product->save outside of any loop should help avoid this.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.