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
-
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– ProxiBlue2014年02月02日 12:20:08 +00:00Commented Feb 2, 2014 at 12:20
1 Answer 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();
}
}
}
-
Does
Path_of_image_hereneed to be updated to where the images are stored, like for example,/media/import?zigojacko– zigojacko2014年02月26日 16:42:37 +00:00Commented Feb 26, 2014 at 16:42 -
correct, in your case
$path = Mage::getBaseUrl('media').DS.'import'.DS.'file_name';Deepak Mallah– Deepak Mallah2014年02月27日 05:58:20 +00:00Commented 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/importdirectory? Thanks.zigojacko– zigojacko2014年02月27日 08:53:11 +00:00Commented 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 luckDeepak Mallah– Deepak Mallah2014年02月27日 09:45:14 +00:00Commented Feb 27, 2014 at 9:45