i tried to import my products now and i ran into a bug with specialchars…
magento is just cutting of the values from the first special char - in the name, the descriptions and the attributes… (well they are added to the database the same way, so its “correct” that it happens to all attributes)
Maybe someone has an idea to “reformat” the values, so they are added to the DB correct…
But with the 1.0 release, there is a new easy method to import picture corresponding to a product; I’ll try to do it this way soon…
Thanks for your effort, Brikou Carré - and superb work!
Make any progress on this new method to import pictures?
senders - 01 April 2008 05:43 AM
Hi Brikou Carré,
Do you also know, how to import a manufacturer by the same way?
Sebastian,
I haven’t confirmed, but I think you should be able to import manufacturer the same way, providing you’ve already configured all of the necessary manufacturers in the attributes section. Have you done this?
I bulk-imported manufacturer attributes using phpMyAdmin into eav_attribute_option, and eav_attribute_option_value using two CSV files. I think those are the only two tables that need to be updated with manufacturers. It seemed to work fairly well, and the attributes were valid for a dataflow import.
I’ve done some sleuthing of my own - I can hold my own with PHP, but I’m not one of those superstar programmers. You know the sort. Anyway, I have it working so images are added “the easy way”, which is presumably the function that Brikou Carré mentioned earlier.
The function is addImageToMediaGallery.
/** * Add image to media gallery * * @param string $file file path of image in file system * @param string|array $mediaAttribute code of attribute with type 'media_image', * leave blank if image should be only in gallery * @param boolean $move if true, it will move source file * @param boolean $exclude mark image as disabled in product page view */
The following code
$file = 'product_image.jpg'; //specify path if necessary $product->addImageToMediaGallery($file,null,false,false);
Though I’ve only solved part of the problem. I’m still trying to figure out how to set the image’s label, base, small, thumb, and sort parameters. I just wanted to post this in the interim, hoping a solution would be obvious to someone else. Meanwhile, I’m going to continue to mess around with it.
Many thanks to Brikou Carré and everyone else for collaborating on this and getting us to this point.
Okay, the position value auto-increments based on order-of-import (if multiples), so that’s no problem. The label value doesn’t seem to be modified by the addImageToMediaGallery function - still working on that. However, I did manage to figure out how to set visibility.
where the array “$visibility” contains 0-3 values, thumbnail, small_image, and/or image, depending on where you want the product image to appear. You can also forgo the variable and embed the array directly into the function like this
I’m striking out on setting the label value programmatically. Someone else’s turn.
EDIT: This is what my version of the code looks like, in the end. Now I just have to tailor it for a dynamic import to move products from the old e-commerce site to Magento.
$product = Mage::getModel('catalog/product'); $product->importFromTextArray($line); $product->addImageToMediaGallery($file1,$visibility,false,false); $product->setWebsiteIds(array(1)); // store id $product->save();
Some observations ....the way Magento updates stock has changed in Ver.1.0. Now stock is passed to product and saved through the product itself instead of $stockItem->save().
And on the images
http://www.magentocommerce.com/boards/viewthread/5120
If you would like to “see” what a product is made of, you can print the content of this product… This can be helpfull to get all the parameters composing this product.
<?php define('MAGENTO', realpath(dirname(__FILE__) . '/../../magento')); // adjust this to your relative magento path ini_set('memory_limit', '32M');
require_once MAGENTO . '/app/Mage.php';
Mage::app();
$id = 28; // the id of the product which is written in the product backend list
I put the above import script in a loop, and for some reason, the loop resets after iterating through roughly 40 records. Its not consistent, though. Could be a few more or a few less. So basically, I import 40 products, and then the script starts over. It does this 10 times before the browser calls it quits.
Its 2:00 AM. Anyone have any thoughts?
while($row = mysql_fetch_array($result)) { ...and so on... }
I’ve tried to echo the results without writing, and it goes to the end of the loop just fine (approx 3000 records). However, when I write to Magento, the loop resets at around record 40 - over, and over, and over again.
Now I can achieve to add some “Simple Product” easily, but the big deal would be to be able to create ”Configurable Product” and link “Simple Products” with “Configurable Product”.
First I started to create a derived object just assiging it the type to “Configurable Product”
$row = array ( 'sku' => 'test-sku-' . $t, 'store' => 0, 'attribute_set' => 'Default', 'type' => 'Configurable Product', // instead of 'Simple Product' 'categories' => '12,25', 'name' => 'Test Product ' . $t, 'description' => 'Here is the description of this product.', 'price' => 33.95, 'short_description' => 'Here is the description...', 'weight' => 0, 'status' => 'Enabled', 'tax_class_id' => 'Taxable Goods', );
This partially works but we also need to tell what are the attribute(s) which make this product configurable.
I don’t really know how to do it right now but if anyone knows this could be great
It looks like importFromTextArray() has been removed from v1.1.5.
This thread is helpful: http://www.magentocommerce.com/boards/viewthread/7519/P15/
I’m going to try using sql to import direct to the database shortly (will post the script here if i can get it to work). Many other topics have mentioned scripts but not posted anything (as far as I can find anyway).
Does anyone have tips / code on updating the layered navigation and caches etc once the import is complete?
I’m using Mage_Catalog_Model_Convert_Adapter_Product::saveRow() to create the initial product and then Mage::getModel( ‘catalog/product’ )->load() to fill in the details. Seems to work OK.
I’m using Mage_Catalog_Model_Convert_Adapter_Product::saveRow() to create the initial product and then Mage::getModel( ‘catalog/product’ )->load() to fill in the details. Seems to work OK.
I’m new to OOP and to Magento - could you point me in the right direction to learn about how to use these please? Thanks.