Checkout calculations not the same as review

Project: 
Ubercart
Category: 
bug report
Priority: 
critical
Status: 
active

I am currently using a BZR copy of ubercart from four days ago and trying to write a module that calculates the Advanced Disposal Charge that applies to electronic products in Alberta. It is a flat fee per type of product, charged per item that applies. I have pretty much all of the code working great, event the ability to set the price per product class/zone. This module will be contributed once it is working 100%

The issue is that the review stage calculates the total with GST ignoring the ADS charges that are showing as line items. The Checkout page, where you select your address is working perfectly though. I have noticed a few things, there is a hidden value 'current_total' that doesn't get updated by getTax() or render_line_items(). Not sure if this is the only issue, just seems odd that nothing happens as the line items are changing.

I have based my module off of much of the code from the taxes module, and have the line items stored in the order table, all that works great.

The line items are listed in the GST tax settings as being taxable. I have also debugged the review stage and it is receiving the ADS line items but simply ignoring them somewhere along the line.

Please let me know if you would like me to email the code to you.
I don't want to post it as an upload as it is not fully functional yet...

Thanks,
Gord.

Re: Checkout calculations not the same as review

Additionally, the first time you go to the Review stage, that tax calculation is without the ADS charge. If you then click Back and then Review again, the tax calculation is correct.

Any ideas?

Thanks,
Gord.

Re: Re: Checkout calculations not the same as review

Gord, I'm curious if this works into the other tax problems we'd been having, particularly with taxes not taxing other taxes on the checkout screen but applying it after reviewing. Do the other fixes resolve this issue?

Just tested with new code, still not working

I think the issue here is that I am simulating another tax system with the module that I wrote.

The checkout stage works absolutely perfectly, it's when I go to review, that my JS added line item, because it depends on the Zone to calculate the charge is not getting passed to the review stage.

Is this because you are encoding the cart contents and line items and storing them in a hidden variable?

I just can't get the tax system to charge tax on a line item that I specify as being taxable in the review stage.

It must be something to do with the dynamic JS calculation process being different than the submitted one when going to review.

Please let me know if there is anything I can send you to help diagnose the issue.

Cheers,
Gord.

Workaround code

Here is some code that I have put in for testing that is giving me results that work.
In my tax calculation function I clear the $_SESSION['ads'] array and then set each matching product calculation again, in case there are changes, as does the uc_taxes module.

<?php
function uc_taxes_action_apply_tax($order, $tax){
 
$amount = 0;
  if (
is_array($order->products)) {
    foreach(
$order->products as $item){
     
$node = node_load($item->nid);
      if (
in_array($node->type, $tax->taxed_product_types)){
       
$amount += $item->price * $item->qty * $tax->rate;
      }
    }
  }
 
$taxed_line_items = $tax->taxed_line_items;
  if (
is_array($order->line_items) && is_array($taxed_line_items)){
    foreach (
$order->line_items as $key => $line_item){
      if (
$line_item['type'] == 'tax' && $line_item['title'] == $tax->name){
       
// Don't tax yourself.
       
continue;
      }
      if (
in_array($line_item['type'], $taxed_line_items)){
       
$amount += $line_item['amount'] * $tax->rate;
      }
    }
  }
  if (isset(
$taxed_line_items['tax'])){
    foreach (
$_SESSION['taxes'] as $other_tax){
     
$amount += $other_tax['amount'] * $tax->rate;
    }
  }
 
// Testing code START
 
foreach ( (array) $_SESSION['ads'] AS $ads_charge){
    if(
$ads_charge['amount']){
     
$amount += $ads_charge['amount'] * $tax->rate;
    }
  }
 
// Testing code END 
 
if ($amount){
   
$line_item = (object)array('id' => $tax->id, 'name' => $tax->name, 'amount' => $amount, 'weight' => $tax->weight);
    return array(
'tax_line_item' => $line_item);
  }
}
?>