New Zenner
- Join Date:
- Aug 2006
- Posts:
- 80
- Plugin Contributions:
- 0
1.3.7.1 Percentage Discounts & Multiple Items calculates Incorrect Sales Tax
Lets get the basics out of the way first:
Zen Cart 1.3.7.1
Database Patch Level 1.3.7
The issues was if more then 1 product was added into your cart and you had a discount coupon that gave a percentage off, the sales tax was not calculating properly.
I found the problem but im unsure if this was already corrected in newer versions of zen-cart or not.
in ot_coupon function calculate_deductions
You loop through each product in the cart here:
global $db, $order, $messageStack;
$tax_address = zen_get_tax_locations();
$od_amount = array();
if ($_SESSION['cc_id']) {
$coupon = $db->Execute("select * from " . TABLE_COUPONS . " where coupon_id = '" . (int)$_SESSION['cc_id'] . "'");
if (($coupon->RecordCount() > 0 && $order_total !=0) || ($coupon->RecordCount() > 0 && $coupon->fields['coupon_type']=='S') ) {
if ($coupon->fields['coupon_minimum_order'] <= $order_total) {
if ($coupon->fields['coupon_type']=='S') {
$od_amount['total'] = $order->info['shipping_cost'];
$od_amount['type'] = 'S';
} else {
if ($coupon->fields['coupon_type'] == 'P') {
$od_amount['total'] = zen_round($order_total*($coupon->fields['coupon_amount']/100), 2);
} else {
$od_amount['total'] = $coupon->fields['coupon_amount'] * ($order_total>0);
}
if ($od_amount['total']>$order_total) $od_amount['total'] = $order_total;
$products = $_SESSION['cart']->get_products();
[B] for ($i=0; $i<sizeof($products); $i++) { [/B]
The issue is while looping the products there, when you get into the coupon type if statements, you attempt to loop through the products again, when we are already doing that.
if ($coupon->fields['coupon_type'] == 'P') {
switch ($this->calculate_tax) {
case 'Credit Note':
$tax_rate = zen_get_tax_rate($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
$tax_desc = zen_get_tax_description($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
$od_amount[$tax_desc] = $od_amount['total'] / 100 * $tax_rate;
$od_amount['tax'] += $od_amount[$tax_desc];
break;
case 'Standard':
$ratio = $od_amount['total']/$this->get_order_total();
$products = $_SESSION['cart']->get_products();
[B] // for ($j=0; $j<sizeof($products); $j++) { [/B] $t_prid = zen_get_prid($products[$i]['id']);
$cc_result = $db->Execute("select products_tax_class_id
from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
if ($is_valid_results) {
$tax_rate = zen_get_tax_rate($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
$tax_desc = zen_get_tax_description($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
if ($tax_rate > 0) {
// $od_amount[$tax_desc] += (($products[$i]['final_price'] * $products[$i]['quantity']) * $tax_rate)/100 * $ratio;
$od_amount[$tax_desc] += round(((($products[$i]['final_price'] * $products[$i]['quantity']) * $tax_rate) + .5)/100 * $ratio, 2);
$od_amount['tax'] += $od_amount[$tax_desc];
}
}
[B] // } [/B]
To fix the problem i commented out the two items in bold and that solved the tax calcs. Let me know if this is something that was already corrected.