bebeboutik-scripts/export_cart.php
2017-12-18 17:14:31 +01:00

57 lines
1.5 KiB
PHP

<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
include('www/config/config.inc.php');
$date_current = new DateTime('2015-04-21');
$date_end = new DateTime('2015-04-29');
$export_total = fopen('export_avril.csv', 'w');
$headers = array(
'Id cart',
'Name',
'Total',
'Carrier',
'Date'
);
fputcsv($export_total, $headers, ';');
while ($date_current <= $date_end) {
$file = fopen('tmp/export-'.$date_current->format('Y-m-d').'.csv', 'w');
$batch = 50;
$i = 0;
$data = '';
foreach ( Db::getInstance()->executeS('
SELECT CONCAT(c.lastname," ", c.firstname) as name, ca.name carrier, a.id_cart, a.id_customer, a.id_currency, a.date_add
FROM ps_cart a
LEFT JOIN `ps_customer` c ON (c.`id_customer` = a.`id_customer`)
LEFT JOIN `ps_carrier` ca ON (ca.`id_carrier` = a.`id_carrier`)
WHERE a.date_add >= "'.$date_current->format('Y-m-d').' 00:00:00"
AND a.date_add <= "'.$date_current->format('Y-m-d').' 23:59:59"
') as $key => $cart) {
$cartObj = new Cart($cart['id_cart']);
$data.= $cart['id_cart'].';'.$cart['name'].';'.$cartObj->getOrderTotal().';'.$cart['carrier'].';'.$cart['date_add']."\n";
$i++;
if($i % $batch == 0) {
writeFile($file, $data);
$data = '';
$i = 0;
}
}
writeFile($file, $data);
fwrite($export_total, file_get_contents('tmp/export-'.$date_current->format('Y-m-d').'.csv') );
fclose($file);
unlink('tmp/export-'.$date_current->format('Y-m-d').'.csv');
$date_current->add(new DateInterval('P1D'));
}
fclose($export_total);
function writeFile($file, $data) {
fwrite($file, $data);
}