4

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.

JoseMarmolejos
  • 1,760
  • 1
  • 17
  • 34

2 Answers2

4

WARNING! DO NOT USE THE ANSWER ABOVE. See my comment for explanation.

Instead of the answer submitted above (which you should NEVER! use) create a custom Ubercart conditional action (CA) and add it to the section "Trigger: Customer completes checkout" in your Ubercart CA workflow, found in https://dev.betternow.org/admin/store/ca/overview

Here I am defining a custom CA

function my_module_ca_action() {
    $order_arg = array(
        '#entity' => 'uc_order',
    '#title' => t('Order'),
    );


    $actions['my_module_status_update'] = array(
        '#title' => t('Some Title'),
    '#category' => t('Custom UC AC'),
    '#callback' => 'my_module_some_function_name',
    '#arguments' => array(
        'order' => $order_arg,
            ),
            );
        return $actions;
}

Now I can use the order id in my own callback function defined in my module:

function my_module_some_function_name(&$order, $settings) {
  echo "This is the order id: " . $order->order_id;
}

I use this approach myself to show a "Thank You" page to users with a link to the product they just purchased.

Ryan
  • 2,747
  • 2
  • 22
  • 16
Houen
  • 1,039
  • 1
  • 16
  • 35
0

$_SESSION['cart_order'] is available on the order review page.

So ...

Create a cookie representing the order ID like this:

<?php setcookie('orderID', '$_SESSION['cart_order']'); ?>

Then, on the order confirmation page, you can call the saved cookie like this:

<?php
if (isset($_COOKIE['orderID'])):
  $theOrder = $_COOKIE['orderID'));

  echo 'The order ID is: ' . $theOrder;
endif;
?>

If the user then goes back and creates a new order, the cookie will be updated whenever they reach the order review page.

erier
  • 1,744
  • 1
  • 11
  • 14