I did a bit of work on this problem using the WA sales tax online lookup service and a script called WAStateRateParser.inc.php file from:
http://www.destinationtax.com/washin...tax-lookup.htm
My small contribution is able to accept an address and return the tax rate from WA.
What we need is someone more familiar with zen-cart who can fill in the two bits of unknown information for me. 1. the variable that has the shipping address, and 2. the variable that has zen-cart's tax rate that we can overwrite.
WAStateRateParser.inc.php can be downloaded at the link above.
My contribution is below:
PHP Code:
<?php
// $override_tax_rate is used incase there are any problems connecting to or with the results returned from dor.wa.gov. (value is percent expressed as a decimle 9% = .09)
$override_tax_rate = ".09";
// when set to true only the debug settings below will be used (for testing)
$wa_tax_debug_mode = "true";
// ########## DEBUG SETTINGS ##########
$wa_tax_debug_address = "6500 Linderson way"; // example address
$wa_tax_debug_city = ""; // example city
$wa_tax_debug_zip = "98501"; // example zip 5 or 9 digit is OK
include_once('WAStateRateParser.inc.php'); // Include code from http://www.destinationtax.com/washington-state-destination-tax-lookup.htm by Jerry Higbee
if($wa_tax_debug_mode) { // If in debug mode use example address
$wa_tax_address = $wa_tax_debug_address;
$wa_tax_city = $wa_tax_debug_city;
$wa_tax_zip = $wa_tax_debug_zip;
} else { // !!! This needs to be changed to pass the variables from zen-cart's shipping address !!!
$wa_tax_address = $wa_tax_debug_address;
$wa_tax_city = $wa_tax_debug_city;
$wa_tax_zip = $wa_tax_debug_zip;
}
// Lookup the address
$rate_look = new WAXMLParser($wa_tax_address,$wa_tax_city,$wa_tax_zip);
$rate_look->setSimpleXML();
$my_lookup = $rate_look->getParsedData();
// Get Local, State, and Total tax
$wa_local_tax_rate = floatval($my_lookup['localrate']);
$wa_state_tax_rate = floatval($my_lookup['staterate']);
$wa_tax_rate = ($wa_local_tax_rate + $wa_state_tax_rate);
// check for valid tax rates otherwise go with the highest default rate
$wa_tax_error = 0;
if ($wa_local_tax_rate < 1 && $wa_local_tax_rate > .01) { } else { $wa_tax_error++; }
if ($wa_state_tax_rate < 1 && $wa_state_tax_rate > .06) { } else { $wa_tax_error++; }
if ($wa_tax_error > 0 ) {
$wa_tax_rate = $override_tax_rate;
}
// if in debug mode display returned tax rates for the address given
if($wa_tax_debug_mode) {
echo "WA Tax Rate: <strong>$wa_tax_rate</strong><br>Local Tax Rate: $wa_local_tax_rate<br>State Tax Rate: $wa_state_tax_rate<br><br>";
if ($wa_tax_error > 0 ) { echo "<br>There were errors with the returned tax rates. Default tax rate of $override_tax_rate was used instead.<br>"; }
print_r($my_lookup);
}
// Pass WA tax rate back to zen-cart replacing default tax rate
$unknown_zen_cart_tax_variable = $wa_tax_rate; // !!! This needs to be changed
?>
Bookmarks