Programmatically receive an order that a user has just completed in Ubercart

When the user goes to the thank you page (cart / checkout / complete), I need to get some order information to send it to the third-party tracking API. The problem is that at this point there is no order information, neither in the session, nor in any other place that I know of. As a workaround, I tried to request the last order for the currently connected user, but this fails when the user is not registered, since Ubercart registers the account on the fly and leaves the user unprotected.

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

My decision:

Take the variable $ _SESSION ['cart_order'] into the cart / checkout / review, assign it $ _SESSION ['faux_order'] and use faux_order in my script in cart / checkout / complete ... which feels as ugly as a giraffe's vision gasps to death.

+4
source share
2 answers

Attention! DO NOT USE ANSWER ABOVE. See my comment for an explanation.

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

Here I define a user 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 identifier 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 myself use this approach to show the "Thank you" page to users with a link to the just purchased product.

+4
source

$ _ SESSION ['cart_order'] is available on the order overview page.

So...

Create a cookie representing the order ID, for example:

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

Then, on the order confirmation page, you can call up the saved cookie as follows:

 <?php if (isset($_COOKIE['orderID'])): $theOrder = $_COOKIE['orderID')); echo 'The order ID is: ' . $theOrder; endif; ?> 

If the user then returns and creates a new order, the cookie will be updated whenever it reaches the order overview page.

0
source

Source: https://habr.com/ru/post/1313441/


All Articles