Magento – how can I get the customer details from order from the magento database

magento-1.7querysales-order

I want to list the details of all the customer which has made an order.
The customers who has created account , can easily be found out from the admin side.
But how can I find the list of all the guest customer who had made orders from the beginning of the store.

Please suggest me some query so that I can list all the customer from the order table.

Best Answer

Try this way:

$orders = Mage::getModel('sales/order')->getCollection();

$guestOrders = array();
foreach($orders as $order){
   if($order->getCustomerIsGuest()){
      $guestOrders[] = $order;
   }
}

//print all guest orders
foreach($guestOrders as $order){
   echo "<pre>".$order->getId()."</pre>";
}

//print all customer who made guest checkout
foreach($guestOrders as $order){
   echo "<pre>".$order->getCustomerFirstname() ." ".$order->getCustomerLastname()." - ".$order->getCustomerEmail()."</pre>";
   //...........
   //there are lot of other customer attributes you can print.
}

Remember guest orders are not associated with any customer.

Hope this helps.

Update [1]

Even better way:

//get only guest orders
$orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_is_guest', 1); 

//print all customer who made guest checkout
foreach($orders as $order){
   echo "<pre>".$order->getCustomerFirstname() ." ".$order->getCustomerLastname()." - ".$order->getCustomerEmail()."</pre>";
   //...........
   //there are lot of other customer attributes you can print.
}
Related Topic