You might have noticed the magento import script is broken: it has some problems uploading images to products, and the stock updating is wrong as well. You might have ended up doing the same thing we did: Importing the products using this script, and then importing images and stock using the old DataFlow module, as that is what is usually recommended. And, the script still has some problems, such as not allowing to use the same image multiple products. Even Magento Go uses it’s own image uploading script!
The problem this has, is that it is annoying having to update things twice, and that the old dataflow is too slow.
So, After debugging the code for a while, I found these simple fixes which will allow you to have a fully functional ImportExport module:
On the class Mage_ImportExport_Model_Import_Entity_Product (app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php)
Add the lines with a +, and remove those with a -:
On line 1133 and 1143:
$strftimeFormat = Varien_Date::convertZendToStrftime(Varien_Date::DATE
$productLimit = null;
$productsQty = null;
+ $uploadedGalleryFiles = array();
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
$entityRowsIn = array();
$entityRowsUp = array();
$tierPrices = array();
$groupPrices = array();
$mediaGallery = array();
- $uploadedGalleryFiles = array();
$previousType = null;
$previousAttributeSet = null;
On line 1226:
if (!array_key_exists($rowData[$imageCol], $uploadedGal
$uploadedGalleryFiles[$rowData[$imageCol]] = $this-
}
+ $mediaGallery[$rowSku][$rowData[$imageCol]] = array(
+ 'attribute_id' => $resource->getAttribute("med
+ 'label' => $rowData[$imageCol."_label"]
+ 'position' => 0,
+ 'disabled' => 0,
+ 'value' => $uploadedGalleryFiles[$rowDa
+ );
$rowData[$imageCol] = $uploadedGalleryFiles[$rowData[$i
}
}
On line 1615:
if (self::SCOPE_DEFAULT != $this->getRowScope($rowData)) {
continue;
}
+ $row=array();
$row['product_id'] = $this->_newSku[$rowData[self::COL_SKU]]['e
$row['stock_id'] = 1;
Or you can just download the Product.php.diff file and git apply it, or patch -p0 it.
UPDATE
After some testing done by some readers, we realized that the CSV should include a “media_gallery” column (with the path of the image), a “_media_is_disabled” column with a value of “0”, and “_media_attribute_id” set to the id of the “media_gallery” attribute in your database (in the eav_attribute table).
Tnx.
It helped, now the import works (images in /media/import directory).
However, images are not visible in admin!!!
Tnx. It works!
Still, no images are visible in the backend (catalog)!
Hi Dama,
the problem the script had, was that it was not creating an Media Gallery for the product. It should be now, as that is part of what the patch does. Are the images showing in the frontend then? If that’s so, there could still be a problem when generating the Media Gallery. Which version of Magento are you using?
Images are showing in the frontend in both catalog and product page, but in admin (editing product) no image is visible.. It appears as there are no images at all!
Latest Magento, ver 1.7.0.2.
Thank you!!
after 3 days this was finally the only thing that worked! (Magento 1.7 with upload of catalog from 1.5)
However – it has only imported one picture for each product, where there was alternative images these have not imported, but heck, its certainly a good start!!
Any ideas how to get the other pics?
Hi, Thanks for the advice but I still can’t get the import to work on 1.7.0.2.
I’m getting ‘Image does not exist’ error on import even if I’m not trying to import images. Everything was working fine on 1.7.0.1 version but have no idea how to get this working.
Import works fine if the product already exists, just wont create new products.
I only tried this with Magento Enterprise, I will try it out with the latest version of Magento Community as soon as I can, sorry if this patch didn’t work for you.
Hi,
I tried this with a community edition – I think ver. 1.6
The only difference is that there, the last bit of your code
if (self::SCOPE_DEFAULT != $this->getRowScope($rowData)) {continue;
}
+ $row=array();
$row['product_id'] = $this->_newSku[$rowData[self::COL_SKU]]['e
$row['stock_id'] = 1;
is different. It shows
if (self::SCOPE_DEFAULT != $this->getRowScope($rowData)) {continue;
}
$row = array_merge(
$defaultStockData,
array_intersect_key($rowData, $defaultStockData)
);
$row['product_id'] = $this->_newSku[$rowData[self::COL_SKU]]['entity_id'];
$row['stock_id'] = 1;
Do you know what I would need to change, if anything, in this particular case?
Thank you
If that’s what the code says, then probably nothing. In 1.7, the $row array was not correctly emptied before each iteration. Anyway, that part of the code is only there to fix the problem with stock qtys, and not the problems with images.
Just another comment – the code you provide on this page is cut off. Full version can be found in the file you attached “Product.php.diff”
Just thought I’d point that out.
Ok, I just tried it out in Magento 1.7, and I noticed something in the import CSV: I do have a media_gallery
column with the exact same files as the images column, I guess that is why it is adding them to the media gallery in the admin. If anyone tries that out, and it works, I will update the post.
Not sure if this applies to your situation, but I have just installed 1.7.0.2 and tried to import a CSV with product with multiple images which I had exported from a previous 1.6.x installation. I was tearing my hair out as it was only showing one image on the front end, and no images at all on the backend. To resolve this I created a dummy product in the new install, added multiple images, exported the products out, and looked in the CSV file for the _media_attribute_id column. The number in here was 88 for the new install, but 82 for the export from the old install, so I simply updated the number, reimported the CSV from the old install again, and voila, it worked perfectly.
Could you please post a sample working csv import file because when I run this it places the value for gallery and media_gallery into the attributes but it does not import the actual images into the magento image structure. I’m using 1.7.0.2
Thank’s for helping community Alex!
I placed the code into the right place – and it worked properly. This should totally be included in magento dataflow profiles… I don’t get why it isn’t. Then I wanted to import about 300 bundle and simple products with data flow profiles and had lots of troubles. Sometimes I could import 100s, sometimes 25, sometimes 0. This was the last straw. Not long ago I became active user of desktop application called Store Manager which is paid but which can manage all types of products. And finally I got rid of the errors!
Thanks for this information-it is very valuable. Each time I import products to my store, there some issue happen. I have also stumbled upon file2cart data import service, but didn’t tried it yet.
Because it takes so much time to locate the error, and then to solve it, that I am ready to pay someone to do this work for me.
Alex, thanks for your great post.
I followed carefully every step of your instructions, but when I got to the point of importing the CSV file, “Check Data” button from System>Import/Export>Import shows the following Validation Results: ‘Column names: “_media_is_disabled”, “_media_attribute_id” are invalid’.
Any ideas of what have I missed?
Thanks again!
BTW, I’m using Magento CE 1.7.0.2.
Hi Carl,
Try leaving them out and importing like that, that is how we are using it internally and it works fine.
Thanks, Alex, I did it and it worked for one image. Now I’m having trouble importing multiple images to the gallery. I tried with comma separated image paths, as some sites refer, and single image path value per row as others do it. I tried entering these values in “gallery” or/and “media_gallery” fields in the CSV. Have you managed to do so?
Thanks again for your help.
Yes Carl, you need to add a row just below the one you had, with only that field set. That will add the second value to that product (add as many rows as the number of images you need).
Hi Alex,
Great job posting this to the community. I am sure this has helped a lot of people.
I came across your website trying to find a solution to a problem of mine where after importing a csv of products through System->Import/Export->Import everything was working great except from the fact that for all products the “No Image” was set to default as selected and I had to go to each product and check again the radio buttons for setting the Base Image, Thumbnail etc.
I gave a shot to your suggestion on this page and it seems that partially everything is working now. The first product image is selected and not the “No Image” but for some reason an additional empty image is added on top. Basically in admin when I hover over this image in admin no image appears.
For example I import one product with one image and the result when I go to the admin product page is that in the image tab contain two images. The actual one and another empty one.
Any suggestions would be welcome.
Update: Last Import i did added the image with an additiona empty image making that one selected for Base Image, Thumbanil etc.