以编程方式获取用户刚刚在 Ubercart 中完成的订单
当用户被发送到“感谢页面”(购物车/结帐/完成)时,我需要获取一些有关订单的信息,以将其发送到第 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
警告!不要使用上面的答案。请参阅我的评论以获取解释。
而不是上面提交的答案(您永远不应该使用它)创建一个自定义 Ubercart 条件操作 (CA) 并将其添加到“触发器:客户”部分Ubercart CA 工作流程中的“完成结帐”,可在 https://dev.betternow.org/ 中找到admin/store/ca/overview
这里我定义了一个自定义 CA
现在我可以在我的模块中定义的回调函数中使用订单 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
Now I can use the order id in my own callback function defined in my module:
I use this approach myself to show a "Thank You" page to users with a link to the product they just purchased.
$_SESSION['cart_order'] 可在订单审核页面上找到。
所以...
创建一个代表订单 ID 的 cookie,如下所示:
然后,在订单确认页面上,您可以像这样调用保存的 cookie:
如果用户随后返回并创建一个新订单,每当他们到达订单审核页面时,cookie 就会更新。
$_SESSION['cart_order'] is available on the order review page.
So ...
Create a cookie representing the order ID like this:
Then, on the order confirmation page, you can call the saved cookie like this:
If the user then goes back and creates a new order, the cookie will be updated whenever they reach the order review page.