0

Context: Magento 1.7.0.0 version. I have to import csv data, with magento dataflow advanced profiles. I have made an Adapter that implements Mage_Dataflow_Model_Convert_Adapter_Abstract. I've implemented saveRow() method for processing each row, ok.

Next step: I want to run some code before any row is processed: something like save() or beforeSave() method... How can I do it?

I guess that I have to implement save() method from Mage_Dataflow_Model_Convert_Adapter_Abstract and to add something on the the Actions XML section on my Import Profile:

<!-- adapter: loading data from local csv file-->
<action type="dataflow/convert_adapter_io" method="load">
    <var name="type">file</var>
    <var name="path">var/import</var>
    <var name="filename"><![CDATA[blabla.csv]]></var>
    <var name="format"><![CDATA[csv]]></var>
</action>

<!-- parsing: transform into database entities -->
<action type="dataflow/convert_parser_csv" method="parse">
    <var name="delimiter"><![CDATA[,]]></var>
    <var name="enclose"><![CDATA[']]></var>
    <var name="fieldnames">true</var>
    <var name="store"><![CDATA[0]]></var>
    <var name="number_of_records">1</var>
    <var name="adapter">mymodule/convert_adapter_blabla</var>
    <var name="method">saveRow</var>
</action>

Any suggestions will be welcome, thanks! :)

Katapofatico
  • 750
  • 1
  • 10
  • 29

1 Answers1

1

the save() method will be triggered only once per import, so I don't think this is the way you want to go with. Though it has access to the collection data, so, depending on the operation you want to do it may fit.
As you have implemented the saveRow() method, can't you include in it a call to some (private) method before doing anything else?

public function saveRow()
{
    $this->_somePrivateMethod();
    ...
    /** the rest of saveRow() method **/
    ...
}

private function _somePrivateMethod()
{
    /** the code you want to execute before every row is saved **/
}
OSdave
  • 8,538
  • 7
  • 45
  • 60
  • A lot of thanks @OSdave, I have tested it and it don't works :( : The import processing is executed with AJAX calls from import web console, once per row!: That's why a new Adapter object is created on Mage_Adminhtml_System_Convert_ProfileController->batchRunAction(): `$adapter = Mage::getModel($batchModel->getAdapter()); ... $adapter->saveRow($importData);`. The extrange point is that it looks to wait for a collection o rows, last code is in for loop: `foreach ($rowIds as $importId) {...` **Solutions**: a) another standard magento way b) how to process all rows in a single AJAX call – Katapofatico Jun 05 '12 at 15:34