Magento – How to set small image as default to product after import many products from CSV? – magento 1.8

imageimportmagento-1.8product

I just import many products form CSV (about 9 000). On back-end i see imported product images but they aren't set as base, small and thumbnail image – default set is "no image"

Do you know how can I change it for all of my products? "Fixes" for Magento 1.7 dosen't work – I'm using Magento 1.8 community
Regards

Best Answer

place the below code in a file which is in root directory and execute the code. Please take the backup of your database before running the code.

<?php 
require_once('app/Mage.php');
umask(0);
Mage::app();

$collection = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect(array('image', 'thumbnail', 'small_image'))
        ->addAttributeToFilter('thumbnail',array('neq'=>'no_selection'));

foreach($collection as $product){
    $path = "Path_of_image_here";
    if(is_file($path)){
        try {
            $product->setSmallImage($path)
            //->setThumbnail($path)
            //->setImage($path)
            ->save();
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    }
}