Magento Forum - UK Magento Forum (Unofficial)

An unofficial but dedicated Magento Forum for Magento Users, Designers and Developers

Create CVS File

A forum for Magento users to discuss tips, issues etc with regards to actually using the Magento front and back end systems.

Create CVS File

Postby rebecca2103 » Thu Jan 29, 2015 10:54 am

Hi, I need to create a CVS file showing order ID, Customer name and email address - how do I do this? If I export a CVS from the order page it does not include the email addresses?

Probably a very basic question but as you can tell.....I need all the help I can get!! :D
Posts: 1
Joined: Thu Jan 29, 2015 10:50 am

Re: Create CVS File

Postby mozeruk » Thu Feb 12, 2015 9:52 am

Hi Rebecca,

You could use this code;
Code: Select all
$orders = Mage::getModel('sales/order')->getCollection();
$orders->setPage(1, 3000);
$fp = fopen('file.csv', 'w');
foreach($orders as $order) {
   $fields = array($order->getBillingAddress()->getFirstname(),$order->getBillingAddress()->getLastname(),$order->getBillingAddress()->getEmail());
   fputcsv($fp, $fields);

1. Create a file called script.php
2. Upload to your site via ftp
3. Then visiting in your browser.
4. it creates a CSV called file.csv stored in the same directory on the server as the script

Any problems let me know.

Posts: 2
Joined: Thu Feb 12, 2015 9:43 am

Re: Create CVS File

Postby LordSprocket » Fri Nov 04, 2016 1:34 pm


I have what it vcery possibly a stupid question!

Is the line: $orders->setPage(1, 3000); the loop count ie. this script will output the first 3000 customer records it encounters?

Thanks in advance

Posts: 1
Joined: Fri Nov 04, 2016 1:31 pm

Return to Magento Users