If this is your first visit, check our documentation. To post, register or login.
Forums / Bug Reports / coupon percentage off, free shipping and taxes

coupon percentage off, free shipping and taxes

Started by balihr on 27 Jul 2015, 6:32 PM · Views: 1,758

Results 1 to 8 of 8
27 Jul 2015, 6:32 PM
#1
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,817
Plugin Contributions:
24

coupon percentage off, free shipping and taxes

I've just noticed something weird in the discounts calculation and am hoping that someone might tell me if I'm missing something or if it's a bug...

Using 1.5.4 clean install. For simpler calculation, I've changed Florida tax rate to 10%.
Created new coupon: 20% off and free shipping.
Added item in cart (Taxable Goods). Using Flat Rate $5.00 (Taxable Goods). Going to checkout using a Florida address.

Here are my totals before applying the coupon:
Sub-Total: 110.97
Flat Rate (Best Way): $5.00
FL TAX 10.0%: $11.60
Total: $127.57

All good.
Now I apply the coupon and this is what I get:
Sub-Total: 110.97
Flat Rate (Best Way): $5.00
Discount Coupon: test :-$27.19
FL TAX 10.0%: $9.38
Total: $98.16

I think this is wrong, isn't it? It seems to be adding shipping tax even though shipping is free.
110.97 + 5 - (22.19 + 5) = 88.78
10% tax on 88.78 should be 8.88. It seems that it's still adding the 0.50 tax from shipping.

Here's what I've done to fix it:
includes/modules/order_total/ot_coupon.php line 419-429

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'];
              $ratio = $od_amount['total']/$orderTotalDetails['orderTotal'];
              // add in Free Shipping
              $od_amount['total'] = $od_amount['total'] + $orderTotalDetails['shipping'];
              $od_amount['tax'] = $orderTotalDetails['shippingTax'];
              if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
                $od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax'];
              }
              break;

replace with:

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
              $od_amount['total'] = $od_amount['total'] + $orderTotalDetails['shipping'];
			  $ratio = $od_amount['total']/$orderTotalDetails['orderTotal'];
              $od_amount['tax'] = $orderTotalDetails['shippingTax'];
              if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
                $od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax'];
              }
              break;

Basically, I just moved the $ratio line. Of course, same "patch" needs to be done for case O.

Now, since this code was written by Ajeh :bow: a long time ago (DiscountCombo_v15B.zip), I'm just not sure if I'm missing something obvious and if it's really supposed to calculate that way OR was it just an oversight and a bug?

My site - Pro ZC Help
My portfolio | My plugins

27 Jul 2015, 10:24 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: coupon percentage off, free shipping and taxes

Using unmodified code I get:
> Sub-Total: $110.97

Flat Rate (Best Way): $5.00
Discount Coupon: 20FREESHIP : -$27.19
FL TAX 10.0%: $8.88
Total: $97.66

What happens if you use the original code without any modifications?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

27 Jul 2015, 10:28 PM
#3
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,817
Plugin Contributions:
24

Re: coupon percentage off, free shipping and taxes

Ajeh:

Using unmodified code I get:

Really? But I WAS using a clean 1.5.4 install. Absolutely no modifications other than tax rate... Demo products.

Let me do another fresh install and try again.

My site - Pro ZC Help
My portfolio | My plugins

27 Jul 2015, 10:37 PM
#4
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,817
Plugin Contributions:
24

Re: coupon percentage off, free shipping and taxes

Oh, I obviously forgot to mention it in my first post - shipping is ALSO set to Taxable Goods. :blush:

It's OK if shipping isn't taxable, but if you change Flat Rate to Taxable Goods, you'll see what I'm talking about.

My site - Pro ZC Help
My portfolio | My plugins

28 Jul 2015, 2:52 AM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: coupon percentage off, free shipping and taxes

On the Modules ... Order Total ... for the Discount Coupon ot_coupon what are your settings?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

28 Jul 2015, 2:56 AM
#6
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,817
Plugin Contributions:
24

Re: coupon percentage off, free shipping and taxes

Standard clean install - I took the 1.5.4 package and did a new install. The ONLY thing I changed was tax rate from 7% to 10%.

To answer your question:
Discount Coupon

This module is installed
true

Sort Order
280

Include Shipping
false

Include Tax
false

Re-calculate Tax
Standard

Tax Class
--none--

My site - Pro ZC Help
My portfolio | My plugins

28 Jul 2015, 6:11 PM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: coupon percentage off, free shipping and taxes

Hate to leave you hanging but we are doing some testing related to this and won't be done for a few more days as if this is a correct change, it also needs to have a similar change on the case 'O' for the same reason ...

So if you can bear with use on this ... :lookaroun

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

28 Jul 2015, 6:25 PM
#8
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,817
Plugin Contributions:
24

Re: coupon percentage off, free shipping and taxes

No worries - I'm already using this as a solution. My client checked with his accountant and this IS the correct calculation. It works for our setup, but it should be tested for different scenarios, of course.

Case 'O' - yeah, that needs the same change. See my initial post. :)

BTW... I'm not a US citizen so I'm not familiar with US laws, but from what I've heard, current calculations present a federal offense (taxes are not something you wanna mess with). You might wanna give this higher priority... :lookaroun

My site - Pro ZC Help
My portfolio | My plugins