uShop English (U.S.) for 179!

uStorekeeper English (U.S.) for 149!

 Tech Support
       Support Policy
       Knowledge Base
       Reference Sites
       Software Piracy
       Legal Notices
       Privacy Policy
       Reseller Info
       Contact Us
       Site Map
different tax rate for every product

Knowledge Base Lobby : uShop Support Conference : Tax, Shipping, and Handling Questions
Jul-19-18 05:42 AM EST
Original Message
different tax rate for every product
Author Juan Cimadevilla on 10-01-2002 at 18:32 (EST)

I have some products in the store with different tax rates, books (4% of VAT) and other items with the regular 16% of VAT applied in my country. (In all EU countries there are many VAT rates depending on the kind of product)

I'd like to be able to use the two tax ratios in mixed orders, i.e.:

1 - "book" - 10.00 (VAT 4% = 0.40)
1 - "regular item" - 10 (VAT 16% = 1.60)

Subtotal= 20.00
VAT = 2.00 (0.40+1.60)
Total= 22.00

Furthermore for international orders the VAT must be 0.00

I have configured the system to 16% VAT to local orders and 0.00 to international ones, but as the applets does not have a tax modifier I cannot set a different TAX ratio for each product.

I'm wondering if I can modify the in any way to use some other applet's value (maybe weight or shipping modifier) as tax modifier.


Table Of Contents
  RE: different tax rate for every product Bill Weiner, 2002-10-02 05:48:01 (1)
            RE:RE: different tax rate for every product Juan Cimadevilla, 2002-10-03 18:08:53 (2)
                 RE: different tax rate for every product Bill Weiner, 2002-10-04 05:49:28 (3)

Messages In This Discussion
         1. RE: different tax rate for every product
        Author Bill Weiner on 10-02-2002 at 05:48 (EST)
uShop does have an option to specify that "tax has already been included in the price of the products". This can be accomplished via the use of the $tax_inclusive setting located near the top of the file. By editing the file and changing the $tax_inclusive setting to "YES":

$tax_inclusive = "YES";

... when setting up your store, you can include the tax when specifying the price in each of the products... then upon checkout, the "Tax" total in the shopping cart will be calculated in reverse so that the tax total is displayed as the total tax that was added based on the tax rate.

As you've noticed, however, the tax inclusive option does run into a problem if your products have different tax rates.

Now for your particular requests, here is what I would suggest:

STEP 1: In your applets, try setting the "taxable" parameter of any product(s) that have 4% tax to "NO". Leave the taxable parameter of all other 16% tax products set to "YES".

STEP 2: Make a backup of your current script... just in case.

STEP 3: Open your script with any text editor such as WordPad.

STEP 4: Do a search on the following line:

$tax_inclusive = "NO";

And change it to:

$tax_inclusive = "YES";

STEP 5: Do a search on the following line:

sub calculate_totals

This will get you to the start of the subroutine that calculates all of the totals for the shopping cart.

STEP 6: Locate the following section of code in that subroutine:

if ($tax_inclusive =~ /yes/i)
$totals_tax = ($totals_total / (1.0 + ($tax_rate_value / 100.0))) * ($tax_rate_value / 100.0);
$totals_tax_with_shipping = ($totals_total_with_shipping_tax / (1.0 + ($tax_rate_value / 100.0))) * ($tax_rate_value / 100.0);

(It will be located at the very bottom of that subroutine.)

(Watch out for line wraps... as the above lines will probably wrap onto multiple lines in this forum.)

STEP 7: Try replacing the above lines, with these lines instead:

if ($tax_inclusive =~ /yes/i)
$totals_tax = ($totals_taxable_subtotal / (1.0 + ($tax_rate_value / 100.0))) * ($tax_rate_value / 100.0);
$totals_tax = $totals_tax + (($totals_nontaxable_subtotal / 1.04) * 0.04);
$totals_tax_with_shipping = ($totals_total_with_shipping_tax / (1.0 + ($tax_rate_value / 100.0))) * ($tax_rate_value / 100.0);

(Note: Again watch out for line wrap.)

STEP 8: Save the TEXT if your editor asks... and try it out!

NOTE 1: I did not test the above code myself, so be sure to test it out. Let me know if you have any problems.

NOTE 2: Before changing the "taxable" setting of all of your 4% applets to "NO"... try it out on just one or two first... and see how it works out.

There are other ways to approach this, but the above solution requires the fewest modifications.
                 2. RE:RE: different tax rate for every product
                Author Juan Cimadevilla on 10-03-2002 at 18:08 (EST)

Thank you for the fast response. I have made the sugested changes, but it did not work as expected. I have three problems:

1st problem: The calculation is bad for NO taxable items because I have the prices without tax, and the tax is calculated from a total "tax included",
i.e. what I want is:
4%item= 10
subtotal= 10
tax= 0.4 (4%)
total= 10.4

what I get is:
4%item= 10
subtotal= 10
tax= 0.38 (4% of 9.62 instead 4% of 10)
Total= 10

If I change the price of the 4% items to tax included it will work, i.e. 10.4 instead 10, but as I have taxable and not taxable customers is not a good idea. All prices must be tax excluded.

2nd problem: I have added both, a 4%item and a 16%item in a single order and only the 4% of "detached" tax has been shown in the tax_subtotal. Furthermore the subtotal and total are the same (the 16% tax has been ignored). i.e. I get:

4%item - EUR 12.02*
16%item - EUR 54.00
subtotal: EUR 66.02
IVA: EUR 0.46
Total: 66.02

and I'd like to have:
4%item - EUR 12.02*
16%item - EUR 54.00
subtotal: EUR 66.02
IVA: EUR 9.12 (0.48+8.64)
Total: 75.14

3rd problem: The tax is the same for local and international orders. I'm using the "state" to add the tax, if you place an order from Madrid or Barcelona the tax must be added, if you place the order from Paris or Lisboa it must be not. I can use the country instead state, but there are three "tax-free" states (provinces) in Spain (Ceuta, Melilla and Canary Islands)

I actually have in tax states: madrid=16%,barcelona=16%,... (up to 49 provinces)

                         3. RE: different tax rate for every product
                        Author Bill Weiner on 10-04-2002 at 05:49 (EST)
Oh, the above modification was for if you had some items with 4% tax and some items with 16% tax. I was not aware that you had items with 0% tax also... so no, that modification will not work for you.

To be able to handle tax inclusive items with three (or more) different tax rates, that would require utilizing the weight or shipping modifier (as you mentioned in your previous posting) and making some rather involved modifications to the "calculate_totals" subroutine... which you can try for yourself, but since the modifications would be so involved, I won't be able to post all the necessary code changes through this forum.

(I would suggest maybe specifing the exact tax amount as the "weight" of each applet... so then in the "calculate_totals" subroutine... the total weight will equal the total tax... and you can adjust the other totals accordingly from there.)

Another easier option would be to do the following:

STEP 1) Specify the prices of all of your products with the different taxes already included.

STEP 2) Put a note on your pages (using regular HTML) that tax has already been included in the price of the products.

STEP 3) In your uShopOrderButton applet, set the "cart_show_totals" parameter to "NO":

< PARAM NAME="cart_show_totals" VALUE="NO" >

The last step will cause only the subtotal to be displayed in the final shopping cart... so you don't have to worry about the total tax display. Of course, this will also hide any Shipping & Handling charges, so that may or may not work for you.

As for subtracting the tax charges from tax inclusive items for certain counties/countries... handling that with the tax inclusing option is really not possible... unless you just have two different stores... one that has the items taxed ... and a seperate store for customers that don't have to pay tax. This may or may not be practicle based on the number of items that you have in your store.

If you need any assistance reworking the "calculate_totals" subroutine to meet your needs, then send us a support request at:

And we may be able to assist via email. (This forum is not condusive for posting code/html.)

© 2003 Microburst Technologies, Inc.