Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tegansnyder/4281839 to your computer and use it in GitHub Desktop.
Save tegansnyder/4281839 to your computer and use it in GitHub Desktop.
Create a CSV of Magento Customers with more than one recurring profile attached to their account.
<?php
error_reporting(E_ALL | E_STRICT);
require_once 'app/Mage.php';
Varien_Profiler::enable();
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app('default');
$collection = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToSelect('*');
$result = array();
$x = 0;
foreach ($collection as $customer) {
$customer_id = $customer->getId();
$email = $customer->getEmail();
$profile = Mage::getModel('sales/recurring_profile')->getCollection()
->addFieldToSelect('*')
->addFieldToFilter('customer_id', $customer_id);
$y = 0;
$result[$x]['customer_id'] = $customer_id;
$result[$x]['customer_email'] = $email;
foreach ($profile as $p) {
$result[$x]['profile_id_' . $y] = $p->getId();
$y = $y + 1;
}
$x = $x + 1;
}
function outputCSV($data) {
$outputBuffer = fopen("php://output", 'w');
foreach($data as $val) {
fputcsv($outputBuffer, $val);
}
fclose($outputBuffer);
}
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=customers.csv");
header("Pragma: no-cache");
header("Expires: 0");
outputCSV($result);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment