0

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

1
  • It will be helpful if you place the code of your importer that did the image attachment to products. Are you using dataflow?, Magmi?, custom shell?, api? etc.
    – ProxiBlue
    Feb 2, 2014 at 12:20

1 Answer 1

1

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();
        }
    }
}
4
  • Does Path_of_image_here need to be updated to where the images are stored, like for example, /media/import?
    – zigojacko
    Feb 26, 2014 at 16:42
  • correct, in your case $path = Mage::getBaseUrl('media').DS.'import'.DS.'file_name'; Feb 27, 2014 at 5:58
  • Is the filename needed? Because in the event of a 9000 product import, you're not going to update this script 9000 times for each product. Or does your suggestion above programmatically get the filename of the images in the media/import directory? Thanks.
    – zigojacko
    Feb 27, 2014 at 8:53
  • to add image you will require the file name, let say import directory has all the images and the images filename are based on the SKU, for product with SKU xyz will have image filename will be xyz.jpg, create some logic similar to that. i had imported 57k product with that logic, good luck Feb 27, 2014 at 9:45

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.