views:

30

answers:

1

When the user is sent to the "thank you page" (cart/checkout/complete) I need to get some info about the order to send it to a 3rd party tracking API. Problem is that in this point there is no info about the order, either in session nor in any other place that I know of. As a workaround I tried querying the last order for the currently connected user but this fails when the user is unregistered as Ubercart registers an account on the fly and leaves the user unlogged.

So my question is, is there a way to get the Order object at this point (cart/checkout/complete) from the page-cart.tpl.php template ?

My solution so far:

Grab the $_SESSION['cart_order'] variable at cart/checkout/review , assign it to $_SESSION['faux_order'] and use faux_order in my script at cart/checkout/complete ... which feels as ugly as seeing a giraffe choke to death.

+1  A: 

Run this against the uc_orders table:

$order_id = db_fetch_object(db_query('SELECT order_id FROM {uc_orders} LIMIT 1 ORDER BY order_id DESC'));

That would get you the last inserted order ID, theoretically, if there isn't anything else going on in the site (backend POS, etc). If you wrap the tracking code in page.tpl.php to occur on the thank you page, you should have your order id.

Kevin
Thanks man, I thought of your approach but a quick test with three concurrent users sent the same data two out of the three times.I really can't believe something like this can't be done in a easier manner with ubercart ... one would guess you'd have a reference to the order up until the checkout/complete page.
JoseMarmolejos
That's odd. You could also try doing watchdog('mytracker', 'Order ID is @order_id', array('@order_id' => $order_id), WATCHDOG_NOTICE); and see what Order ID it logs for what user. The ones that don't get sent you can cross reference with the ones that do get sent, and see what the difference is.
Kevin