Jump to content

Dealing with tax for product attributes and combinations


Recommended Posts

Tax in Prestashop can be a bit confusing, but there is one area where it is especially so (in my opinion) which is product attributes and combinations. Let's say you have a product that comes in different varieties which has a base price of $10. One of the varieties is $5 more expensive. So you enter the product in your catalog and configure that combination to have an increase impact on price of $5. Now here is what I would expect: if you select that combination, it would show a pre-tax price of $15, and assuming a 10% tax rate a price of $16.50. However, the way Prestashop currently works is that the pre-tax price will be $14.50 and the tax-included price will be $16.00. The reason why is because the attribute price portion of the total price (in this case $5) as entered in the catalog is considered to already include tax (regardless of how else you have tax configured). So for the pre-tax price, it is subtracting the appropriate tax from the attribute price portion and for tax-included, it's adding tax only to the base price portion.

No disrespect to the developers as I really admire what they've done with Prestashop, but I think this quirk is inconsistent, confusing and makes the product catalog difficult to maintain (especially if your tax rate ever changes, you'd have to not just change the tax rate in one place, but in all the attribute prices for all the product combinations). Fortunately it's a quick and easy change to make it so that the attribute price is also considered to be pre-tax like everything else.

In Product.php (under prestashop/classes), change line 1096 (in version 1.1)
from:

$price_ht = $price + ($attribute_price / (1 + ($tax / 100)));


to:

$price_ht = $price;




and change line 1161
from:

$price += $usetax ? $result['attribute_price'] : ($result['attribute_price'] / (1 + ($tax / 100)));


to:

$price += $usetax ? ($result['attribute_price'] / (1 - ($tax / 100))) : $result['attribute_price'];



You might also want to go into AdminProducts.php under admin/tabs to remove that asterisk notation that the attribute price includes tax on or around line 2135.

Now all the prices you enter in the catalog will consistently be treated as pre-tax values and you should get the expected behavior. Hopefully that's helpful.

Link to comment
Share on other sites

  • 2 months later...

Here is more information - I have reported this as a bug to the Prestashop developers - here is what I found regarding PS 1.2:

Prestashop is passing incorrect state tax to Paypal. The issue lies in the order in which the computation is completed (note PS is using TWO different tax computations in PS 1.2) and what data is passed to Paypal.
For our example, we are buying 10 items that are $1.50 at a 9.75% State tax rate.
Method one of computing (which PS uses in the cart): unit price*qty*tax rate for our example {1.50 * 10} = 15 * 1.0975= $16.46 product with tax
Method Two (which is on the product pages and is passed along to Paypal): unit price * tax rate * qty for our example [1.50 * 1.0975} = 1.65 * 10 = $16.50 product with tax
I took pictures of this if you would like.
Usually in the US, the state tax is computed by taking the complete taxable product subtotal and then multiplying by the state tax rate.
By trying to compute the tax the earlier stage, the Paypal cart is charging too much for tax.
Method 1 is closer to US tax rate computation than Method 2.
Thank you
By diamond204 on 01 Jul 2009 at 10:50 (UTC+1)

Link to comment
Share on other sites

I've not dug into 1.2 yet but that's on my list of things to do. The problem you describe is a rounding issue. It doesn't really matter if it's calculated unit price * quantity * tax rate or unit price * quantity * tax rate. That is, it doesn't matter unless you're rounding the figure too soon. In your example, method two should be (1.50 * 1.0975) = 1.64625 * 10 = 16.46. Sounds like you've reported the bug appropriately though.

As for tax on product attributes and combinations in 1.2, I'll update this thread as necessary once I get it installed and running.

Link to comment
Share on other sites

Hi again,

The frustrating thing with the "bug" is that the total with tax that Prestashop 1.2 displays in the cart with lets say about 10+ items is different than what Paypal displays as a total. It usually is a few cents off - of course this is a big issue having the two numbers being different even if it is only a few cents. Very frustrating. I hope there is a solution out there.

Link to comment
Share on other sites

I've not dug into 1.2 yet but that's on my list of things to do. The problem you describe is a rounding issue. It doesn't really matter if it's calculated unit price * quantity * tax rate or unit price * quantity * tax rate. That is, it doesn't matter unless you're rounding the figure too soon. In your example, method two should be (1.50 * 1.0975) = 1.64625 * 10 = 16.46. Sounds like you've reported the bug appropriately though.

As for tax on product attributes and combinations in 1.2, I'll update this thread as necessary once I get it installed and running.


Yes I do believe that Prestashop 1.2 does the rounding too early - it actually rounds as you add product into your cart, not at checkout. That may be what is causing me issues - I think alot of people will be shocked to see this when they upgrade their shops to 1.2 . I hope there is a way to fix easily in the code.
Link to comment
Share on other sites

  • 1 month later...

Ubiquitous, I think the changes you need to make are :
in classes\product.php
line 1096 from
$price_ht = $price + ($attribute_price / (1 + ($tax / 100)));
to
$price_ht = $price + $attribute_price;
and
line 1161 from
$price += $usetax ? $result['attribute_price'] : ($result['attribute_price'] / (1 + ($tax / 100)));
to
$price += $usetax ? ($result['attribute_price'] * (1 + ($tax / 100))) : $result['attribute_price'];

For the first change, it allows a price reduction (sale) on a product that has a combination related price increase, if you don't put this, the price reduction will calculated without the combination price increase.

For the second change, it is just a mathematical formula mistake.

I work with Presta in the US, we need to use state tax, all product need to be displayed without tax until the last step of the checkout (payment) were I added the cart summary with tax. Also because of exception in NY, we use the product level tax by specifying in the NY state that we use the product tax, for example, this allows us not to charge tax for NY for product < $110. This would not work with exceptions in more than one state but is enough for most stores. I know some tax issue were changed in 1.2 but I have not checked it yet as I know some changes will also be necessary. I now have a good tax less version (until last step of checkout) handling combination price increase, price reduction and vouchers and feel free to ask me if you have any question at [spam-filter]@manhatech.com. I love Presta but if they do not adapt their system to to the world they will loose a lot of markets...having said that, grats to the Presta team for still a great product.

Link to comment
Share on other sites

  • 4 weeks later...

I need to find a code line to add attribute tax to price given. I got following this post to add attribute tax correctly to the cart but it does not show it in the product price. Here there is an image of my problem

7,62 = main + tax main + attribute
7,90 = main + tax main + attribute + tax attribute

My shop sales with and without tax, depending on the buyer' state

Do you know how to get to this code line???

Excuse my english, i am spanish

12011_iJFmqM03u7iTXvXX7Eue_t

Link to comment
Share on other sites

  • 3 weeks later...

PS v1.2 version of youbiquitous's original post.

This will add any applicable state taxes for a product combination/attribute.
I have not used this to see if decreases in base price work out correctly.
Also, it does not work correctly if you have pricing entered in on the info tab (leave all values at 0). You can work around this by having an 'original' or 'no option' option in your attribute group.
You can, however, have reduction amounts, and the product tax *should* work (not 100% sure).
I was in a hurry to get this working for my store and didn't put much time into getting it 100%. I might come back to it later to finish.

First of all, make a copy of all edited files and rename it ..bak, in case you ever want to refer back to the unaltered code.

*** in prestashop/classes/Product.php
line 1267, change this

$price += $attribute_price;

*** to this

$price += ($attribute_price + ($attribute_price * ($tax / 100)));

*** in prestashop/product.php
lines 311 to 316, change this

$smarty->assign(array(
'currencySign' => $currency->sign,
'currencyRate' => $currency->conversion_rate,
'currencyFormat' => $currency->format,
'currencyBlank' => $currency->blank)
);

*** to this (adds another line, so now we are 311 to 317)

$smarty->assign(array(
'currencySign' => $currency->sign,
'currencyRate' => $currency->conversion_rate,
'currencyFormat' => $currency->format,
'currencyBlank' => $currency->blank,
'stateVariableTax' => $tax)
);

*** in prestashop/themes//product.tpl
insert a line at line 11 and add this

var stateVariableTax = {$stateVariableTax};

*** the surround code will look like this (lines 9 to 13)

var currencyFormat = '{$currencyFormat|intval}';
var currencyBlank = '{$currencyBlank|intval}';
var stateVariableTax = {$stateVariableTax};
var taxRate = {$product->tax_rate|floatval};
var jqZoomEnabled = {if $jqZoomEnabled}true{else}false{/if};

*** in prestashop/themes//js/product.js
line 227, change this

var tax = noTaxForThisProduct ? 1 : ((taxRate / 100) + 1);

*** to this

var tax = noTaxForThisProduct ? 1 : (((taxRate + stateVariableTax) / 100) + 1);

*** in the same file
lines 246 and 247, change this

var priceProduct = productPriceWithoutReduction2 - priceReduct;
var productPricePretaxed = (productPriceWithoutReduction2 - priceReduct) / tax;

*** to this

var priceProduct = (productPriceWithoutReduction2 - priceReduct) * tax;
var productPricePretaxed = (productPriceWithoutReduction2 - priceReduct);

*** in the same file

delete or comment out (//) line 252

Link to comment
Share on other sites

  • 1 year later...

Hi - thanks for a very interesting - and indeed valid post! The way Presta handles tax for attributes is truly odd!

making it very difficult to deal with annual price and indeed these days VAT changes.

Am running 1.3.2.3 (final) the above code changes original code is different in this version - anyone have updated code for this?
thanks
Baz

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

Tax in Prestashop can be a bit confusing, but there is one area where it is especially so (in my opinion) which is product attributes and combinations. Let's say you have a product that comes in different varieties which has a base price of $10. One of the varieties is $5 more expensive. So you enter the product in your catalog and configure that combination to have an increase impact on price of $5. Now here is what I would expect: if you select that combination, it would show a pre-tax price of $15, and assuming a 10% tax rate a price of $16.50. However, the way Prestashop currently works is that the pre-tax price will be $14.50 and the tax-included price will be $16.00. The reason why is because the attribute price portion of the total price (in this case $5) as entered in the catalog is considered to already include tax (regardless of how else you have tax configured). So for the pre-tax price, it is subtracting the appropriate tax from the attribute price portion and for tax-included, it's adding tax only to the base price portion.

 

No disrespect to the developers as I really admire what they've done with Prestashop, but I think this quirk is inconsistent, confusing and makes the product catalog difficult to maintain (especially if your tax rate ever changes, you'd have to not just change the tax rate in one place, but in all the attribute prices for all the product combinations). Fortunately it's a quick and easy change to make it so that the attribute price is also considered to be pre-tax like everything else.

 

In Product.php (under prestashop/classes), change line 1096 (in version 1.1)

from:

$price_ht = $price + ($attribute_price / (1 + ($tax / 100)));

to:

$price_ht = $price;

 

 

and change line 1161

from:

$price += $usetax ? $result['attribute_price'] : ($result['attribute_price'] / (1 + ($tax / 100)));

to:

$price += $usetax ? ($result['attribute_price'] / (1 - ($tax / 100))) : $result['attribute_price'];

 

You might also want to go into AdminProducts.php under admin/tabs to remove that asterisk notation that the attribute price includes tax on or around line 2135.

 

Now all the prices you enter in the catalog will consistently be treated as pre-tax values and you should get the expected behavior. Hopefully that's helpful.

 

Hello,

I have similar issue with attributes combinations and incorrect prices in my default theme. I use 1.4.6 and 1.4.7 PS. I cannot find your line of the code for prices to fix it. Should I be looking somewhere else? Please help. Thanks. OlegD

Link to comment
Share on other sites

×
×
  • Create New...