希望這個答案是不是太晚了你,但你有沒有試過如下:
$order->line_items[] = uc_order_line_item_add($order->order_id, 'Pay at door','Pay at door',5);
的問題是,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;
}
來源
2013-04-04 13:14:43
PAB