Magento 1.7 – Dataflow Advanced Profiles Export with Custom Decimal Separator

dataflowexportimportexportmagento-1.7

I need to change dot to comma on product price when I export using dataflown advanced profile. I tried this way:

...
<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="decimal_separator"><![CDATA[,]]></var>

     <var name="adapter">catalog/convert_adapter_product</var>
     <var name="method">parse</var>
</action>
...

But this not work, how I can do this only for this profile? I'm trying to do this programming, copying from core to local, but without success.

Thank you!

Best Answer

You can't just add arbitrary attributes in the XML declaration; there has to be PHP which processes them. You need to rewrite the Mage_Dataflow_Model_Convert_Parser_Csv::getCsvString() method to evaluate it. The core method looks like this:

/**
 * Retrieve csv string from array
 *
 * @param array $fields
 * @return sting
 */
public function getCsvString($fields = array()) {
    $delimiter  = $this->getVar('delimiter', ',');
    $enclosure  = $this->getVar('enclose', '');
    $escapeChar = $this->getVar('escape', '\\');

    if ($delimiter == '\t') {
        $delimiter = "\t";
    }

    $str = '';

    foreach ($fields as $value) {
        if (strpos($value, $delimiter) !== false ||
            empty($enclosure) ||
            strpos($value, $enclosure) !== false ||
            strpos($value, "\n") !== false ||
            strpos($value, "\r") !== false ||
            strpos($value, "\t") !== false ||
            strpos($value, ' ') !== false) {
            $str2 = $enclosure;
            $escaped = 0;
            $len = strlen($value);
            for ($i=0;$i<$len;$i++) {
                if ($value[$i] == $escapeChar) {
                    $escaped = 1;
                } else if (!$escaped && $value[$i] == $enclosure) {
                    $str2 .= $enclosure;
                } else {
                    $escaped = 0;
                }
                    $str2 .= $value[$i];
            }
            $str2 .= $enclosure;
            $str .= $str2.$delimiter;
        } else {
            $str .= $enclosure.$value.$enclosure.$delimiter;
        }
    }
    return substr($str, 0, -1) . "\n";
}
Related Topic