Vote up!
Vote down!

How can I add an order id to an anonymous user's session

Hey all,
So, I have a scenario where an anonymous user requests a product from me (a hiking trip). When they get to the checkout:review screen, they are redirected to a "we'll get back to you shortly" page. My staff checks availability, and then sends an approval email to the order email. In the order email, there is a link to the checkout cart associated with the user where they can finish the process.

My problem is, if the user's session has expired or they change browsers, they get a "page not found". I'm trying to do all of this without creating accounts because of UE reasons (got lots of complaints since most users only use the site once). I can grab the order ID from the url in the link, so how to I assign it to the current anonymous user's session?


Asked by: Abenezer
on February 19, 2015

1 Answer

Vote up!
Vote down!

Just in case anyone else is looking for a solution to this, here's what I figured out.

I created a custom token that grabs the order ID from the URL with the custom token module. Here's what the token looks like:

= (!empty($_SERVER['HTTPS'])) ?
$parts = parse_url($url);
$path_parts= explode('/', $parts[path]);
$this_order = $path_parts[2];
$this_order; // **echo's second part of url**

It's important to make the token a "site information" token type.

Then I created a rule that acts on "drupal is initializing", and under a PHP action I added:

$order = commerce_order_load('[site:order-id]');
$_SESSION['commerce_cart_orders'][] = $order->order_id;

where [site:order-id] is my custom token.

Answer by: Abenezer
Posted: Feb 19, 2015