These lovely script has been working since magento 1.2, with minor changes to 1.3~1.4, while respecting the magento style, even with creative solutions, such as that used for some critical installations keeping two web servers: one for local import tasks and other for real web, which were copied thousands of new products via mysqldump… in seconds!
But now, the absolutely brilliant “magento developers, community team and contributors” offer us a new and fast way of interacting with the data.
I greatly prefer it to other private initiatives -even my MySQL inyections-, for his clarity and his total structural integration with magento and his spirit.
As a demonstration of my support to all developers and users of magento I wanted to facilitate the integration of two features from the old script to the new model: the automatic creation of categories, the automatic addition of “select” attribute options and the possibility of reindex / flush cache / clean images / recalculate rules. They can export csv files too.
Also, add a new adapter “CSV1” that allows to use the old csv files (comma-separated, single line) in the new import system (multi-line-attribute)
This is very cool! Thank you for sharing. I am about to try it, but had one question. Do I still need to create an Advanced Profile to use the extension?
This is very cool! Thank you for sharing. I am about to try it, but had one question. Do I still need to create an Advanced Profile to use the extension?
-Talesh.
Hi Talesh! You’re welcome!
You don’t need to create any profile, simply install it via magento-connect (when available, I hope in few days) and use it via command line or crontab.
But if you don’t want to wait, you can copy it to your magento folder and uncompress.
tar xzf AMartinez_CustomImportExport-1.5.002.tgz
There are some examples in var/customimportexport folder
Yup I just noticed that the XML file was missing from the package when I installed it manually. As I come across anything else while testing in the wild I will let you know.
Yup I just noticed that the XML file was missing from the package when I installed it manually. As I come across anything else while testing in the wild I will let you know.
It works very well for me. My suggestion is to post a sample CSV file that goes with your extension. I have managed to get mine working but still trying to make the \\\"config_attributes\\\" column work. My configurable product never has all the simple products associated with it.
By the way, I want to mention that there was a bug in Magento Core file app/code/core/Mage/ImportExport/Model/Import/Adapter/Abstract.php, around line #84:
Mage::throwException($this->__("%s file does not exists or is not readable", $source));
must be:
Mage::throwException(Mage::helper('importexport')->__("%s file does not exists or is not readable", $source));
I reported this issue and now this is solved (you only need to update)
Single-Row CSV explanation (files with extension .csv1)
As you can see in my adapter file app/code/community/AMartinez/CustomImportExport/Model/Import/Adapter/Csv1.php there are some calls for two new functions:
The array passed as parameter sets the fields to manage as “multi-value field”, but why not process them all directly? Because some fields (custom fields, description fields, etc) can contain commas in their content, but these commas do not indicate multiple values. In addition, I don’t want to change the multi-value character, for historical or backward reasons.
I use extension “Inchoo Featured Product”. And it adds attribute “inchoo_featured_product” for products. I set values of this attribute from admin panel by hand After import all these values become “0”. What can i do to prevent this attribute from import?
I am using custom attributes without problem… What type is the featured product attribute?
I see “Inchoo Featured Product” extension is 1.3 compatible, perhaps “forgot” to update some .xml new to 1.5 version?
Try this: go to attributes manager, delete the original attribute (installed by extension) then make a new one with all the same data (name, code, etc) and test it again…
In any case, you can edit what you need at app/code/community/AMartinez/CustomImportExport/Model/Import/Entity/Product.php, isAttributeValid function, to manage these values:
public function isAttributeValid($attrCode, array $attrParams, array $rowData, $rowNum) { switch ($attrParams['type']) { case 'varchar': $val = Mage::helper('core/string')->cleanString($rowData[$attrCode]); //// convert to utf-8 //// $val = iconv('ISO-8859-1', 'UTF-8' . '//IGNORE//TRANSLIT', $val); $valid = Mage::helper('core/string')->strlen($val) < self::DB_MAX_VARCHAR_LENGTH; break; case 'decimal': $val = trim($rowData[$attrCode]); $valid = (float)$val == $val; break; case 'select': $valid = isset($attrParams['options'][strtolower($rowData[$attrCode])]); if (!$valid) { if (in_array($attrCode . ":" . $rowData[$attrCode], $this->_newAttrParams)) { return true; } if ($this->parseAttributeOption($attrCode, $rowData[$attrCode])) { $this->_newAttrParams[] = $attrCode . ":" . $rowData[$attrCode]; // $this->addRowError(Mage::helper('importexport')->__("Attribute option added for '%s'"), $rowNum, $attrCode); echo ":::: " . Mage::helper('importexport')->__("New attribute option added: ") . $attrCode . " - " . $rowData[$attrCode] . " (first ocurrence in line " . ($rowNum+1) . ") ::::\n"; $this->addRowError(Mage::helper('importexport')->__("Attribute option added for '%s'"), $rowNum, $attrCode); } return true; } break; case 'int': $val = trim($rowData[$attrCode]); $valid = (int)$val == $val; break; case 'datetime': $val = trim($rowData[$attrCode]); $valid = strtotime($val) || preg_match('/^\d{2}.\d{2}.\d{2,4}(?:\s+\d{1,2}.\d{1,2}(?:.\d{1,2})?)?$/', $val) || $val == "1899-12-31"; // firebird null date break; case 'text': $val = Mage::helper('core/string')->cleanString($rowData[$attrCode]); //// convert to utf-8 //// $val = iconv('ISO-8859-1', 'UTF-8' . '//IGNORE//TRANSLIT', $val); $valid = Mage::helper('core/string')->strlen($val) < self::DB_MAX_VARCHAR_LENGTH; break; default: $valid = true; break; } if (!$valid) { $this->addRowError(Mage::helper('importexport')->__("Invalid value for '%s'"), $rowNum, $attrCode); } return (bool) $valid; }
Take a look at app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php too…