Magento – How to select the images as base image thumbnail image in bulk

magento-1magento-1.7magento-community

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.

<?php

 require 'app/Mage.php';
 Mage::app();
 $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

Best Answer

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'
ORDER BY sku;

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.

Related Topic