Skip to content

Instantly share code, notes, and snippets.

@isyan
Created June 2, 2014 03:42
Show Gist options
  • Select an option

  • Save isyan/2243af1e40df0eb07d6e to your computer and use it in GitHub Desktop.

Select an option

Save isyan/2243af1e40df0eb07d6e to your computer and use it in GitHub Desktop.
get customer name and email and prompts for a download as a csv file
<?php
require_once "app/Mage.php";
Mage::app();
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=customer-feed.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('Name', 'Email'));
$collection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email');
// loop over the rows, outputting them
foreach($collection as $customer) {
fputcsv($output, array($customer->getName(), $customer->getEmail()));
}
fclose($output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment