1

我目前正在寻找一种将订单注释添加到 Magento v1.4.2 安装的订单导出(.csv 格式)的方法。

我已经设置了一个配置文件,它将使用简单的订单导出和 IKT 订单导出扩展导出我需要的所有内容,例如客户姓名、付款、运输等,但还没有找到一种方法来导出客户评论/评论历史记录与订单。

有没有一种简单的方法可以做到这一点?IKT 订单导出有一个自定义映射字段,我找到了包含订单注释的表,但我无法让模块对其进行映射。

评论位于数据库字段 sales_flat_order_status_history(评论)中。我确信它在代码中,但作为一个相对新手.... 帮助将不胜感激。

4

1 回答 1

3

您可以使用 Magento 的Varien_File_Csv类轻松地将自定义数组数据导出到 csv。
如果您知道要从中导出的字段,sales_flat_order_status_history那么您可以简单地执行以下操作(只是一个基本想法):

<?php
/**
 * @author      MagePsycho <info@magepsycho.com>
 * @website     http://www.magepsycho.com
 */
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
#Mage::setIsDeveloperMode(true);
#ini_set('display_errors', 1);
umask(0);
Mage::app();

$filePath   = '/path-to-csv/comments.csv';
$csv        = new Varien_File_Csv();
$exportData = array(); 
$comments   = getCommentsFromHistoryTable(); //you can fetch comments from the required table
foreach($comments as $_comment){ //loop over the comments to prepare the export data
    $data = array();
    $data['field1'] = $_comment->getField1();
    $data['field2'] = $_comment->getField2();
    //... so on
    $exportData[] = $data;
}
$csv->saveData($filePath, $exportData);

就这样。它将数据保存在指定的csv中。

希望这对您有所帮助。
谢谢

于 2012-03-13T20:05:45.753 回答