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!





LinkBack URL
About LinkBacks







Bookmarks