【问题标题】:Total order not updated for the custom line item自定义订单项的总订单未更新
【发布时间】:2016-07-25 00:42:42
【问题描述】:

我正在使用 ubercart 3 和 drupal 7。我想创建自定义订单项以收取额外的手续费。下面的代码工作正常,但额外的处理量没有添加到总数中,而是添加到了小计中。

我做错了什么?

 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;    
  }
}

【问题讨论】:

    标签: drupal drupal-7 drupal-modules ubercart


    【解决方案1】:

    您需要使用 hook_uc_line_item 来定义您的自定义订单项。例如:

    /**
    * 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;
    }
    

    【讨论】:

      猜你喜欢
      • 2012-11-28
      • 2017-06-12
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 2012-07-26
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多