5

I want to retrieve all customer data including the address information, customer custom attributes, and customer profile information. Right now i'm using customer model like this:

$collections = Mage::getModel('customer/customer')->getCollection();
foreach ($collections as $collection) {
            $result[]= $collection->getData();
}
print_r($result);

form this i only get basic information like entity_id, store_id, created_at, is_active, and etc. by using this i can't get even the customer personal information like telephone or at least customer name

5

you can get the customer details like below :

customer id here

$customerId = 1;

load customer object

$customer = Mage::getModel('customer/customer')->load($customerId); //insert cust ID

create customer address array

$customerAddress = array();
foreach ($customer->getAddresses() as $address)
{
   $customerAddress[] = $address->toArray();
}

displaying the array

echo '<pre/>';print_r($customerAddress);exit;

After getting the user’s address you will see something like this:

Array
(
    [entity_id] => 1
    [entity_type_id] => 2
    [attribute_set_id] => 0
    [increment_id] => 
    [parent_id] => 1
    [created_at] => 2013-12-05 14:28:40
    [updated_at] => 2013-12-05 16:14:13
    [is_active] => 1
    [firstname] => Daniel
    [lastname] => Halmagean
    [city] => New York
    [region] => New Jersey
    [postcode] => 123123
    [country_id] => RO
    [telephone] => 2342423434243
    [region_id] => 282
    [street] => my street name
    [customer_id] => 1
)
  • And how to get all customer ids?! – Black Apr 1 at 15:29
1
  1. This is the default query for a customer collection. As you might notice without specifying fields to retrieve it retrieves everything. So lets add some fields!

    $collection = mage::getModel('customer/customer')->getCollection()
    ->addAttributeToSelect('email')
    ->addAttributeToSelect('telephone')
    ->addAttributeToFilter('firstname', 'sander')
    ->addAttributeToSort('email', 'ASC');
     var_dump((string)$collection->getSelect());
    
  2. In your case you just need to specify the addAttributeToSelect so it only retrieves that field. On non EAV collections use addFieldToSelect.

        $users = mage::getModel('customer/customer')->getCollection()
       ->addAttributeToSelect('email');
    
       foreach ($users as $user)
       var_dump($user->getData());
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.