2

How can I know that a person was a guest or registered user from the order placed? Is it possible to identify this from sales data?

6

For orders where the user was a guest the field customer_is_guest on the table sales_flat_order will be 1. Whereas for registered user this will have a value of 0.

6

For the guest orders it's easy.

$order->Mage::getModel('sales/order')->load($id);
$isGuest = $order->getCustomerIsGuest();
//or
//$isGuest = $order->getCustomerId() == 0;

But to check if the customer registered or it was already logged in is not that easy.
You cannot get the information from the order object. You need to check the quote object associated to the order. But that may not exist.
You can try something like this:

$order->Mage::getModel('sales/order')->load($id);
if ($order->getCustomerIsGuest()) { 
    //customer is guest
}
else {
    $quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
    if ($quote->getId()) {
         $method = $quote->getCheckoutMethod();
         if ($method == 'register'){
              //customer registered when placing the order
         }
         else {
              //customer was already logged in when placing the order
         }
    }
    else {
        // there is no way of knowing if the customer registered or was already logged in but for sure an account exists.
    }
}
5
  • Should be possible if you match the email address against the customer tables. There is a createdate of some sort in there that can be matched against the order. They should be somewhat identical, like within a 60 second interval if the customer registered with that order.
    – user4351
    Aug 5 '14 at 2:12
  • @Melvyn. That could be possible, but it's not 100% effective. There is a chance (a very small one indeed) where false positives can appear.
    – Marius
    Aug 5 '14 at 5:41
  • True, so if this needs to be one hundred percent accurate, I would implement a customer attribute that stores the order with which that customer registered. This is useful for other sales related statistics as well and it takes only one observer to write the data. ;-)
    – user4351
    Aug 5 '14 at 17:10
  • @Melvyn nice idea.
    – Marius
    Aug 5 '14 at 17:18
  • The code above doesn't work in magento 1.9.0.1, nice tip found here stackoverflow.com/a/17727500/1078641 . $quote->getCheckoutMethod() gives you login_in instead , need to use $quote = $observer->getQuote(); $checkout_method = $quote->getData(); $checkout_method = $checkout_method['checkout_method'];
    – electroid
    Oct 31 '16 at 3:10
2

You can try below code.

    $order = Mage::getModel('sales/order')->load($orderId);
    $order->getCustomerIsGuest();

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.