This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
urapidflow:data_preprocess [2010/03/19 21:13] unirgy |
urapidflow:data_preprocess [2011/07/06 19:11] (current) unirgy |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Pre-process data before import ====== | ||
+ | The example is simplified, without handling of errors for events like file open or write. | ||
+ | |||
+ | <file php urapidflow.php> | ||
+ | <?php | ||
+ | |||
+ | // load Magento libraries | ||
+ | include_once ' | ||
+ | Mage:: | ||
+ | |||
+ | // open original file for reading | ||
+ | $fs = fopen(' | ||
+ | |||
+ | // open file to be imported for writing | ||
+ | $fd = fopen(' | ||
+ | |||
+ | // retrieve column names | ||
+ | $fieldColumns = fgetcsv($fs); | ||
+ | $first = true; | ||
+ | |||
+ | // iterate through file | ||
+ | while ($r = fgetcsv($fs)) { | ||
+ | // get a row as associated array | ||
+ | $row = array_combine($fieldColumns, | ||
+ | | ||
+ | // perform your data modifications here | ||
+ | // change existing columns | ||
+ | $row[' | ||
+ | | ||
+ | // or add new columns, | ||
+ | // make sure that the new columns are always available | ||
+ | // and order of columns is always the same | ||
+ | $row[' | ||
+ | | ||
+ | // output header | ||
+ | if ($first) { | ||
+ | fputcsv($fd, | ||
+ | $first = false; | ||
+ | } | ||
+ | | ||
+ | // write the product row | ||
+ | fputcsv($fd, | ||
+ | } | ||
+ | // close files | ||
+ | fclose($fd); | ||
+ | fclose($fs); | ||
+ | |||
+ | // run the profile, which should be associated with final import file | ||
+ | Mage:: | ||
+ | </ |