Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I get a list of billing address for our top 500 customers
 
overshot16
Jr. Member
 
Total Posts:  1
Joined:  2012-10-01
 

I am new to this company and I can not figure out all the relations between SQL tables. Note we have kept all of the default magento databases. I need to get a list of billing address for our top 500 customers. Is there a way to find how a column is populated in a table? I am using crucial web hosting. Thanks for any info

 
Magento Community Magento Community
Magento Community
Magento Community
 
Luge
Jr. Member
 
Avatar
Total Posts:  10
Joined:  2010-09-22
Belarus, Minsk
 

Hello. You do not neet to make direct queries to the database. Magento allows to get all information through it’s API and EAV database structure.
Here is the example how you can save all default billing addresses into var/customers.csv

<?php

// init store
ini_set('memory_limit''2000M');
error_reporting(E_ALL E_STRICT);
$mageFilename 'app/Mage.php';
require_once 
$mageFilename;
ini_set('display_errors'1);
umask(0);
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE''';
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE''store';
Mage::app($mageRunCode$mageRunType);

// get cusomers collection
$customer_collection Mage::getModel('customer/customer')->getCollection();

// open csv for writing
$fp fopen('var/customers.csv''w');
$data = array(
        
'id' => 'ID',
        
'firstname' => 'Customer Firstname',
        
'lastname' => 'Customer Lastname',
        
'billing_firstname' => 'Billing Firstname',
        
'billing_lastname' => 'Billing Lastname',
        
'billing_country' => 'Billing Country',
        
'billing_city' => 'Billing City',
        
'billing_region' => 'Billing Region',
        
'billing_postcode' => 'Billing Zip',
        
'billing_street' => 'Billing Street',
        
'billing_telephone' => 'Billing Phone'
);

// write into csv
fputcsv($fp$data);
// iterate customers
foreach ($customer_collection as $customer{
    
// load customer's information
    
$customer Mage::getModel('customer/customer')->load($customer->getId());
    
// get default billing address
    
$address Mage::getModel('customer/address')->load($customer->getDefaultBilling());

    
$data['id'$customer->getId();
    
$data['firstname'$customer->getFirstname();
    
$data['lastname'$customer->getLastname();
    
$data['billing_firstname'$address->getLastname();
    
$data['billing_lastname'$address->getLastname();

    
// "long" country name
    
$country_id $address->getCountryId();
    
$data['billing_country'Mage::app()->getLocale()->getCountryTranslation($country_id);
    
$data['billing_city'$address->getCity();
    
$data['billing_region'$address->getRegion();
    
$data['billing_postcode'$address->getPostcode();

    
// join 2 address lines
    
$street $address->getStreet();
    
$data['billing_street'implode(', '$street);

    
$data['billing_telephone'$address->getTelephone();

    
// write into csv
    
fputcsv($fp$data);
}

fclose
($fp);

Hope this code will help you to understand how things are done in magento.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top