Jump to content

Identify Logged-In and Guest Customers


Recommended Posts


For the payment gateway I developped, I am required to check whether the customer is logged in or is a guest (the payment provider requires it for fraud assessment purposes). I originally was under the assumption that the parameter basket['register'] meant the the customer is logged in (if set to 1) or is guest (if not set). Is it wrong?

On another note, I would like to have a clarification about the behavior of customer_id:

  • Can I assume that the customer_id in asket['billing_address ']['customer_id'] and in basket['delivery_address ']['customer_id'] is always the same?
  • Can I assume that, for two different customers in my shop (whether they are logged in or guest), customer_id will always be different? (I understand that, a same customer being a guest might end up with different customer_id)
  • I sometimes see te customer_id in basket['customer']['customer_id'] (which is convenient) and sometimes I don't see it there and have to grab it from either basket['billing_address ']['customer_id'] and in basket['delivery_address ']['customer_id'] (logs enclosed). Is there any reason for that?

Appreciate any help you may have!



Link to comment
Share on other sites

Sorry, $this->_basket['register'] is not an indication of whether or not the shopper is a logged-in customer or not.

You can use:


which will return a logical true if the shopper is logged in.

I am not familiar with basket['customer']. The following should get you the customer_id of the logged-in customer, or the id of the guest customer:

if(empty($shopper_id = $GLOBALS['user']->getId())) $shopper_id = $GLOBALS['user']->getGhostId();

The basket['billing_address']['customer_id'] and in basket['delivery_address ']['customer_id'] should be the same. The addresses come from CubeCart_addressbook and are keyed against the registered customer's 'customer_id'.

No customer will ever have the same 'customer_id' as any other customer. One of the customer details to obtain is the shopper's email address. And email addresses must be unique - CubeCart will not allow a Guest shopper to proceed to checkout having attempted to give an email that already exists.

Link to comment
Share on other sites

Thanks, I've used something very similar in my code. Posting it below if anyone is interested:

            if ($GLOBALS['user']->getId()){
                $hidden['vads_cust_id'] = $GLOBALS['user']->getId();
                $hidden['vads_ext_info_guest'] = "NO";
            else {
                $hidden['vads_cust_id'] = $GLOBALS['user']->getGhostId();
                $hidden['vads_ext_info_guest'] = "YES";

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...