以编程方式获取用户刚刚在 Ubercart 中完成的订单

发布于 2024-09-06 15:51:09 字数 450 浏览 2 评论 0原文

当用户被发送到“感谢页面”(购物车/结帐/完成)时,我需要获取一些有关订单的信息,以将其发送到第 3 方跟踪 API。问题是,在这一点上,无论是在会议中还是在我所知道的任何其他地方,都没有有关订单的信息。作为一种解决方法,我尝试查询当前连接的用户的最后一个订单,但当用户取消注册时,此操作会失败,因为 Ubercart 会动态注册帐户并使用户保持未登录状态。

所以我的问题是,有没有办法从 page-cart.tpl.php 模板获取此时的 Order 对象(cart/checkout/complete)?

到目前为止我的解决方案:

在 cart/checkout/review 获取 $_SESSION['cart_order'] 变量,将其分配给 $_SESSION['faux_order'] 并在 cart/checkout/complete 的脚本中使用 faux_order ...感觉就像就像看到长颈鹿被窒息而死一样丑陋。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吖咩 2024-09-13 15:51:09

警告!不要使用上面的答案。请参阅我的评论以获取解释。

而不是上面提交的答案(您永远不应该使用它)创建一个自定义 Ubercart 条件操作 (CA) 并将其添加到“触发器:客户”部分Ubercart CA 工作流程中的“完成结帐”,可在 https://dev.betternow.org/ 中找到admin/store/ca/overview

这里我定义了一个自定义 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;
}

现在我可以在我的模块中定义的回调函数中使用订单 id:

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

我自己使用这种方法向用户显示“谢谢”页面带有他们刚刚购买的产品的链接。

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.

可爱咩 2024-09-13 15:51:09

$_SESSION['cart_order'] 可在订单审核页面上找到。

所以...

创建一个代表订单 ID 的 cookie,如下所示:

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

然后,在订单确认页面上,您可以像这样调用保存的 cookie:

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

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

如果用户随后返回并创建一个新订单,每当他们到达订单审核页面时,cookie 就会更新。

$_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文