Actually once I had your figures and I tested against a couple of different selections of cart contents I found the bug fairly quickly.
I am a bit shamefaced that this made its way thru testing, as I was sure that I had tested this fairly comprehensivly
As mentioned the bug only shows if there is more than 1 item in the cart, the bug however has nothing to do with the restriction code.
heres my updated function. Note I would like to test this a bit more before saying that this fix is authorative, especially as I have not tested this with restrictions in place.
PHP Code:
function calculate_deductions($order_total) {
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();
for ($i=0; $i<sizeof($products); $i++) {
// speed up process and store value
$is_valid_results = is_product_valid($products[$i]['id'], $_SESSION['cc_id']);
if ($is_valid_results) {
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();
$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] += round(((($products[$i]['final_price'] * $products[$i]['quantity']) * $tax_rate) + .5)/100 * $ratio, 2);
$od_amount['tax'] += $od_amount[$tax_desc];
}
}
break;
default:
}
}
if ($coupon->fields['coupon_type'] == 'F') {
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();
$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] += round(((($products[$j]['final_price'] * $products[$j]['quantity']) * $tax_rate) + .5)/100 * $ratio, 2);
$od_amount['tax'] += $od_amount[$tax_desc];
}
}
break;
default:
}
}
}
}
}
}
}
}
return $od_amount;
}
Bookmarks