function tep_get_tax_rate()
this function is called everywhere.. which is absolutely pointless and is possibly one of the biggest bottlenecks in the site if you have a lot of products per category.. the reason why it is pointless is if you dont show the prices with taxes added on then there is no reason to call this function yet it is called for each product for each category. Even if you cache the results for the product.. the function is called for absolutely no reason.. this has lead to other coding flaws in contributions for example 'PriceFormatter.php' which also calls this function for no good reason.
So how do you fix it.. a little time is all you need. Instead of calling this function with the tax_class_id BEFORE sending it to the currency formatter methods (ie $currencies->format_price etc..) just pass the tax_class_id into it.. let currencies methods pass the tax_class_id further until it finally reaches its main useful method .. tep_add_tax ..
tep_add_tax does its only useful function.. IF you are adding the tax to the price.. CALCULATE IT THEN!!! .. let tep_add_tax call tep_get_tax_rate() with the tax_class_id which you have now passed through.. INSTEAD OF .. passing in an absolutely pointless products_tax value which will NEVER BE USED!! ..
examples..
in /catalog/includes/functions/general.php
change
// Add tax to a products price
function tep_add_tax($price, $tax) {
// if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) ) {
// BOF Separate Pricing Per Customer, show_tax modification
// next line was original code
// if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) ) {
global $sppc_customer_group_show_tax;
global $sppc_customer_group_tax_exempt;
if(!tep_session_is_registered('sppc_customer_group_show_tax')) {
$customer_group_show_tax = '1';
} else {
$customer_group_show_tax = $sppc_customer_group_show_tax;
}
if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) && ($customer_group_show_tax == '1')) {
// EOF Separate Pricing Per Customer, show_tax modification
return $price + tep_calculate_tax($price, $tax);
} else {
return $price;
}
}
to this
// Add tax to a products price
function tep_add_tax($price, $tax_class) {
// if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) ) {
// BOF Separate Pricing Per Customer, show_tax modification
// next line was original code
// if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) ) {
global $sppc_customer_group_show_tax;
global $sppc_customer_group_tax_exempt;
if(!tep_session_is_registered('sppc_customer_group_show_tax')) {
$customer_group_show_tax = '1';
} else {
$customer_group_show_tax = $sppc_customer_group_show_tax;
}
if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax > 0) && ($customer_group_show_tax == '1')) {
// EOF Separate Pricing Per Customer, show_tax modification
return $price + tep_calculate_tax($price, tep_get_tax_rate($tax_class));
} else {
return $price;
}
}
note I am using SPPC so your methods will be different if you are not.. regardless this is exactly how this function should have been coded to begin with.
next change whatever calls that function .. not many unless you are using PriceFormatter.php but for example the currencies class
change this
function display_price($products_price, $products_tax, $quantity = 1) {
return $this->format($this->calculate_price($products_price, $products_tax, $quantity));
}
to this
function display_price($products_price, $products_tax_class, $quantity = 1) {
return $this->format($this->calculate_price($products_price, $products_tax_class, $quantity));
}
and this
function calculate_price($products_price, $products_tax, $quantity = 1) {
global $currency;
return tep_round(tep_add_tax($products_price, $products_tax), $this->currencies[$currency]['decimal_places']) * $quantity;
}
to this
function calculate_price($products_price, $products_tax_class, $quantity = 1) {
global $currency;
return tep_round(tep_add_tax($products_price, $products_tax_class), $this->currencies[$currency]['decimal_places']) * $quantity;
}
now I mean come on this has to make perfect sense... it does to me anyhow.. ive already made the changes.. noticed a nice drop in the number of queries.. and no need for caching something that shouldnt need to be in the first place.. (not unless you are showing these prices with taxes included that is..)
J















