New Zenner
- Join Date:
- Dec 2006
- Posts:
- 20
- Plugin Contributions:
- 0
Coupon tax recalculation wierdness.
I've been working for a few days trying to get the coupon module in 1.3.0 (I know its old, but the client won't pay to upgrade the system) In any case the coupon module wouldn't adjust the tax values. It would calculate the tax discount that was supposed to be applied based on the value of the coupon and would store it in $od_amount as it should but it simply would not apply the discount to the tax total. After spending countless hours looking at different objects and how they were interacting, I noticed the following:
if ( $od_amount['total'] > 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];
}
}
this should have done exactly what I wanted, except it wasn't. The while loop wasn't running at all. It seems that for some reason the pointer in the $order->info['tax_groups'] array was at the end of the array. In order to get it working I had to reset($order->info['total']) back to the starting point. So that the while loop would run.
The above code block then looks like:
if ( $od_amount['total'] > 0 ){
reset($order->info['tax_groups']);
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];
}
}
So I hope this is of some help to someone, and I hope that this problem has been fixed in the later versions. If not this will do it.