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

Marius
199k55 gold badges431 silver badges837 bronze badges
asked Feb 2, 2014 at 3:28
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. Commented 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();
 }
 }
}
answered Feb 3, 2014 at 7:38
4
  • Does Path_of_image_here need to be updated to where the images are stored, like for example, /media/import? Commented Feb 26, 2014 at 16:42
  • correct, in your case $path = Mage::getBaseUrl('media').DS.'import'.DS.'file_name'; Commented 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. Commented 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 Commented Feb 27, 2014 at 9:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.