3

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?

2
  • Was your question answered? Then please mark a solution. Commented Feb 28, 2013 at 17:44
  • @Erfan I hope you knew, "how to add import option to the custom module data?". Can you guide me or suggest any link for reference? Thank you.
    – DRAJI
    Commented Oct 28, 2013 at 6:23

2 Answers 2

2

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>
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.