osCmax v2.5 User Manual
Results 1 to 4 of 4

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, ...

      
  1. #1
    osCMax Testing Team
    Join Date
    May 2006
    Posts
    83
    Rep Power
    12


    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&#37;";
          }
          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.

  2. #2
    osCMax Testing Team
    Join Date
    May 2006
    Posts
    83
    Rep Power
    12


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

    Hey Guys, I'm going to resurrect this post because I still haven't found the answer I needed. I put off the implementation. Can someone take a look and possibly point me in the right direction?

  3. #3
    jpf
    jpf is offline
    osCMax Testing Team
    jpf's Avatar
    Join Date
    Sep 2003
    Location
    Manitoba, Canada
    Posts
    2,699
    Rep Power
    22


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

    As I Have mentioned on number of other posts....

    Compare your mod to a clean version of osc - Carefully mark/comment ALL changes. Then compare that marked copy to MAX. Then you can see what need to change.

    List the exact code changes needed and the MAX code.
    JPF - osCMax Fourm Moderator - To contact, post on the forum or click here
    Try out our osCMax at: Live Catalog Demo
    Limited access Admin: Live Admin Demo
    Feel free to add products they way you want and then purchase them -=+=- Sorry nothing will be billed or shipped!

  4. #4
    osCMax Testing Team
    Join Date
    May 2006
    Posts
    83
    Rep Power
    12


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

    Actually, I brute forced my brain, grew some talent and got it figured out! Thanks.

Similar Threads

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •