0

I need to find out if a customer (during checkout) is also currently logged in as a Zen Cart administrator. The purpose is for allowing certain actions to be available for an administrator placing an order on behalf of a customer (say, by telephone).

My first idea was to check $_SESSION['admin_id'].

However this does not seem to be set, instead $_SESSION['customer_id'] is.

I think this is because different session names are chosen in the admin and customer areas (zenAdminId vs zenid).

How can I find out if this customer would be logged in as an admin, had they been in the admin area at the same time?

I am working on the checkout step prior to sending off to a hosted payment service provider.

Edit: the merchant is logged in as an admin and is entering the customer's details, which are different to those of the admin account, into the checkout screens. It is a customer-not-present/MOTO setup.

2 Answers 2

1

You are correct - $_SESSION['customer_id'] is set. And there's nothing in the customer's table which indicates if this person is an admin. However, if they use the same email address for their customer account and for their admin account, you can look up their email in the customers table with $_SESSION['customer_id'], then match that against the admin_email field in the emails in Use this to look up table "admin."

3
  • It's an idea Scott but I'd prefer to enter the customer's email address (which would be different, since we're typing a customer's details from a phoned order) if I can. All the other details will be the customer's own. I might use this as a short term fix and type our own admin email here. Nov 4, 2011 at 8:25
  • oh ok. how about adding a third field to the login screen, something like "Admin Login as Customer Password" and when this is set appropriately, flag the login as an admin logging in on behalf of the customer. Nov 4, 2011 at 10:25
  • I can see that working too. I have opted for the admin email address solution for now. Thanks. Would love to be able to load both admin and customer sessions at the same time as that would be more elegant. Nov 8, 2011 at 12:24
0

It is worth noting that if your admin cookie isn't restricted by path SESSION_USE_ROOT_COOKIE_PATH=True that you can simply check for the cookie zenAdminID. You can read the contents of this cookie by querying zen_sessions, the sesskey being the value in zenAdminID.

You have to base64_decode the value from the result to get the session. It gives a serialised object, although unfortunately you are unable to use unserialize on it. You can load it as the current $_SESSION but this would overwrite your current one.

I simply did this to get the admin_id:

preg_match('/admin_id\|s:1:"([0-9]+?)"/', $admin_session, $admin_matches);

$admin_matches[1] giving the admin id value.

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.