1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| $list[] = array("ID", "date de paiement", "nom", "prénom", "mail", "total", "types", "détails commande");
foreach($commandes as $commande) {
$total = Money::EUR(0);
$items = $commande->getItems();
$details = "";
$type = "";
$titre = "";
foreach($items as $item) {
$produit = $item->getProduit();
$total = $total->add( $produit->getPrice()->multiply( $item->getQuantity() ) );
if($item->getProduit()->getActivite() !== NULL) {
$type .= "Activité ";
$titre = $item->getProduit()->getActivite()->getTitre();
//var_dump($titre);
} else if($item->getProduit()->getPublication() !== NULL) {
$type .= "Publication ";
$titre = $item->getProduit()->getPublication()->getTitre();
//var_dump($titre);
} else if($item->getProduit()->getArticle() !== NULL) {
$titre = $item->getProduit()->getArticle()->getTitre();
$type .= "Article ";
}
$details .= substr($titre, 0, 20) . "\n" . $item->getProduit()->getTitre() ." à ". $moneyFormatter->format($item->getProduit()->getPrice()) ." x ". $item->getQuantity() ." = ". $moneyFormatter->format($item->getTotal()). " \n ";
}
$list[] = array(
$commande->getId(),
$commande->getDatePaiement()->format("d/m/Y H:i"),
$commande->getUser()->getNom(),
$commande->getUser()->getPrenom(),
$commande->getUser()->getMail(),
$moneyFormatter->format($total),
$type,
$details,
);
}
$response = new Response();
$fp = fopen('php://output', 'w');
fputs($fp, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
foreach ($list as $fields) {
fputcsv($fp, $fields, ";");
}
fclose($fp);
$response->headers->set('Content-Type', 'application/octet-stream; charset=utf-8');
$response->headers->set('Content-Disposition', 'attachment; filename="export.csv"');
return $response; |
Partager