I was having difficulty with getting the Discount Order Totals Module to work correctly especially when the shopping cart had a mixture of Tax included & Tax excluded products. I worked on the code of the file ot_group_pricing.php . I note that this file has been updated in ZC v1.3.6 with the code above. However, I still found it not to work as i would like so i continued to work on a solution.
See attachment for my modified version of ot_group_pricing.php
Basically, I modified & added new code into the function 'calculate_deductions' ie:
PHP Code:
/*
* calculate the ratio between orig subtotal & new subtotal,
* then use this ratio to calculate the new tax component value of the new subtotal compared to the orig tax component of the orig subtotal
* also, when calculating the ratio add some insignificant values to stop divide by zero errors
*/
$orig_sub_total = $order_total - $gift_vouchers;
$subTotalDiscRatio = 1 - (($orig_sub_total - $od_amount['total'] + .000001) / ($orig_sub_total + .000001));
switch ($this->calculate_tax) {
case 'Standard':
reset($order->info['tax_groups']);
while (list($key, $value) = each($order->info['tax_groups'])) {
$tax_rate = zen_get_tax_rate_from_desc($key);
if ($tax_rate > 0) {
$od_amount[$key] = $tod_amount = round($order->info['tax'] * $subTotalDiscRatio,4);
$od_amount['tax']+=$tod_amount;
}
}
break;
The idea behind this was that ZenCart already knows the tax component of the 'sub_total', so why not just simply apply this calculated ratio to the Tax component.
Also, within the file ot_group_pricing I commented out a few lines to do with the variable '$tax' and also the new if statement, 'if (DISPLAY_PRICE_WITH_TAX', in function 'process', commenting out these lines of code also helped me to get the correct returned Totals figures of my test shopping basket.
PHP Code:
function process() {
global $db, $order, $currencies;
$od_amount = $this->calculate_deductions($this->get_order_total());
if ($od_amount['total'] > 0) {
reset($order->info['tax_groups']);
// $tax = 0;
while (list($key, $value) = each($order->info['tax_groups'])) {
$tax_rate = zen_get_tax_rate_from_desc($key);
if ($od_amount[$key]) {
$order->info['tax_groups'][$key] -= $od_amount[$key];
// $order->info['total'] -= $od_amount[$key];
// $tax += $od_amount[$key];
}
}
/*
if (DISPLAY_PRICE_WITH_TAX == 'true') {
$od_amount['total'] += zen_calculate_tax($od_amount['total'], $tax);
}
*/
DrByte, a question: I am wondering if the call to function 'zen_calculate_tax' may not work as expected in file ot_group_pricing.php , did you mean to pass value of '$tax' from the global tax set in the 'tax rates' table or its actual value set from the returned value of '$od_amount['tax']' in function 'calculate_deductions' ?
regards, Matt
Bookmarks