【发布时间】:2016-09-17 14:09:43
【问题描述】:
我通过它将所有产品导出到 csv 文件中,
但我的 csvfile 没有创建,我可以在屏幕上看到变量输出。
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
set_time_limit(0);
require_once '/var/www/html/app/Mage.php';
umask(0);
Mage::app('default');
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
define('CSV_PATH', 'var/www/html/rahul_csvfiles/'); // specify CSV file path
$csv_fileoutput = CSV_PATH . "cfd_all_products_log".date("Y-m-d H:i:s").".csv";
$csvfileoutput = fopen($csv_fileoutput, 'a');
fputcsv($csvfileoutput, array('Entity_id','SKU','Product_Name','Product Name','Title', 'Short Description', 'Long Description', 'URL'));
$store_id = 2;
$collection = Mage::getModel('catalog/product')->getCollection()->addStoreFilter($store_id)
->addAttributeToSelect('*')
->setPageSize(3)
->setCurPage(1);
foreach ($collection as $product) {
$product_id = $product->getID();
$sku = $product->getSKU();
$productname = $product->getName();
$price = (float) $product->getPrice();
$description = $product->getDescription();
$shortdescription = $product->getShortDescription();
$url = $product->getProductUrl();
echo $product_id. "\n";
echo $sku. "\n";
echo $productname. "\n";
echo $price. "\n";
echo $url . "\n";
fputcsv($csvfileoutput, array($product_id,$sku,$productname,$productname,$price,$description,$shortdescription,$url));
}
?>
请让我知道我做错了什么,任何建议都会有所帮助。
谢谢
【问题讨论】:
-
查看
$csvfileoutput = fopen($csv_fileoutput, 'a');fopen()Returns a file pointer resource on success, or FALSE on error.的回复 -
CSV_PATH的值不以斜杠开头,因此您可能正在尝试写入不存在的目录。