6

The problem is that I am sending the Magento order to an external ERP and they need the customer id from Magento.

the problem comes when the customer is guest because in theory this customer doesn't have an id but I am not sure. Is there a way to check if the customer is a guest?

I am using the Mage_Sales_Model_Order object in order to get the information I need from the customer.

Thanks!

1
  • what if customer is not logged in and ordered as guest ? Commented Nov 18 at 8:32

4 Answers 4

3

if you just want to know if the customer is guest or not. trigger getCustomerIsGuest() in Mage_Sales_Model_Order I believe that can get customer instance of order.

8

as you said I am using the Mage_Sales_Model_Order object in order to get the information then:

if($order->getCustomerIsGuest()){
    // customer is guest
}else{
    $customerid = $order->getCustomer()->getId();
    //send the customer id to your external ERP
}
1
  • Hi, thanks for your help, I was wondering if this really existed. I am going to check this and see if it works.
    – apz2000
    Commented May 9, 2014 at 22:53
1

Here is a way to do it in SQL, for one customer.

select
   entity_id,
   increment_id,
   customer_is_guest
from
   sales_flat_order
where
   increment_id = 101125260
;

Outputs:

+-----------+--------------+-------------------+
| entity_id | increment_id | customer_is_guest |
+-----------+--------------+-------------------+
|   2371223 | 101125260    |                 1 |
+-----------+--------------+-------------------+

To generate a histogram and understand the percentage of your users which are logged in when checking out.

select
   if(customer_id, 1, 0) as loggedin,
   count(*)
from
   sales_flat_order
where
   created_at > '2018-11-01'
group by
   1
order by
   1 desc
;

Outputs:

+----------+----------+
| loggedin | count(*) |
+----------+----------+
|        1 |     1194 |
|        0 |     1693 |
+----------+----------+
0

This can also be checked by observer:

$order = $observer->getEvent()->getOrder(); 
$guestCustomer = $order->getCustomerIsGuest();
groupId  = $order->getCustomerGroupId();

we can get all type of customer data using observer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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