osCommerce and osCMax shopping cart software forums

Shopping Cart Software

osCommerce with teeth!

 

Adding tax based on Zip need help with tax.php class file..

This is a discussion on Adding tax based on Zip need help with tax.php class file.. within the osCMax v2 Customization/Mods forums, part of the osCMax v2.0 Forums category; Hi Guys, I'm trying to implement a tax by zip code modification. There are a few of them out there, ...


Go Back   osCommerce and osCMax shopping cart software forums > osCMax v2.0 Forums > osCMax v2 Customization/Mods

Register FAQ Members List Calendar Mark Forums Read


Free community membership! Fast easy FREE membership
Reply

 

LinkBack Thread Tools
  #1  
Old 05-07-2008, 11:12 AM
osCMax Testing Team
 
Join Date: May 2006
Posts: 34
Thanks: 0
Thanked 3 Times in 3 Posts
Rep Power: 0
fourmat
Default Adding tax based on Zip need help with tax.php class file..

Hi Guys,

I'm trying to implement a tax by zip code modification. There are a few of them out there, but the NY County Tax Rate contribution seemed to do exactly what I needed.

osCommerce Community Add-Ons

The instructions are pretty straight forward, but there are some major differences in the includes/functions/general.php files between MS2.2 and OSCMax RC3.

Specifically, the function tep_get_tax_rate( function is broken off into the /includes/classes/tax.php file. There are changes in the coding that are throwing me for a loop. This is the only location that there seems to be a major difference.

I was wondering if someone might be able to take a peek at the difference in code and help me make the adjustments.

These are the instructions for making the changes:

Code:
in includes/functions/general.php

CHANGE TO:
--------------------------------------------------------------------------------
<?php
////BOF New York State Tax Modification
// 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;
      }
    }

		$tax_zip_code = trim($tax_zip_code); // This trims any spaces they may have entered after/begin the zip
		if(strlen($tax_zip_code) > 5){
			$tax_zip_code = substr($tax_zip_code,0,5); // This cuts the zip down to the first 5 digits
		}

    $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 {

if ($county_taxrate != "") {
	      $tax_multiplier = $county_taxrate;
		return $tax_multiplier;
      }
      else
	{
	return 0;
	}

      
    }
  }


////
// Return the tax description for a zone / class
// TABLES: tax_rates;
/* test */
  function tep_get_tax_description($class_id, $country_id, $zone_id, $tax_zip_code = "") {
    $county_taxquery = tep_db_query("select zip_tax_rate, zipcounty 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 = number_format($county_tax_query['zip_tax_rate'], 2, '.', '');
    $county = $county_tax_query['zipcounty'];
    } else {
    $county_taxrate = "";
    $county = "";
    }

    $tax_query = tep_db_query("select tax_description 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 . "' order by tr.tax_priority");
    if (tep_db_num_rows($tax_query)) {
      $tax_description = '';
      while ($tax = tep_db_fetch_array($tax_query)) {
        $tax_description .= $tax['tax_description'] . ' + ';
      }
      $tax_description = substr($tax_description, 0, -3);
      if ($county_taxrate != "") {
	       $tax_description .= " + $county County Tax $county_taxrate%";
      }
      return $tax_description;

    } else {
	
	if ($county_taxrate != "") {
	      $tax_description = "$county County Tax $county_taxrate%";
		return $tax_description;

      }
	else {
      return TEXT_UNKNOWN_TAX_RATE;
	}
    }
  }

                                    ////////EOF New York State Tax Modification

-----------------------------------------------------------------

IN the OSCMAX General.php:

Code:
////
// 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) {
// BOF: MOD - Separate Pricing Per Customer, show_tax modification
    global $customer_zone_id, $customer_country_id, $osC_Tax, $sppc_customer_group_tax_exempt;

     if(!tep_session_is_registered('sppc_customer_group_tax_exempt')) {
     $customer_group_tax_exempt = '0';
     } else {
     $customer_group_tax_exempt = $sppc_customer_group_tax_exempt;
     }

     if ($customer_group_tax_exempt == '1') {
	     return 0;
     }
 return $osC_Tax->getTaxRate($class_id, $country_id, $zone_id);
}

// EOF: MOD - Separate Pricing Per Customer, show_tax modification


////
// Return the tax description for a zone / class
// TABLES: tax_rates;
  function tep_get_tax_description($class_id, $country_id, $zone_id) {
// BOF: MOD - Separate Pricing Per Customer, show_tax modification
  	 global $osC_Tax;
  	 return $osC_Tax->getTaxRateDescription($class_id, $country_id, $zone_id);
// EOF: MOD - Separate Pricing Per Customer, show_tax modification
    }


And in the OSCMax class/tax.php:



Code:
 class osC_Tax {
    var $tax_rates;

// class constructor
    function osC_Tax() {
      $this->tax_rates = array();
    }

// class methods
    function getTaxRate($class_id, $country_id = -1, $zone_id = -1) {
// LINE ADDED: Bugfix 0000036 
    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;
      }
    }

      if (isset($this->tax_rates[$class_id][$country_id][$zone_id]['rate']) == false) {
        $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 = 1.0;
          while ($tax = tep_db_fetch_array($tax_query)) {
            $tax_multiplier *= 1.0 + ($tax['tax_rate'] / 100);
          }

          $tax_rate = ($tax_multiplier - 1.0) * 100;
        } else {
          $tax_rate = 0;
        }

        $this->tax_rates[$class_id][$country_id][$zone_id]['rate'] = $tax_rate;
      }

      return $this->tax_rates[$class_id][$country_id][$zone_id]['rate'];
    }

    function getTaxRateDescription($class_id, $country_id, $zone_id) {
      if (isset($this->tax_rates[$class_id][$country_id][$zone_id]['description']) == false) {
        $tax_query = tep_db_query("select tax_description 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 . "' order by tr.tax_priority");
        if (tep_db_num_rows($tax_query)) {
          $tax_description = '';

          while ($tax = tep_db_fetch_array($tax_query)) {
            $tax_description .= $tax['tax_description'] . ' + ';
          }

          $this->tax_rates[$class_id][$country_id][$zone_id]['description'] = substr($tax_description, 0, -3);
        } else {
          $this->tax_rates[$class_id][$country_id][$zone_id]['description'] = TEXT_UNKNOWN_TAX_RATE;
        }
      }

      return $this->tax_rates[$class_id][$country_id][$zone_id]['description'];
    }
  }

The biggest issue that I have in understanding this is that there is a difference in coding where the class uses a lot of "this->" statement. I'm not sure how those work in comparison to the standard "return=0" type of statement. Any help would be greatly appreciated. Thanks!

Last edited by fourmat; 05-07-2008 at 11:14 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
State Tax by Zip Code simplex osCMax v2 Customization/Mods 1 03-18-2008 09:17 AM
Tax,Zones,Tax Class and Tax Rates soibaal osCMax v2 Features Discussion 3 07-31-2007 10:25 PM
New York State Tax By Zip Code michael_s New osCommerce Contributions 0 06-16-2007 03:04 AM
County Sales Tax by Zip Code michael_s New osCommerce Contributions 0 03-27-2007 09:11 PM
Changing default TAX class when adding new products fuzzyphil osCMax v1.7 General Mods Discussion 0 07-28-2005 10:42 PM


All times are GMT -8. The time now is 02:52 PM.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO
http://www.oscmax.com/forums/
Copyright 2008 osCMax