Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Zip based Tax adds tax for goods, but not shipping


bastille

Recommended Posts

hello

 

With the help of some very kind oscommerce posters I have been able to put together a modfication that will charge a special tax rate based on New York Zip codes (in New York different counties charge different tax rates, yes its a nightmare!)

 

It works for taxable goods but not for shipping. And yes I did make the shipping a taxable item.

 

What the mod does is add a county supplmental tax on top of the state rate (ny is 4.00 and the avereage county levy is 4.25 of so). It does it for goods but won't add the county levy. I'm stumped. Any ideas??

 

Here is the tax mod.....

 

////
// Returns the tax rate for a zone / class
// TABLES: tax_rates, zones_to_geo_zones
 function tep_get_tax_rate($class_id, $country_id = -1, $zone_id = -1, $tax_zip_code ="") {
   global $customer_zone_id, $customer_country_id;

   if ( ($country_id == -1) && ($zone_id == -1) ) {
     if (!tep_session_is_registered('customer_id')) {
       $country_id = STORE_COUNTRY;
       $zone_id = STORE_ZONE;
     } else {
       $country_id = $customer_country_id;
       $zone_id = $customer_zone_id;
     }
   }

   $county_taxquery = tep_db_query("select zip_tax_rate from  " . TABLE_ZIPTAX . " where zip_code =  '" . $tax_zip_code . "'");
   if (tep_db_num_rows($county_taxquery)) {
   $county_tax_query = tep_db_fetch_array($county_taxquery);
   $county_taxrate = $county_tax_query['zip_tax_rate'];
   } else {
   $county_taxrate = "";
   }

   $tax_query = tep_db_query("select sum(tax_rate) as tax_rate from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " za on (tr.tax_zone_id = za.geo_zone_id) left join " . TABLE_GEO_ZONES . " tz on (tz.geo_zone_id = tr.tax_zone_id) where (za.zone_country_id is null or za.zone_country_id = '0' or za.zone_country_id = '" . (int)$country_id . "') and (za.zone_id is null or za.zone_id = '0' or za.zone_id = '" . (int)$zone_id . "') and tr.tax_class_id = '" . (int)$class_id . "' group by tr.tax_priority");
   if (tep_db_num_rows($tax_query)) {
     $tax_multiplier = 0.0;
     while ($tax = tep_db_fetch_array($tax_query)) {
       $tax_multiplier += $tax['tax_rate'];
     }
     if ($county_taxrate != "") {
      $tax_multiplier += $county_taxrate;
     }
     return $tax_multiplier;
   } else {
     return 0;
   }
 }


////

 

any ideas :'(

Link to comment
Share on other sites

bastille,

 

I believe the "problem" is in the includes/modules/order_total/ot_shipping.php. The code there uses tep_get_tax_rate and tep_get_tax_description, but not with the fourth argument ($ship_zip) that is needed for adding the county tax and county tax description.

 

If I add in a zipcode for Nassau it uses the correct county tax and the correct tax description. It just need figuring out how to get the $ship_zip in there. Haven't tried that yet.

      $module = substr($GLOBALS['shipping']['id'], 0, strpos($GLOBALS['shipping']['id'], '_'));

     if (tep_not_null($order->info['shipping_method'])) {
       if ($GLOBALS[$module]->tax_class > 0) {
         $shipping_tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id'], '11507');
         $shipping_tax_description = tep_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id'], '11507');

Link to comment
Share on other sites

I think this works as it should, modified ot_shipping.php in includes/modules/order_total/ approximately lines 48-53:

      $module = substr($GLOBALS['shipping']['id'], 0, strpos($GLOBALS['shipping']['id'], '_'));

     if (tep_not_null($order->info['shipping_method'])) {
       if ($GLOBALS[$module]->tax_class > 0) {
         $shipping_tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id'], $order->delivery['postcode']);
         $shipping_tax_description = tep_get_tax_description($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id'], $order->delivery['postcode']);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...