Jump to content
Sign in to follow this  
Chemo

Optimization of tep_get_tax_rate()

Recommended Posts

Hello Chemo,

 

thanx for this great contribution. The shop works much faster than before!

BUT there ist a little problem with the tax calculation...

 

If a user is logged in, the price is without tax!

 

I have two geo_zone_ids - id=1 for EU incl. German Tax and id=2 for world without taxes...

It is exactly the same, if a user is logged in...wherever he come from. The tax class should distinguish if the logged user is from the EU and should show the prices with taxes or if the user is from a "world-country" and show them without taxes :( :(

 

I have installed the "Optimize tep_get_tax_rate() v1.1" contribution correctly and turned on the configuration value "Display Prices with Tax = true".

 

Please help :blush: thanx :)

 

Sorry for my bad English ;)

Share this post


Link to post
Share on other sites

Have also a problem with my general.php.

I receive an error message

Fatal error: Call to a member function on a non-object in /srv/www/htdocs/shop/includes/functions/general.php on line 336

 

I have several other contribs installed like shopping cart enhancement etc.

I know, thats always written here, that the MS3-taxclass is not affecting other contribs.

 

Is there a way how I can find out, what causes a.m. error message ?

 

Thanks in advance,

kind regards

Andreas

Share this post


Link to post
Share on other sites

 	Shopping Cart	  more

Fatal error: Call to a member function on a non-object in /home/XXXX/public_html/shopping/includes/functions/general.php on line 310

 

Hi all,

I found this error msg when i click " add to cart" button ...

 

And this is insuction for line 310 of general.php (red color part)

 

////
// 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;
[color=#FF0000]return $osC_Tax->getTaxRate($class_id, $country_id, $zone_id);[/color]
 }

////
// 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);
 }

 

Anybody can help me check what wrong i doing @@?

Share this post


Link to post
Share on other sites

Finally, i get the solution ...

This is from what chemo posted before

Special to who install page cache and Optimization of tep_get_tax_rate

 

Move the tax class initialization code above the page cache code (currently below it). So, it should look like this:

 

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


/*--------------------------------------------------------*\
# Page cache contribution - by Chemo
# Define the pages to be cached in the $cache_pages array
\*--------------------------------------------------------*/
$cache_pages = array('index.php', 'product_info.php', 'conditions.php', 'contact_us.php', 'privacy.php');
#$cache_pages = array('index.php');
if (!tep_session_is_registered('customer_id') && ENABLE_PAGE_CACHE == 'true') {
# Start the output buffer for the shopping cart
ob_start();
require(DIR_WS_BOXES . 'shopping_cart.php');
$cart_cache = ob_get_clean();
# End the output buffer for cart and save as $cart_cache string

# Loop through the $cache_pages array and start caching if found
foreach ($cache_pages as $index => $page){
if ( strpos($_SERVER['PHP_SELF'], $page) ){
 include_once(DIR_WS_CLASSES . 'page_cache.php');
 $page_cache = new page_cache($cart_cache);
 # The cache timelife can be set globally in the settings
 # Example below sets it for 60 minutes
 # $page_cache->cache_this_page(60);
 $page_cache->cache_this_page();
} # End if
} # End foreach
} # End if

 

*Information is come from: http://forums.oscommerce.com/lofiversion/i...hp/t119114.html

Share this post


Link to post
Share on other sites

i'd love to install this contribution, i uploaded the latest tax.php into the correct place and followed the install instructions from the newest i could find with them but receive this error:

 

Fatal error: Call to a member function on a non-object in /home/***/shopincludes/functions/general.php on line 420

 

i see a previous fix for this which is moving the application_top part up above a CACHE mod, but i do not have this on my store.. does anyone have any ideas about what i can do?

 

thanks in advance :)

kev.

Edited by kev@num

Share this post


Link to post
Share on other sites

woohoo... this helped me:

 

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;
}
}

Edited by kev@num

Share this post


Link to post
Share on other sites

hello!

 

it's speeded up my shop now, but previouly when logged in it showed prices including tax..

is there anyway to still show prices like this?

 

i've uploaded the lastest version from aug 2006 with the fix but it doesn't work for me..

Share this post


Link to post
Share on other sites

Just a note to say I installed this today and tested thoroughly on ms2.2 and it works a treat. I installed Chemo's vers 1.1 dated Nov 24/04 and then replaced the tax.php file with the latest version dated aug.27/06 from xmanflash.

 

Just thought I'd make a note here of a recent installation for those wondering if it works due to the problems noted here. Also worth mentioning it is an extremely easy contrib to install, my shop has 56 contribs installed total to date and this interfered with NOTHING - don't be afraid to use it, the speeds are fantastic!

Share this post


Link to post
Share on other sites

Works for me also.

 

 

Just a note to say I installed this today and tested thoroughly on ms2.2 and it works a treat. I installed Chemo's vers 1.1 dated Nov 24/04 and then replaced the tax.php file with the latest version dated aug.27/06 from xmanflash.

 

Just thought I'd make a note here of a recent installation for those wondering if it works due to the problems noted here. Also worth mentioning it is an extremely easy contrib to install, my shop has 56 contribs installed total to date and this interfered with NOTHING - don't be afraid to use it, the speeds are fantastic!

Share this post


Link to post
Share on other sites

Hi all,

 

anyone else find that when the customer logs in the VAT is then lost from the "whats in my cart"?

 

this is because the customer has logged in and their address has not been selected yet. fix is as follows, I just commented out the offending line and replaced it with the next in catalog\includes\classes\tax.php (line29)...

 

 

// 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')) {
  if (!tep_session_is_registered('customer_id') || $customer_country_id=="") {
	$country_id = STORE_COUNTRY;
	$zone_id = STORE_ZONE;
  } else {
	$country_id = $customer_country_id;
	$zone_id = $customer_zone_id;
  }
}

 

HTH

 

Si.

Edited by Jan Zonjee

Share this post


Link to post
Share on other sites

OR even better use the global values

 

	function getTaxRate($class_id, $country_id = -1, $zone_id = -1) {
global $customer_zone_id, $customer_country_id;  //new line to fix tax login issue
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;
  }
}

 

Si.

Edited by scranmer

Share this post


Link to post
Share on other sites
OR even better use the global values

Exactly the fix xmanflash added to that contribution 2 years ago.... (????)

Share this post


Link to post
Share on other sites

Does anyone has this problem:

 

Prices are visable include TAX.

Customer logs in: Prices are still visable include TAX

Customer changes address in address book: prices are visable EX TAX.

Even when original address is not changed and only saved: prices are visable without tax.

 

Curious if anyone has this problem and off course if anyone has the solution...

 

Regards,

Alex

Share this post


Link to post
Share on other sites

I want to use this add-on so I can get Sage CSV working. However, I am having trouble modifying the includes/functions/general.php page.

 

Basically its asking me to add:

 

REPLACE tep_get_tax_rate() it with this code:

 

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

}

 

When I have listed:

 

function tep_get_tax_rate($class_id, $country_id = -1, $zone_id = -1) {

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_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;

}

}

 

and

 

function tep_get_tax_description($class_id, $country_id, $zone_id) {

global $osC_Tax;

return $osC_Tax->getTaxRateDescription($class_id, $country_id, $zone_id);

}

 

When I have:

 

function tep_get_tax_description($class_id, $country_id, $zone_id) {

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

}

}

 

I have multi shipping zones basically spanning the english and scottish islands. Is this not going to disrupt it? if so, is there an alternative I can add?

 

Any help gratefully received.

 

TIA


Debbie Harrison

 

Share this post


Link to post
Share on other sites
I want to use this add-on so I can get Sage CSV working. However, I am having trouble modifying the includes/functions/general.php page.

 

I have multi shipping zones basically spanning the english and scottish islands. Is this not going to disrupt it? if so, is there an alternative I can add?

Those queries have been moved to the class tax. You can compare the queries and see if they are the same as in general.php (I think they are). The difference is the class tax "remembers" a tax rate and returns the stored rate when asked for it instead of doing a query every time.

Share this post


Link to post
Share on other sites

Those queries have been moved to the class tax. You can compare the queries and see if they are the same as in general.php (I think they are). The difference is the class tax "remembers" a tax rate and returns the stored rate when asked for it instead of doing a query every time.

 

Hi,

 

Coming into this late I know, but I have the same problem with multi geo-zone shipping, I don't understand your post above - should I be modifying the general.php file or not? as my code does not match that posted in the contribution.

 

Thanks


Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.

Share this post


Link to post
Share on other sites

Sorry - ignore my post - found the answer on chemo's thread


Now running on a fully modded, Mobile Friendly 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.

Share this post


Link to post
Share on other sites

Just wanted to confirm and see if there is still a need to use this add-on in rc2.2a or 2.3?

A better version of it (along the lines Chemo posted elsewhere) has been added to 2.3. If you can find the download of 2.3 on Github you just need to change two functions in includes/functions/general.php to get the functionality this addon brings.

Share this post


Link to post
Share on other sites

A better version of it (along the lines Chemo posted elsewhere) has been added to 2.3. If you can find the download of 2.3 on Github you just need to change two functions in includes/functions/general.php to get the functionality this addon brings.

 

 

ah I see..well since I am using 2.3 downloaded from github I guess I am all set then..

 

Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×