Mittwoch, 12. März 2014

Magento Export Customers

If you need to export customer data for Excel this script does the job. If you upload and execute it. A file.csv with you customers will be created. The UTF-8 CSV file can be imported in Excel. Don't forget to delete both files afterwords. Also note that personal records should not be mailed without encryption.

<?php
require_once("app/Mage.php");
Mage::app();
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
$collection = Mage::getModel('customer/customer')
    ->getCollection()
    ->addAttributeToSelect('*');

$fp = fopen('file.csv', 'w');
foreach($collection as $customer) {
 $customerAddressId = $customer->getDefaultBilling();
    if ($customerAddressId){
        $address = Mage::getModel('customer/address')->load($customerAddressId);

        $fields = array(
            $address->getData('company'),
            $customer->getData('prefix'),
            $customer->getFirstname(),
            $customer->getLastname(),
            $address->getData('street'),
            $address->getData('postcode'),
            $address->getData('city'),
            $address->getCountry(),
            $customer->getData('email')
        );
        fputcsv($fp, $fields);
        var_dump($fields); echo "<br>";
    }
}
?>

I converted the code to html using hilite.me looks nice, what do you think?

Like it? Share it! Flattr this

Keine Kommentare: