I've been reading numerous threads about this, but have been unable to find a thread that actually solves my specific issue. I am using OpenCart for a small business that sells products in Florida, USA. I am having an issue with the sales tax. For Florida, we only need to charge sales tax to customers within Florida. Anywhere in the USA outside of Florida, no sales tax needs to be applied.
Under admin, I have set up a "Taxable Goods" category, set up a Geo Zone with only Florida, USA in it, applied the "Taxable Goods" category to my products, etc. and so on. I'm fairly certain I've set up everything correctly there.
I've made a test login to make sure that the sales tax setup is working right. First, I made an address with Florida as the state. As expected, the sales tax showed up. Good so far...
Then I made an address with another random state in the USA and went to check out and... uh oh, there's the sales tax. I tried changing the address to another country; sales tax still showed up. I started digging and debugging in the code and it appears the issue stems from 'tax.php' under the 'cart' directory in the 'library' directory:
Code: Select all
<?php
class Tax {
var $taxes = array();
function __construct(&$locator) {
$this->config =& $locator->get('config');
$this->database =& $locator->get('database');
$this->session =& $locator->get('session');
// ***Issue is here***
$address_info = $this->database->getRow("select country_id, zone_id from address where address_id = '" . (int)$this->session->get('shipping_address_id') . "' and customer_id = '" . (int)$this->session->get('customer_id') . "'");
// ***Issue ends here***
if ($address_info) {
$country_id = $address_info['country_id'];
$zone_id = $address_info['zone_id'];
} else {
$country_id = $this->config->get('config_country_id');
$zone_id = $this->config->get('config_zone_id');
}
$results = $this->database->getRows("select tr.tax_class_id, sum(tr.rate) as rate, tr.description from tax_rate tr left join zone_to_geo_zone z2gz on (tr.geo_zone_id = z2gz.geo_zone_id) left join geo_zone gz on (tr.geo_zone_id = gz.geo_zone_id) where (z2gz.country_id = '0' or z2gz.country_id = '" . (int)$country_id . "') and (z2gz.zone_id = '0' or z2gz.zone_id = '" . (int)$zone_id . "') group by tr.tax_class_id");
foreach ($results as $result) {
$this->taxes[$result['tax_class_id']] = array(
'rate' => $result['rate'],
'description' => $result['description']
);
}
}
function calculate($value, $tax_class_id, $calculate = TRUE) {
if (($calculate) && (isset($this->taxes[$tax_class_id]))) {
return $value + ($value * $this->taxes[$tax_class_id]['rate'] / 100);
} else {
return $value;
}
}
function getRate($tax_class_id) {
return (isset($this->taxes[$tax_class_id]) ? $this->taxes[$tax_class_id]['rate'] : NULL);
}
function getDescription($tax_class_id) {
return (isset($this->taxes[$tax_class_id]) ? $this->taxes[$tax_class_id]['description'] : NULL);
}
function has($tax_class_id) {
return isset($this->taxes[$tax_class_id]);
}
}
?>
Code: Select all
function get($key) {
return (isset($_SESSION[$key]) ? $_SESSION[$key] : NULL);
}
Since there are no records in the address table with 0 as the address_id, the SQL query returns nothing. If you follow the original code past my comments a little more:
Code: Select all
if ($address_info) {
$country_id = $address_info['country_id'];
$zone_id = $address_info['zone_id'];
} else {
$country_id = $this->config->get('config_country_id');
$zone_id = $this->config->get('config_zone_id');
}
I haven't had time to dig deeper and figure out why $_SESSION['shipping_address_id'] is never set in the code, but I figured I'd post it here to see if anyone else has had a similar issue or it if has been fixed already.