我不知道为什么这么复杂,但我想要做的就是当用户在Ubercart中更改付款方式时,在我的订单中添加一个订单项.我设法通过在我的付款方式中添加以下行来完成此操作.
uc_order_line_item_add($ order-> order_id,'门口付款','门口付款',5);
这似乎添加了订单项,但订单总数未更新.当我刷新页面时,我可以看到在那里添加的订单项.显然,我不想刷新屏幕,我希望在我的付款方式回调期间显示新的订单总额和订单项.我想这可以通过调用jquery来实现,但我在Google中找不到任何有用的东西.
有人可以帮忙吗?
小智 5
希望这个答案对你来说还不算太晚,但你是否尝试过以下方法:
$order->line_items[] = uc_order_line_item_add($order->order_id, 'Pay at door','Pay at door',5);
Run Code Online (Sandbox Code Playgroud)
问题是uc_order_line_item_add只是更新数据库而不是当前正在传递的订单对象,后来用于计算总数等,谢天谢地,uc_order_line_item_add返回一个可以简单地附加到订单对象的行项目数组.我不确定它是否适用于您的付款方式,但它适用于我在hook_uc_order,我有类似的税收问题,直到第二次刷新才更新.
如果它有助于我的完整示例代码如下:
<?php
function my_module_uc_order($op, &$order, $arg2) {
switch ($op) {
case 'presave':
// using presave as taxes are calculated during save
$line_item_id = FALSE;
if (!is_array($order->line_items)) {
$order->line_items = array();
}
else {
foreach ($order->line_items as $index => $line_item) {
if ($line_item['type'] == 'my_line_item') {
$line_item_id = $line_item['line_item_id'];
break;
}
}
}
if ($line_item_id === FALSE) {
// Add item.
// Dummy amount for testing.
$amount = 3;
// uc_order_line_item_add returns a line_item array so we can just add it to the order object.
$order->line_items[] = uc_order_line_item_add($order->order_id, 'my_line_item', 'My Item Title (added)', $amount);
// uc_order_line_item_add($order_id, $type, $title, $amount, $weight = NULL, $data = NULL).
}
else {
// Update item.
// Dummy amount for testing.
$amount = 4;
// uc_order_update_line_item($id, $title, $amount, $data = NULL).
uc_order_update_line_item($line_item_id, 'My Item Title (updated)', $amount);
// Manually modify amount.
$order->line_items[$index]['amount'] = $amount;
}
break;
}
}
/**
* Implements hook_uc_line_item().
*/
function my_module_uc_line_item() {
$items[] = array(
'id' => 'my_line_item',
'title' => t('Custom text'),
'weight' => 0,
'default' => FALSE,
'stored' => TRUE,
'add_list' => TRUE,
'calculated' => TRUE,
);
return $items;
}
Run Code Online (Sandbox Code Playgroud)