Forums / General Questions / Total Not Calculating Coupon

Total Not Calculating Coupon

Locked

Views: 1,150

Results 1 to 10 of 10
This thread is locked. New replies are disabled.
5 Jan 2010, 10:07 AM
#1
fooddudes avatar

fooddudes

New Zenner

Join Date:
Nov 2008
Posts:
33
Plugin Contributions:
0

Total Not Calculating Coupon

Total Not Calculating Coupon. I had an order come in and the discount was applied properly, but not added in the order total. The coupon is $10 off orders of $50 or more. Below are the order totals, any help is greatly appreciated.

Sub-Total: $51.75
Delivery: $2.99
Discount: -$10.00
State Tax: $3.04
Local Tax: $0.82
Total: $58.60

5 Jan 2010, 1:46 PM
#2
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Total Not Calculating Coupon

Are you using the Local Sales Tax module? If so, this is where your problem lies. The Local Sales Tax module ignores any coupons or discounts, and just adds the Tax and Shipping to the Order SubTotal, and makes this the Order Total.

The update you need is:

Find this line of code within includes/modules/order_total/ot_local_sales_tax.php

                    $taxRateLocal = $taxResult->fields['local_tax_rate'];

And add teh follwoing code after:

$order_discount = ($order->info['shipping_cost'] + $order->info['subtotal']) - $order->info['total'];
if ($order_discount > 0) {
  $debug2 .= 'Order total '.$order->info['total'].'<br />';
  $percentage_discount = ($order->info['total'] / ($order->info['total'] + $order_discount));
  $debug2 .= '<b>Percentage Discount</b>'.$percentage_discount.'<br />';
} else {
  $percentage_discount = 1;
}
$taxable_amount = $percentage_discount * ($Taxable_Subtotal + ($order->info['shipping_cost'] * (int)$ot_local_sales_taxes_charge_tax_on_shipping));

A few lines further down you'll find

//use zen cart tax function to calculate the tax (Taxable subtotal + shipping if needed)
$LocalTaxTotal = zen_calculate_tax(.........

Replace this with

//use zen cart tax function to calculate the tax (Taxable subtotal + shipping if needed)
$LocalTaxTotal = zen_calculate_tax($taxable_amount, $taxRateLocal);

Finally, below this, find

$order->info['total'] = $order->info['shipping_cost'] + $order->info['subtotal'] + $order->info['tax'];

And replace it with

$order->info['total'] += $order->info['tax'];

As with all updates, BACKUP first!

Absolute

Back, after a 4 year absence! Did you miss me?
Absolute Web Solutions Ltd
Interested in our work? Take a look at one of our sites - The Tech Store

6 Jan 2010, 2:58 AM
#3
fooddudes avatar

fooddudes

New Zenner

Join Date:
Nov 2008
Posts:
33
Plugin Contributions:
0

Re: Total Not Calculating Coupon

Hi Absolute, thank for your response. I made the changes, but the error still occurs any other insight would be greatly appreciated.

6 Jan 2010, 8:51 AM
#4
absolute avatar

absolute

Totally Zenned

Join Date:
May 2005
Location:
Bath, Somerset
Posts:
1,054
Plugin Contributions:
2

Re: Total Not Calculating Coupon

I've offered up the code we use to fix this problem, so my only other advice is to use the debug2 variable to see where the problem is occuring.

Absolute

Back, after a 4 year absence! Did you miss me?
Absolute Web Solutions Ltd
Interested in our work? Take a look at one of our sites - The Tech Store

7 Jan 2010, 6:55 AM
#5
fooddudes avatar

fooddudes

New Zenner

Join Date:
Nov 2008
Posts:
33
Plugin Contributions:
0

Re: Total Not Calculating Coupon

Absolute, thanks for your help after making changes to the order totals sort order I was able to get the discounts to calculate correctly.

21 Jan 2010, 2:51 PM
#6
bikeforce avatar

bikeforce

New Zenner

Join Date:
Sep 2009
Posts:
73
Plugin Contributions:
0

Re: Total Not Calculating Coupon

I have a problem relating to this I have implemented Newsletter discount and Discount Coupon. Newsletter 5% discount - Coupon 20% . The Total percentage taken off the subtotal is correct however if i use the numeric value beeing displayed it doesnt make sense.

£18.38
Sub-Total:

£0.00
Free Shipping Options (Free Shipping):

-£3.68
Discount Coupon: BikeForceFriends&Fam :

-£0.78
Newsletter Discount:

£2.05
UK VAT:

£13.78

so the overall percentage ammount is correct - 18.38 * 0.75 = 13.77 ish

however 18.38 -0.78 -3.68 = 13.92

So to the customer that wouldn make sense.

I would also like to show subtotal with out the tax as it seems to the untrained eye like the tax will be added on although it already has been. But I still want to show tax on the product pages...

Does anyone know anything about this?

21 Jan 2010, 3:00 PM
#7
bikeforce avatar

bikeforce

New Zenner

Join Date:
Sep 2009
Posts:
73
Plugin Contributions:
0

Re: Total Not Calculating Coupon

Bikeforce:

so the overall percentage ammount is correct - 18.38 * 0.75 = 13.77 ish

so the overall percentage ammount is correct - 18.38 * 0.75 = 13.785

8 Apr 2010, 5:23 PM
#8
kramergutt avatar

kramergutt

New Zenner

Join Date:
Sep 2008
Posts:
11
Plugin Contributions:
0

Re: Total Not Calculating Coupon

Thanks a ton for the fix Absolute.

I just have one side note. Most people that use the local sales tax might be separating their tax into state and county. Therefore you may already have a tax amount on your order total from the state when you go to calculate the discount before applying the local tax. Therefore you may be taxing the tax. I.E.

Total $10
Shipping $10
Discount $10

Pretax total
GA tax 4% = $.40
Fulton County 3% = (should) $.30

but Fulton Country is actually taxing $10.40 since the GA tax was already added.

To fix this, your line reading:

$order_discount = ($order->info['shipping_cost'] + order->info['subtotal']) - $order->info['total'];

Should read:

$order_discount = ($order->info['shipping_cost'] + order->info['subtotal']) - ($order->info['total'] - $order->info['tax']);

I cannot guarantee this for anyone, but it worked for me.

8 Apr 2010, 5:35 PM
#9
kramergutt avatar

kramergutt

New Zenner

Join Date:
Sep 2008
Posts:
11
Plugin Contributions:
0

Re: Total Not Calculating Coupon

My logic is wrong on my last post. There is more that is needed. I am researching and will post my findings.

8 Apr 2010, 5:59 PM
#10
kramergutt avatar

kramergutt

New Zenner

Join Date:
Sep 2008
Posts:
11
Plugin Contributions:
0

Re: Total Not Calculating Coupon

Absolute,

For my logic fix I removed any non local tax from the order total before your discount calculations and left it out because your code adds it back later.

if ($order->info['tax'] > 0)
{
$order->info['total'] = $order->info['total'] - $order->info['tax'];
}

This seems to work well for me.