I have created a rather easy solution with 2.0.0.0
Based on suggestions listed in this post, I have created a GEO-Zone for New York State (USA--> NY)
Then I created a Tax Rate of 4% called "Sales Tax" (rate doesn't matter since it will be overridden) for that zone
In the tax.php I changed the getRates method like this:
Code: Select all
public function getRates($value, $tax_class_id) {
$tax_rate_data = array();
/* NYS Sales tax specific code */
$sales_tax_name = "Sales Tax";
$postcode = 0; //Fallback value
if (isset($_SESSION['shipping_address']))
$shipping_address = $_SESSION['shipping_address'];
if (isset($shipping_address )) {
$postcode = @$shipping_address['postcode'];
}
if (isset($this->tax_rates[$tax_class_id])) {
foreach ($this->tax_rates[$tax_class_id] as $tax_rate) {
$amount = 0;
if ($tax_rate['name']==$sales_tax_name) {
$amount += ($value / 100 * $this->getSalesTaxRateByPostCode($postcode));
} else /* Do whatever opencart would do normally */
{
if (isset($tax_rate_data[$tax_rate['tax_rate_id']])) {
$amount = $tax_rate_data[$tax_rate['tax_rate_id']]['amount'];
} else {
$amount = 0;
}
if ($tax_rate['type'] == 'F') {
$amount += $tax_rate['rate'];
} elseif ($tax_rate['type'] == 'P') {
$amount += ($value / 100 * $tax_rate['rate']);
}
}
$tax_rate_data[$tax_rate['tax_rate_id']] = array(
'tax_rate_id' => $tax_rate['tax_rate_id'],
'name' => $tax_rate['name'],
'rate' => $tax_rate['rate'],
'type' => $tax_rate['type'],
'amount' => $amount
);
}
}
return $tax_rate_data;
}
public function getSalesTaxRateByPostCode($postcode) {
$getnewtaxrate=$this->db->query("select zip_tax_rate from ziptax where zip_code = '$postcode'");
$newtaxrate=$getnewtaxrate->row['zip_tax_rate'];
if (isset($newtaxrate)) return $newtaxrate;
else return 0;
}
I'm still in the testing process, but so far it looks good...
Let me know what you think, and if I'm missing something (other than the fact, that various zip codes are in multiple counties...