Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Optimization of tep_get_tax_rate()


Guest

Recommended Posts

  • 2 weeks later...
  • Replies 71
  • Created
  • Last Reply

Top Posters In This Topic

i installed this mod together with order_editor_16a. So when in these last modd I add new product in order, evrything work ok, but in TAX field i have "0". I think it is couse by the tep_get_tax_rate functin. Does anybody know how to fix it?

Link to comment
Share on other sites

Ask in their support thread...it has nothing to do with the tep_get_tax_rate() class port contribution.

 

All changes should have been completed on the catalog side and NOT the admin side. Thus, if there is a tax problem on the admin side it is another contribution.

 

Bobby

Link to comment
Share on other sites

  • 1 month later...

Multi-Store compatibility

 

I am trying to get this to work with Mutli-Stores but having one heck of a time making it work.

 

Here are the MS general.php queries....

 

function tep_get_tax_rate($class_id, $country_id = -1, $zone_id = -1) {
   global $customer_id, $customer_zone_id, $customer_country_id; //rmh M-S_pricing

   if (tep_customer_tax_exempt($customer_id)) { return 0; } //rmh M-S_pricing

   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;
     }
   }
   $classname = 'tax_'.$class_id; //Unique session name for the tax class
   if (tep_session_is_registered('customer_id')) { //Is the customer_id registered?
       $classname .= '_customer'; //Add _customer to the name since it passed the check
       if (!tep_session_is_registered($classname)) { //Is the classname already registered?
           $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)) { //If there are taxes...
             $tax_multiplier = 1.0;
             while ($tax = tep_db_fetch_array($tax_query)) {
                       $tax_multiplier *= 1.0 + ($tax['tax_rate'] / 100);
                   }
                   $_SESSION["$classname"] = ($tax_multiplier - 1.0) * 100; //Used the global $_SESSION.  Is there a way to use native API?                    
                   return ($tax_multiplier - 1.0) * 100;
            } else { // There are no taxes so just return 0
                     $_SESSION["$classname"] = 0; //Used the global $_SESSION.  Is there a way to use native API?
                     return 0;
                   }
       } else {  //The class is registered in session so return that
               return $_SESSION["$classname"]; 
               }

   } else { //The visitor is a guest so output 0
           return 0; 
           }
 }
//rmh M-S_fixes end

////
// Return the tax description for a zone / class
// TABLES: tax_rates;
 function tep_get_tax_description($class_id, $country_id, $zone_id) {
   global $customer_id; //rmh M-S_pricing

   if (tep_customer_tax_exempt($customer_id)) { return 0; } //rmh M-S_pricing

   $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);

     return $tax_description;
   } else {
     return TEXT_UNKNOWN_TAX_RATE;
   }
 }

 

Here is the tax.php that needs to be updated with above extras...

 

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

   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'];
   }
 }
?>

 

This would significantly speed up my store if I can integrate this. Thanks in advance.

 

Brad

Link to comment
Share on other sites

  • 1 month later...

I just added this contribution, it does seem to improve speed.

 

However, I am having one problem. It is including the shipping price in the amount taxed. This did not occur before installing this contribution. Is this a known issue?

 

Thanks in advance.

Link to comment
Share on other sites

After some more investigation, it appears that the tax rate is not showing up correctly on the order_confirmation page, but is being added correctly to the total, before being sent to our payment processor.

 

However, this causes a problem, because the total that is displayed to the customer is actually greater then the actual total charged.

Link to comment
Share on other sites

After i installed this contrib, it sayd that there was a parse error and an extra } on line 364 (in general.php), which in my case looks like this:

 

$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);

}

return ($tax_multiplier - 1.0) * 100;

} else {

return 0;

}

} <---------- line 364

 

I removed that bracket and now everything seems to go smooth, think that this might cause problems in future?

 

Im using 2.2 MS2

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

 

i have a short question:

We have 2 taxrates (7% for food and 16% for all the other products). The taxrate is chossen by the product like given above.

 

Is it right, if i use this contrib, that i only could use one of these, because the system would not lookup the database anymore, or would the system be able to calculate it right, because it gets the taxrate from the product_info and only doesn't look in the database if the taxrate should be shown or not?

 

Thanks for your help.

 

Ren?

Edited by SNCJansen
Link to comment
Share on other sites

You can use as many tax rates as you want...it only queries the database once for each UNIQUE tax rate. So, if a store only has 1 tax rate it would query once no matter how may products are listed on that page. If there are 2 tax rates it will execute a maximum of 2 queries to lookup those values.

 

Bobby

Link to comment
Share on other sites

I installed this wonderful contrib and have to find that I belong to the group of people where it doesn't work. I always get a zero tax rate when a customer logs in.

 

I agree with Chemo that this is not a problem of the contribution. I looked into the code and have to agree that it doesn't break anything. Still it's a fact that it doesn't run, and when I revert to the original code all is well. Hmmm....

 

I found that the two globals $customer_zone_id and $customer_country_id are empty in the osC_Tax class. Why, I have no clue.

 

Could this just be a php malconfiguration on my side?

 

Best,

Ted

Link to comment
Share on other sites

  • 3 weeks later...

In all store the products are with no tax.. but ! in checkout_confirmation.php the price is with the tax ! :)

All is Ok when i uninstall this contribition but i got more queries..

so... prices without tax in the store (but less queries) or prices with tax (but more queries) ?

ok not funny... but whats wrong with the code ?

Don't tell i forgot the :

// tax class

require('includes/classes/tax.php');

$osC_Tax = new osC_Tax;

?>

in application_top =)

Link to comment
Share on other sites

I installed this wonderful contrib and have to find that I belong to the group of people where it doesn't work. I always get a zero tax rate when a customer logs in.

 

Well, I looked again and found that $customer_zone_id and $customer_country_id are not defined as globals in function getTaxRate(). Adding the globals made the problem I had disapear.

 

Let your code look like this:

      function getTaxRate($class_id, $country_id = -1, $zone_id = -1) {
       global $customer_zone_id, $customer_country_id;
     <snip, snip>

 

Best,

Ted

Link to comment
Share on other sites

  • 3 months later...

hmmmm.....

mine tep_get_tax_rate() section in general.php has a slight addition for SPPC contrib:

// 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 Separate Pricing Per Customer, tax exempt modification
global $customer_zone_id, $customer_country_id, $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;
 }
// EOF Separate Pricing Per Customer, tax exempt modification
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_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);
  }
  return ($tax_multiplier - 1.0) * 100;
} else {
  return 0;
}
 }

 

If I change the above to:

// 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 Separate Pricing Per Customer, tax exempt modification
global $customer_zone_id, $customer_country_id, $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;
 }
// EOF Separate Pricing Per Customer, tax exempt modification
global $customer_zone_id, $customer_country_id, $osC_Tax;
return $osC_Tax->getTaxRate($class_id, $country_id, $zone_id);
}

...will it still function correctly? Will the SPPC stuff still work correctly with this contrib? Thanks ;)

Link to comment
Share on other sites

  • 1 month later...

I'm getting the following error when I add to cart or anything else:

 

Fatal error: Call to a member function on a non-object in /home/blahblah-/public_html/shop/includes/functions/general.php on line 428

 

428 is the first return line in tep_get_tax_rate()

 

Here's what I have in my general.php:

 

////
// 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) {
global $customer_zone_id, $customer_country_id, $osC_Tax;
return $osC_Tax->getTaxRate($class_id, $country_id, $zone_id);
}

////
// Return the tax description for a zone / class
// TABLES: tax_rates;
function tep_get_tax_description($class_id, $country_id, $zone_id) {
global $osC_Tax;
return $osC_Tax->getTaxRateDescription($class_id, $country_id, $zone_id);
}

 

I believe this speed up my site alot because I have many different featured products areas. So I really want to get this class working properly. Please help me.

 

Thank You,

 

James

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 months later...
  • 2 weeks later...
Well, I looked again and found that $customer_zone_id and $customer_country_id are not defined as globals in function getTaxRate(). Adding the globals made the problem I had disapear.

 

Let your code look like this:

	  function getTaxRate($class_id, $country_id = -1, $zone_id = -1) {
	global $customer_zone_id, $customer_country_id;
  <snip, snip>

 

Best,

Ted

 

 

I confirm that post. I had the same problem. When I log in with a user, the tax rate was different (return 0).

Someone should update the contribution with this fix!

Edited by demoalt
Link to comment
Share on other sites

  • 3 weeks later...
I'm getting the following error when I add to cart or anything else:

 

Fatal error: Call to a member function on a non-object in /home/blahblah-/public_html/shop/includes/functions/general.php on line 428

 

428 is the first return line in tep_get_tax_rate()

 

Here's what I have in my general.php:

 

////
// 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) {
global $customer_zone_id, $customer_country_id, $osC_Tax;
return $osC_Tax->getTaxRate($class_id, $country_id, $zone_id);
}

////
// Return the tax description for a zone / class
// TABLES: tax_rates;
function tep_get_tax_description($class_id, $country_id, $zone_id) {
global $osC_Tax;
return $osC_Tax->getTaxRateDescription($class_id, $country_id, $zone_id);
}

 

I believe this speed up my site alot because I have many different featured products areas. So I really want to get this class working properly. Please help me.

 

Thank You,

 

James

 

 

// 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) {
global $customer_zone_id, $customer_country_id, $osC_Tax;
return $osC_Tax->getTaxRate($class_id, $country_id, $zone_id);
} 

////
// Return the tax description for a zone / class
// TABLES: tax_rates;
function tep_get_tax_description($class_id, $country_id, $zone_id) {
global $osC_Tax;
return $osC_Tax->getTaxRateDescription($class_id, $country_id, $zone_id);
}

 

Thats what i have in my general.php and it works for me

Link to comment
Share on other sites

  • 1 month later...
I'm getting the following error when I add to cart or anything else:

 

Fatal error: Call to a member function on a non-object in /home/blahblah-/public_html/shop/includes/functions/general.php on line 428

 

428 is the first return line in tep_get_tax_rate()

 

 

I believe this speed up my site alot because I have many different featured products areas. So I really want to get this class working properly. Please help me.

 

Thank You,

 

James

 

 

I got the same error -particularly if a customer was logged in. I solved it my moving the following:

require('includes/classes/tax.php');
$osC_Tax = new osC_Tax;

from the bottom of application_top.php (as instructed) to just below:

// currency
 if (!tep_session_is_registered('currency') || isset($HTTP_GET_VARS['currency']) || ( (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') && (LANGUAGE_CURRENCY != $currency) ) ) {
if (!tep_session_is_registered('currency')) tep_session_register('currency');

if (isset($HTTP_GET_VARS['currency'])) {
  if (!$currency = tep_currency_exists($HTTP_GET_VARS['currency'])) $currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
} else {
  $currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
}
 }

HTH,

Tom

Link to comment
Share on other sites

  • 2 months later...
I confirm that post. I had the same problem. When I log in with a user, the tax rate was different (return 0).

Someone should update the contribution with this fix!

 

Hello i have the same problem After i have installed the contribution

the logged in customers coulonly see he prices without tax.

 

I saw the post about this problem but i dont undrestand could anyone please help?

 

How do i put the globals?

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