简体   繁体   English

自定义订单项的总订单未更新

[英]Total order not updated for the custom line item

I am using ubercart 3 with drupal 7. I want to create custom line item for additional handling charges. 我将ubercart 3与drupal 7一起使用。我想创建自定义订单项以收取额外的手续费。 Below code is working fine but the additional handling amount is not added with the total, but its added with the subtotal. 下面的代码可以正常工作,但是额外的处理量未与总数相加,而是与小计相加。

What am I doing wrong? 我究竟做错了什么?

 function mycustom_uc_order($op, $order, $arg2) {
 switch ($op) {
 case 'save':   
  $package_lineitem_id = $ups_charges = $package_lineitem_index = '';
  $line_items = uc_order_load_line_items($order);
  foreach ($line_items as $key => $line_item) {
    if ($line_item['type'] == 'shipping' && $line_item['amount'] != '') {
      $ups_charges = $line_item['line_item_id'];
    } elseif($line_item['type'] == 'custom_package_charges'){
      $package_lineitem_id = $line_item['line_item_id'];
      $package_lineitem_index = $key;
    }
  }        
      $pack_charges = 5; 
    // If packaging charges line item exists update else create a new one
    if(empty($package_lineitem_id)){
      $order->line_items[] = uc_order_line_item_add($order->order_id, 'custom_package_charges', 'Additional Handling Charges for Packaging', $pack_charges,5);
    } else { 
      uc_order_update_line_item($package_lineitem_id, 'Additional Handling Charges for Packaging', $pack_charges);
      $order->line_items[$package_lineitem_index]['amount'] = $pack_charges;
    }   

  break;    
  }
}

You need to use hook_uc_line_item to define your custom line item. 您需要使用hook_uc_line_item来定义您的自定义订单项。 For example: 例如:

/**
* Implements hook_uc_line_item().
*/

function mycustom_uc_line_item() {
$items[] = array(
 'id' => 'custom_package_charges',
 'title' => t('Custom text'),
 'weight' => 0,
 'default' => FALSE,
 'stored' => TRUE,
 'add_list' => TRUE,
 'calculated' => TRUE,
);
return $items;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM