# Tax being calculated before discount

Thread began 2/15/2010 9:53 am by adam106173 | Last modified 2/23/2010 5:59 pm by Eric Mittman | 6870 views | 11 replies |

## 2/15/2010 9:53 am  |  #1 adam106173

### Tax being calculated before discount

I have a discount rule being applied to the eCart 4 that works fine. It comes into play when a certain combination of products are ordered. It is a flat rate discount. The problem is tax is being charged to the dollar amount before the discount is taken. I have the tax calculated based on the TotalPrice. It seems like this should work, but it doesn't. Any help would be appreciated.

## 2/16/2010 12:35 pm  |  #2 Eric Mittman

You will want to base the tax on the subtotal for the cart, not the total price. Give this a try and if you continue to have trouble with it post back with your cart page from within the WA_eCart folder.

## 2/16/2010 3:13 pm  |  #3 adam106173

I used "based on items with a specific value" and can't choose sub-total because of that. There are items that tax is charged, and non-taxable items as well, which is why I used this calculation. I've attached the file.

Thank you,

Attached Files
WA_eCart.zip

## 2/17/2010 2:28 pm  |  #4 Eric Mittman

I have taken a look at the cart tax and discount rules. The problem is that tax will be calculated on the total price column. Since the total price for the item does not take into account any discounts you will be taxed on the non discounted amount.

There is another subtotal you could use for the tax, if you choose to base it off of the taxable total then it will take into account the charges and discounts before applying the tax.

The problem with this is that it will still be based on the totalprice of all the items in the cart. The only way that I could think of that would allow this to work for you would be to modify the taxabletotal function so that it only gets the subtotal for the items that have a 1 in the taxable column.

This would allow you to use the taxable total to base the calculation on instead of the one you are using now. To make this change to the taxable total function you would need to locate the function in the WA_eCart_Definition.php file. In here look for this line of code:

php:
``function GetTaxableTotal() {``

In here you will see that the \$taxtotal variable is being set based on the total of the totalprice column. You can replace this line of code with the conditional total code so that it only includes items that have a 1 in the taxable column.

replace this:

php:
``\$taxTotal  = \$this->TotalColumn("TotalPrice");``

with this:

php:
``\$taxTotal  = \$this->TotalColumn("TotalPrice") = \$this->ConditionalTotal("TotalPrice", "Taxable", "1");``

Please give this a try and let us know how it works for you. If you make any changes to your cart this update might be overwritten, so make sure to back up this page after you make the update.

## 2/17/2010 3:47 pm  |  #5 adam106173

Thanks for your help. I ran into an error when I tried to use the code you gave me. I'm sure it's a simple one to figure out, but I thought I'd just ask for more of your help:

Parse error: parse error, unexpected '=' in /home/content/n/j/n/njnla/html/WA_eCart/WA_eCart_Definition_PHP.php on line 410

What do you think? If I remove the = it will destroy the code, right?

## 2/18/2010 2:11 pm  |  #6 Eric Mittman

Sorry about that, I forgot to remove the original value for it, the code on that line should look like this:

php:
``\$taxTotal  = \$this->ConditionalTotal("TotalPrice", "Taxable", "1");``

Give this a try and let us know how it works for you.

## 2/19/2010 8:57 am  |  #7 adam106173

Hi. I tried this code, but it did not work. No errors were generated, it just worked like it currently does by charging tax on the total before discounts. Any other thoughts?

## 2/19/2010 3:40 pm  |  #8 Eric Mittman

The more I think about this the more I question the validity of applying the taxes and discounts like this.

For example, lets say you have a single item in your cart that should be taxed and that items amount is \$5. Lets also assume that you have another \$40 product that does not have tax applied and the user has a coupon that is giving them \$20 off, what value would you apply your tax rate to?

If you applied tax on the \$5 this would be the amount before the discount. You could not subtract the discount amount from this \$5 so you would need some way to determine the discounted item price for the taxable items. Since the discount is not applied on a per item basis you would not be able to do this without an equation to determine how to get the new discounted price for the taxable items. Tax will be charged based on the items price, either discounted or whole. Taking the discount into consideration with the tax does not fit the scenario you are working with.

## 2/22/2010 12:11 pm  |  #9 adam106173

My client sells seminars, which is non-taxable and CD's, which are taxable. She sells maybe 8 CD's and a couple bundles. Three of the CD's are new. The promo is buy one of the new CD's and get each additional new CD at 50% off. All these new CD's are the same price. Since this only applies to the new CD's and this promo can't be mixed with the old CD's, and there's no coupon number to apply - I made a column value representing the on-special products. Depending upon the total of this column value, certain flat rate discounts are applied. This all works perfectly, except for the tax.

If you see my screen shot, the cart shows two cd's that are part of the special with the flat discount being taken off. It also has a seminar in it. The tax should only be based on the two cd's, which it is. But it should be based on the two cd's minus the flat discount, which it isn't.

What do you think?

## 2/22/2010 4:51 pm  |  #10 Eric Mittman

Thanks for the example, I think it illustrates perfectly what I'm getting at here. In the charge rule that is applying the tax how does it know the total to apply tax to? In your example you would want to apply the tax to the discounted amount of the cd's. How does the cart calculate the discounted price of the cd's?

In this specific example you would want to take the price of the cd's minus the discount that is specific to them, then tax that amount. The problem is that this is not how discounts are organized in the cart. You are not actually changing the price of the cd's but you are applying a discount to the subtotal of the cart. To figure out the price that is charged for the cds you would need to take a total of the total price for that item, minus the specific discount. You would need to be able to do this for each item in the cart, essentially calculating the new item price to charge tax on the fly.

This would get very complex depending on the item and discount combinations that you would need to take account for. If you could store the discount price for the items it would be much easier to find the taxable total. Also, if discounts were only given to taxable items you could rely on that to make it easier to write this tax rule.

So in a nutshell the problem is determining the discounted price for the items, applying the tax amount would be very simple if you could determine the proper total first.

## Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

## Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

## Everything else!

Close Window

Account or customer service questions?

Need technical support?

Content

Layout

Ease of use

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Window

## We were unable to retrieve the attached file

Close Window

### Attach and remove files

• Text Formatting
• Insert Element
• Block Formatting
• Cancel
Close Window

Close Window

#### This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --