Looks like I finally got this issue sorted.
After lots of experimenting, file hunting and tracing - and getting my maths brain into gear I made the changes below.
Files affected:
includes/classes/currencies.php
at the end of the file I changed
PHP Code:
function display_price($products_price, $products_tax, $quantity = 1) {
return $this->format(zen_add_tax($products_price, $products_tax) * $quantity);
}
to this
PHP Code:
function display_price($products_price, $products_tax, $quantity = 1) {
//-bof-frank18-Fix rounding error with tax calculation
return $this->format(zen_round(zen_add_tax($products_price, $products_tax), 2) * $quantity);
//-eof-frank18-Fix rounding error ...
}
includes/classes/order.php
changed (from around line 526)
PHP Code:
/*********************************************
* Calculate taxes for this product
*********************************************/
$shown_price = (zen_add_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $this->products[$index]['tax']))
+ zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
$this->info['subtotal'] += $shown_price;
$this->notify('NOTIFIY_ORDER_CART_SUBTOTAL_CALCULATE', array('shown_price'=>$shown_price));
// find product's tax rate and description
$products_tax = $this->products[$index]['tax'];
$products_tax_description = $this->products[$index]['tax_description'];
to this
PHP Code:
/*********************************************
* Calculate taxes for this product
*********************************************/
//$shown_price = (zen_add_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $this->products[$index]['tax'])) // standard ZC1.5.1 code (frank18)
// next line is replacement which works a treat (frank18)
$shown_price = round((zen_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax'])), 2) * $this->products[$index]['qty']
+ zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
$this->info['subtotal'] += $shown_price;
$this->notify('NOTIFIY_ORDER_CART_SUBTOTAL_CALCULATE', array('shown_price'=>$shown_price));
// find product's tax rate and description
$products_tax = $this->products[$index]['tax'];
$products_tax_description = $this->products[$index]['tax_description']; // - shows correct product totals incl tax (frank18)
includes/classes/shopping_cart.php
changed line 851
PHP Code:
$this->total += zen_round(zen_add_tax($productTotal, $products_tax), $decimalPlaces) * $qty;
to this
PHP Code:
// $this->total += zen_round(zen_add_tax($productTotal, $products_tax), $decimalPlaces) * $qty;
$this->total += zen_round(zen_add_tax($productTotal, $products_tax), 2) * $qty; // -frank18- correct rounding issue
Even though $decimalPlaces are set to '2' they won't take (don't know why???) - but by actually specifying 2 decimal places in that line fixed it
Finally in both of these files
includes/functions/functions_prices.php
admin/includes/functions/functions_prices.php
There are 5 instances in each of the 2 files showing
PHP Code:
return number_format($blah_blah_variable, 4, '.', '');
which I all changed to
PHP Code:
return number_format($blah_blah_variable, 2, '.', '');
I tested this on 3 different local ZC1.5.1 installs with normal priced products, products priced by attributes, products with special prices and products with sale maker prices. All are now showing fine on the shopping cart page, checkout_shipping, checkout_payment, checkout_confirmation and in admin - including the invoice. The fixes are now active on my main live store.
I would be grateful to see some comments on these changes - especially after seeing numerous reports on the same rounding issue on this forum and on the net - dating back to 2008.
If we are lucky, Ajeh (the shipping and payment module specialist ) may take a look at this.
Cheers / Frank
Bookmarks