BUG: US/State specific Tax applied to international user without a state

Started by thebeuving, September 07, 2012, 23:51:47 PM

Previous topic - Next topic

thebeuving

In our virtuemart install (v2.0.8e) on Joomla 2.5.6 we have a sales tax rule setup Idaho (US). If an international user from a country that has states fails to select a state Idaho sales tax is applied.

Here is our tax config:

Published = Yes
Ordering = 0
Description = Empty
Type of Arithmetic Operation = Tax per bill
Math Operation = -%
Value = 6.00000
Currency = USD
Product Category = Empty/All
Shopper Groups = Empty/All
Country = United States
State = Idaho
Visible for Shopper = Yes
Visible for vendor = Yes
Start Date = Empty
End Date = Empty
Founded in 2005, Khoza Technology, Inc. formerly SRI Hosting, Inc. is an IT services company with proven success building hosted services, applications, and websites.

https://khoza.com

jjk

Quote from: thebeuving on September 07, 2012, 23:51:47 PM
Math Operation = -%

Normally (I think :-) this should be +%. Most american shops display the price without the tax, which only is added if the shopper selects a state in which the tax applies (Idaho in your case).
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

thebeuving

Quote from: jjk on September 08, 2012, 13:18:08 PM
Quote from: thebeuving on September 07, 2012, 23:51:47 PM
Math Operation = -%

Normally (I think :-) this should be +%. Most american shops display the price without the tax, which only is added if the shopper selects a state in which the tax applies (Idaho in your case).

Good catch that was a typo, I do have it confirgured as "+%" but it automatically adds tax in the shopping cart and only removes it after a user selects a state other than Idaho.

Any thoughts on why that is happening would be great.

David
Founded in 2005, Khoza Technology, Inc. formerly SRI Hosting, Inc. is an IT services company with proven success building hosted services, applications, and websites.

https://khoza.com

jjk

Do you get the same after updating to VM2.0.10? (2.0.11 very soon)
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

thebeuving

I just tested in svn r6454 and the problem is the same. The problem is in calculationh.php the function testRulePartEffecting returns true if $data is not set.

I think the easiest solution is just to cast $this->_deliveryState and $this->_deliveryCountry to integers in the setCountryState function.


                if (!empty($this->_cart->ST['virtuemart_state_id'])) {
                        $this->_deliveryState = (int)$this->_cart->ST['virtuemart_state_id'];
                } else if (!empty($cart->BT['virtuemart_state_id'])) {
                        $this->_deliveryState = (int)$this->_cart->BT['virtuemart_state_id'];
                }


That way if no state is selected it will be set to 0 since 0 isn't a valid id in the database this should be safe. Also this will also fix the problem some people are having with state specific taxes all being listed out before a user sets there state.

Let me know if this is something we can get into the code base.

Thanks,
David
Founded in 2005, Khoza Technology, Inc. formerly SRI Hosting, Inc. is an IT services company with proven success building hosted services, applications, and websites.

https://khoza.com

Milbo

Fixing something with a cast sounds always good. I added it to the core.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

razor7

Thanks!, patched my VM 2.0.10 file calculationh.php, function testRulePartEffecting but it didn't fixed it, the tax is applyed to all customers, no matter wich country they are.

I have set up a Florida VAT, see screenshot for details

Best Regards!

[attachment cleanup by admin]
MGS Creativa - VirtueMart Payment Plugin Experts
http://www.mgscreativa.com

Take a look at our downloads section for VirtueMart payment plugins and mouch more!
http://www.mgscreativa.com/en/online-store

razor7

Well, I had to modify function gatherEffectingRulesForBill of calculationh.php, added cast for $this->_deliveryState on line 870 and it worked!

Quote
      $hitsDeliveryArea = $this->testRulePartEffecting($states, (int)$this->_deliveryState);
MGS Creativa - VirtueMart Payment Plugin Experts
http://www.mgscreativa.com

Take a look at our downloads section for VirtueMart payment plugins and mouch more!
http://www.mgscreativa.com/en/online-store