1

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.

1

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.
}
1

For guest , magento have it customer_id as null.So you need to sales model by guest email address and magento set a flagcustomer_is_guest =1whenever customer will checkout as guest.

Magento also save Customer email address to sales model table whenever loggin customers are checkout ,so on this case customer_is_guest =1 is importand

$orderCollection = Mage::getModel("sales/order")->getCollection()
    ->addFieldToSelect('*')
    ->addFieldToFilter('customer_is_guest',1) ;
foreach( $orderCollection  as $eachorder){
//var_dump($eachOrder) or print_r($eachOrder);


// you can also use your logic here.

}

I hope this will help you.

0

Well it's pretty simple, for guest orders, you can get customer's firstname & lastname as below:

$orderCollection = Mage::getModel('sales/order')
                                            ->getCollection()
                                            ->addFieldToSelect('*')
                                            ->addFieldToFilter('customer_is_guest', 1);

foreach($orderCollection as $order):
echo $order->getCustomerFirstname()." ";
echo $order->getCustomerLastname();
endforeach;

Check some of below links for better understanding.

Success page get customer name and order id

https://blog.digiswaps.com/magento-get-customer-details-from-order/

https://stackoverflow.com/questions/6075464/magento-questions-get-customer-details-and-onepage-checkout-success-doesnt-send

https://stackoverflow.com/questions/8698781/how-do-i-get-customername-from-an-order

Hope this may help you.

  • @Kishore Patra Was this answer helpful ? – Vicky Dev Dec 29 '15 at 16:41
  • This is used for retrieving the information of a single customer related to a particular order, I guess. But I want the list of all the guest customer who had made orders from the beginning of the store. – Kishore Patra Dec 30 '15 at 1:44
  • Updated my answer, check now. – Vicky Dev Dec 30 '15 at 5:12
0

You can use below code to get customer detail from order:

    $orders = Mage::getModel('sales/order')->getCollection();
    foreach($orders as $order){
        //You can get all data of order easily by echo "<pre>"; print_r($order->getdata());
        if($order->getCustomerId())
        {
            $customerData = Mage::getModel('customer/customer')->load($order->getCustomerId()); //customer info loaded
        } 
        else
        {
            //Its guest customer . Do whatever you want                
        }

    }

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.