Here's an update the Zen Cart 1.5.5 /includes/modules/order_total/ot_coupon.php's calculate_deductions function to correct the issue for both the amount-off and percentage-off plus free shipping cases:
Code:
function calculate_deductions() {
global $db, $order, $messageStack, $currencies;
$currencyDecimalPlaces = $currencies->get_decimal_places($_SESSION['currency']);
$od_amount = array('tax'=>0, 'total'=>0);
if ($_SESSION['cc_id'])
{
$coupon = $db->Execute("select * from " . TABLE_COUPONS . " where coupon_id = '" . (int)$_SESSION['cc_id'] . "'");
$this->coupon_code = $coupon->fields['coupon_code'];
$orderTotalDetails = $this->get_order_total($_SESSION['cc_id']);
if ($coupon->RecordCount() > 0 && $orderTotalDetails['orderTotal'] != 0 )
{
// left for total order amount vs qualified order amount just switch the commented lines
// if (strval($orderTotalDetails['totalFull']) >= $coupon->fields['coupon_minimum_order'])
if (strval($orderTotalDetails['orderTotal']) >= $coupon->fields['coupon_minimum_order'])
{
$coupon_is_free_shipping = false; //-20160417-lat9-Correct tax on free-shipping+off/% *** 1 of 4 ***
switch($coupon->fields['coupon_type'])
{
case 'S': // Free Shipping
$od_amount['total'] = $orderTotalDetails['shipping'];
$od_amount['type'] = 'S';
$od_amount['tax'] = ($this->calculate_tax == 'Standard') ? $orderTotalDetails['shippingTax'] : 0;
if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
$od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax'];
}
return $od_amount;
break;
case 'P': // percentage
$od_amount['total'] = zen_round($orderTotalDetails['orderTotal']*($coupon->fields['coupon_amount']/100), $currencyDecimalPlaces);
$od_amount['type'] = $coupon->fields['coupon_type'];
$ratio = $od_amount['total']/$orderTotalDetails['orderTotal'];
break;
case 'E': // percentage & Free Shipping
$od_amount['total'] = zen_round($orderTotalDetails['orderTotal']*($coupon->fields['coupon_amount']/100), $currencyDecimalPlaces);
$od_amount['type'] = $coupon->fields['coupon_type'];
// add in Free Shipping
//-bof-20160417-lat9-Correct tax on free-shipping+off/% *** 2 of 4 ***
// $od_amount['total'] = $od_amount['total'] + $orderTotalDetails['shipping'];
$coupon_is_free_shipping = true;
//-eof-20160417-lat9-Correct tax on free-shipping+off/% *** 2 of 4 ***
$od_amount['tax'] = ($this->calculate_tax == 'Standard') ? $orderTotalDetails['shippingTax'] : 0;
$ratio = $od_amount['total']/$orderTotalDetails['orderTotal'];
if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
$od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax'];
}
break;
case 'F': // amount Off
$od_amount['total'] = zen_round(($coupon->fields['coupon_amount'] > $orderTotalDetails['orderTotal'] ? $orderTotalDetails['orderTotal'] : $coupon->fields['coupon_amount']) * ($orderTotalDetails['orderTotal']>0), $currencyDecimalPlaces);
$od_amount['type'] = $coupon->fields['coupon_type']; // amount off 'F' or amount off and free shipping 'O'
$ratio = $od_amount['total']/$orderTotalDetails['orderTotal'];
break;
case 'O': // amount off & Free Shipping
$od_amount['total'] = zen_round(($coupon->fields['coupon_amount'] > $orderTotalDetails['orderTotal'] ? $orderTotalDetails['orderTotal'] : $coupon->fields['coupon_amount']) * ($orderTotalDetails['orderTotal']>0), $currencyDecimalPlaces);
$od_amount['type'] = $coupon->fields['coupon_type']; // amount off 'F' or amount off and free shipping 'O'
// add in Free Shipping
//-bof-20160417-lat9-Correct tax on free-shipping+off/% *** 3 of 4 ***
// if ($this->include_shipping == 'false') {
// $od_amount['total'] = $od_amount['total'] + $orderTotalDetails['shipping'];
// }
$coupon_is_free_shipping = true;
//-eof-20160417-lat9-Correct tax on free-shipping+off/% *** 3 of 4 ***
$od_amount['tax'] = ($this->calculate_tax == 'Standard') ? $orderTotalDetails['shippingTax'] : 0;
$ratio = $od_amount['total']/$orderTotalDetails['orderTotal'];
if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
$od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax'];
}
break;
}
switch ($this->calculate_tax)
{
case 'None':
break;
case 'Standard':
if ($od_amount['total'] >= $orderTotalDetails['orderTotal']) $ratio = 1;
foreach ($orderTotalDetails['orderTaxGroups'] as $key=>$value)
{
$od_amount['tax_groups'][$key] = zen_round($orderTotalDetails['orderTaxGroups'][$key] * $ratio, $currencyDecimalPlaces);
$od_amount['tax'] += $od_amount['tax_groups'][$key];
if ($od_amount['tax_groups'][$key] == 0) unset($od_amount['tax_groups'][$key]);
}
if (DISPLAY_PRICE_WITH_TAX == 'true' && $coupon->fields['coupon_type'] == 'F') $od_amount['total'] = $od_amount['total'] + $od_amount['tax'];
break;
case 'Credit Note':
$tax_rate = zen_get_tax_rate($this->tax_class);
$od_amount['tax'] = zen_calculate_tax($od_amount['total'], $tax_rate);
$tax_description = zen_get_tax_description($this->tax_class);
$od_amount['tax_groups'][$tax_description] = $od_amount['tax'];
}
//-bof-20160417-lat9-Correct tax on free-shipping+off/% *** 4 of 4 ***
if ($coupon_is_free_shipping) {
$od_amount['total'] += $orderTotalDetails['shipping'];
}
//-bof-20160417-lat9-Correct tax on free-shipping+off/% *** 4 of 4 ***
}
}
}
// print_r($order->info);
// print_r($orderTotalDetails);echo "<br><br>";
// echo 'RATIo = '. $ratio;
// print_r($od_amount);
return $od_amount;
}