5 replies [Last post]
jasonabc's picture
Offline
Uber Donor
Joined: 05/05/2008
Juice: 573
Was this information Helpful?

Hi - at checkout - the Order Total Preview has the subtotal, shipping, tax etc line items in a weird order. This is confusing for customers as it looks like tax is being added to the sub total plus shipping instead of just the sub total. It currently appears like this:

Subtotal: $35.00
Shipping: $10.00
Subtotal excluding taxes: $45.00
NY Sales Tax: $3.11
Order total: $48.11

How do I move the Sales Tax line item up so it is underneath the Sub total (and before Shipping)? In OSC you can set a sort order of all the different order total modules in Admin but I don't see anything here.

Subtotal: $35.00
NY Sales Tax: $3.11
Shipping: $10.00
Subtotal excluding taxes: $45.00
Order total: $48.11

thanks

Jason

arpieb's picture
Offline
Joined: 10/28/2009
Juice: 81
hook_line_item_data_alter?

Could you use hook_line_item_data_alter to alter the weight on the line items to shift them around? I don't know if this will affect calculations or not (A before B, B before C types) but it definitely affects where they show up in the listing.

jasonabc's picture
Offline
Uber Donor
Joined: 05/05/2008
Juice: 573
Re: hook_line_item_data_alter?

thanks for the reply - much appreciated Eye-wink

robmilne's picture
Offline
Joined: 06/07/2011
Juice: 5
Hack that works for me

This is a dirty hack and requires that you do some snooping with print_r

Inside uc_payment_get_totals function of uc_payment.module (Ubercart 6.x-2.4) I placed this on line 353 (after $grand_total = 0;):

$output .= print_r($order->line_items);

This gave me a list of the line items and their weights. I carefully noted the 'type' element for each item, decided the proper order, changed the weight and called the usort after my manipulation. In my case the types that I needed to sort were the subtotal, fee (handling), tax_subtotal (product + handling), tax, shipping.

Replace...

  if ($order) {
    usort($order->line_items, 'uc_weight_sort');

    $output = t('Order total preview:')
             .' ';
    $grand_total = 0;

    $context = array(
      'type' => 'line_item',
      'subject' => array(
        'order' => $order,
      ),
    );

    foreach ($order->line_items as $line) {

With...

  if ($order) {
    $output = t('Order total preview:')
             .' ';
    $grand_total = 0;

    $items = array();
    foreach ($order->line_items as $line) {
      switch($line['type']) {
        case 'subtotal':
          $line['weight'] = -10;
          break;
        case 'fee':
          $line['weight'] = -8;
          break;
        case 'tax_subtotal':
          $line['weight'] = -1;
          break;
        case 'tax':
          $line['weight'] = 0;
          break;
        case 'shipping':
          $line['weight'] = 10;
          break;
      }
      array_push($items, $line);
    }
    usort($items, 'uc_weight_sort');

    $context = array(
      'type' => 'line_item',
      'subject' => array(
        'order' => $order,
      ),
    );

    foreach ($items as $line) {

I don't believe this compromises system security.
I would have preferred to have the weights set properly inside the module but I could not find where the original weights were set

-rob

jasonabc's picture
Offline
Uber Donor
Joined: 05/05/2008
Juice: 573
Re: Hack that works for me

awesome - thanks mate Eye-wink

robmilne's picture
Offline
Joined: 06/07/2011
Juice: 5
cart/checkout/review problem too

Ok, ubercart is officially driving me crazy. I thought my own module was spaghetti until I tried debugging this monster.

I've decided to dispense with the tax subtotal line since it doesn't fall in the right position and it isn't the correct amount either. For my own purposes I'm only keeping the product subtotal, handling, tax and shipping
This is the mod to the foreach loop in my previous mod:

    foreach ($order->line_items as $line) {
      $add_line = true;
      switch($line['type']) {
        case 'subtotal':
          $line['weight'] = -10;
          break;
        case 'fee':
          $line['weight'] = -8;
          break;
        case 'tax':
          $line['weight'] = 0;
          break;
        case 'shipping':
          $line['weight'] = 10;
          break;
        default:
          $add_line = false;
          break;
      }
      if($add_line) {
        array_push($items, $line);
      }
    }

The 'Review order' page also has order issues. I have another hack to remove the tax subtotal line inside the uc_order_load_line_items function of the uc_order.module:

Change...

  else {
    foreach (_line_item_list() as $type) {
      if ($type['stored'] == FALSE
          && (isset($type['callback']) && function_exists($type['callback']))
          && (!isset($type['display_only']) || $type['display_only'] == FALSE)) {
        $result = $type['callback']('load', $order);
        if ($result !== FALSE && is_array($result)) {
          foreach ($result as $line) {
            $items[] = array(
              'line_item_id' => $line['id'],
              'type' => $type['id'],
              'title' => $line['title'],
              'amount' => $line['amount'],
              'weight' => isset($line['weight']) ? $line['weight'] : $type['weight'],
              'data' => $line['data'],
            );
          }
        }
      }
    }
  }

to...

  else {
    foreach (_line_item_list() as $type) {
      if ($type['stored'] == FALSE
          && (isset($type['callback']) && function_exists($type['callback']))
          && (!isset($type['display_only']) || $type['display_only'] == FALSE)) {
        $result = $type['callback']('load', $order);
        if ($result !== FALSE && is_array($result)) {
          foreach ($result as $line) {
            if($line['id'] == "tax_subtotal") continue;
            $items[] = array(
              'line_item_id' => $line['id'],
              'type' => $type['id'],
              'title' => $line['title'],
              'amount' => $line['amount'],
              'weight' => isset($line['weight']) ? $line['weight'] : $type['weight'],
              'data' => $line['data'],
            );
          }
        }
      }
    }
  }

Unfortunately now my total amount is wrong - the tax calculations don't agree between the 'Review order' page and the payment area of the 'Checkout' page!!!!!!!!!!!!!! Guess I'll have to dispense with the fee - the module can't handle it consistently. Not impressed.
-rob