结果以CSV文件形式打印,而不是在php中的fputcsv中传递的对象

时间:2018-08-03 07:46:41

标签: magento-1.9 export-to-csv php-5.5

我想在Magento 1.9中将​​产品的输出写入CSV

以下是我的代码:-

$product_id = $_POST['product_id'];
$productCollection = Mage::getModel('catalog/product')->getCollection()
            ->addAttributeToFilter('type_id', array('eq' => 'configurable'))
            //->addFieldToFilter('entity_id', array('gt' => 216))
            ->setPageSize(20);
$fileName = "exports.csv";
$fp = fopen($fileName, 'w');
$csvHeader = array("SKU", "Name", "Short Description", "Categories", "Price", "Discount Label", "Enabled On Website?", "Visible as Out of Stock", "Created date", "Updated date", "Sizes");
header('Content-Encoding: UTF-8');
//header('Content-type: text/csv; charset=UTF-8');
header('Content-Type: application/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename="'.$fileName.'";');
fputcsv( $fp, $csvHeader,";");
fpassthru($fp);
fclose($fp);
response("success",$productCollection->getData());

由于某种原因,来自响应的数据被写入CSV而不是fputcsv,并且也以中文或日语而不是英语写入。

我不知道发生了什么。为什么代码会覆盖fputcsv并将响应中的数据写入csv,而中文/日语也是如此?

0 个答案:

没有答案