Question

I want to parse a csv, map the fields, and do perform some custom logic with the imported data, but I can't seem to figure out the Profile Actions XML.

The XML currently looks like this, along with my reasoning:

=> Firstly the Adapter checks if the file exists and creates the batch model.

<action type="dataflow/convert_adapter_io" method="load">
    <var name="type">file</var>
    <var name="path">var/import</var>
    <var name="filename"><![CDATA[stuff.csv]]></var>
    <var name="format"><![CDATA[csv]]></var>
</action>

=> Here the Parser parses the CSV and stores it into dataflow_import_data table for other actions to access/manipulate it.

<action type="dataflow/convert_parser_csv" method="parse">
    <var name="delimiter"><![CDATA[,]]></var>
    <var name="enclose"><![CDATA["]]></var>
    <var name="fieldnames">true</var>
</action>

=> Here the mapper converts the data stored in the dataflow_import_data table.

<action type="dataflow/convert_mapper_column" method="map">
   <var name="map">
       <map name="first_name"><![CDATA[Given Name]]></map>
       <map name="last_name"><![CDATA[Family Name]]></map>
   </var>
   <var name="_only_specified">true</var>
</action>

=> And finally, I can perform my own logic. (this doesn't make much sense since the csv rows are already parsed, but there doesn't seem to be a right action for this.. )

<action type="dataflow/convert_parser_csv" method="parse">
    <var name="delimiter"><![CDATA[,]]></var>
    <var name="enclose"><![CDATA["]]></var>
    <var name="fieldnames">false</var>
    <var name="number_of_records">10</var>
    <var name="adapter">mymodule/convert_adapter_myadapter</var>
    <var name="method">saveRow</var>
</action>

Obviously, above won't work because (in the second action) convert_parser_csv doesn't have an adapter and method.

Can someone point me in the right direction to make the mapper work?

Was it helpful?

Solution

The mapper only works with exporting data. The documentation didn't mention that :(

I will map the fields myself in the saveRow method of my adapter. Following code works fine:

<action type="dataflow/convert_adapter_io" method="load">
    <var name="type">file</var>
    <var name="path">var/import</var>
    <var name="filename"><![CDATA[stuff.csv]]></var>
    <var name="format"><![CDATA[csv]]></var>
</action>

<action type="dataflow/convert_parser_csv" method="parse">
    <var name="delimiter"><![CDATA[,]]></var>
    <var name="enclose"><![CDATA["]]></var>
    <var name="fieldnames">false</var>
    <var name="number_of_records">10</var>
    <var name="adapter">mymodule/convert_adapter_myadapter</var>
    <var name="method">saveRow</var>
</action>

OTHER TIPS

I don't know exactly if this fits your needs, but maybe you should take a look at this extension: AvS_FastSimpleImport. With FastSimpleImport you can use an array as source for Magento´s ImportExport Core Module. So, you could read your CSV (or any other source) into an array, manipulate the data and run the import.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top