I have imported 7000 products through an Oscommerce website everything is great except that the imported images are not selected as base image , small image and thumbnail image.

I need to inform you that every product have a single image which will act as base image , small image and thumbnail image.

I am not getting how to do that as it's not possible for me to go to every product and mark the image as base image , small image and thumbnail image.

I have created a script and trying to run it is not giving any error but still not solving the issue.


 require 'app/Mage.php';
 $prod_id = 7068 ;
 $_product = Mage::getModel('catalog/product')->load($prod_id);
 $prod_img_col = $_product->getMediaGalleryImages();

 foreach($prod_img_col as $gallery_img) {

  $_product->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'catalog' . DS . 'product'. $gallery_img['file'], array('image', 'thumbnail', 'small_image'), false, false); 



I hope anyone knows how to do this.

Thanks, Sarvagya


If you're comfortable with editing the database directly, I can point you in the right direction.

SELECT * FROM catalog_product_entity cpe
    LEFT JOIN catalog_product_entity_varchar cpev ON cpev.entity_id = cpe.entity_id
    LEFT JOIN eav_attribute ea ON ea.attribute_id = cpev.attribute_id
WHERE ea.attribute_code = 'image' OR
      ea.attribute_code = 'small_image' OR
      ea.attribute_code = 'thumbnail'

That'll get you all of your products and all of their image attributes. Take note of which attribute has your values. You may need to look at catalog_product_entity_varchar directly to get the attribute_id of the other two image attributes (one of image, small_image or thumbnail, probably the latter two).

So you could write a PHP script that directly inserts into catalog_product_entity_varchar, using the results from the select statement above.

| improve this answer | |
  • Hello andyjv, I tried the command it provides me the informations regarding the images but how should i insert the value my attributes for images are 85,86,87 . Thanks for your help – Sarvagya Aug 1 '13 at 10:23
  • You could write a PHP script, but I'm sure there are other ways. In PHP you'd get all the results into an array, grab the value of whichever attribute actually has the image, and then update catalog_product_entity_varchar. Thats really kind of a whole other how-to though. – andyjv Aug 8 '13 at 18:48

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.