I am modifying a script that exports fields from a database as a CSV file. I modified it a little so it now exports as a text file, but it is throwing in some extra characters that I don’t want. This is using the fputcsv() function which im sure is why its inserting extra characters.
Here is what it exports currently in a text file:
a19_13_8,1,-Jul 27, 2010 6:26:40 PM-,$32.20,$0.00,$0.00,-
-
r30_2700_4,1,-Jul 27, 2010 6:26:40 PM-,$14.70,$0.00,$0.00,-
Here is how I want it to export in a text file (comma seperated, no dash and no comma at the end of each line:
a19_13_8,1,Jul 27, 2010 6:26:40 PM,$32.20,$0.00,$0.00
r30_2700_4,1,Jul 27, 2010 6:26:40 PM,$14.70,$0.00,$0.00
Here is my script
const ENCLOSURE = '-';
const DELIMITER = ',';
public function exportOrders($orders)
{
$fileName = 'order_export_'.date("Ymd_His").'.txt';
$fp = fopen(Mage::getBaseDir('export').'/'.$fileName, 'w');
$this->writeHeadRow($fp);
foreach ($orders as $order) {
$order = Mage::getModel('sales/order')->load($order);
$this->writeOrder($order, $fp);
}
fclose($fp);
return $fileName;
}
protected function writeOrder($order, $fp)
{
$common = $this->getCommonOrderValues($order);
$orderItems = $order->getItemsCollection();
$itemInc = 0;
foreach ($orderItems as $item)
{
if (!$item->isDummy()) {
$record = array_merge($common, $this->getOrderItemValues($item, $order, ++$itemInc));
fputcsv($fp, $record, self::DELIMITER, self::ENCLOSURE);
}
}
}