Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Searching by price ranges in advanced search


Fredrik.r

Recommended Posts

I have read in the bug reports that I'm not the only one having this problem. It works as long there is only one country, tax zone, tax rate or whatever the reason is. I have several rates assigned to several countries but still the same rate; 25% tax.

 

When customer enters 100-200, osc searches for 100-200 as a net price. Why is that?

 

Would very much appreciate some help with fixing advanced_search_results.php

Link to comment
Share on other sites

I have read in the bug reports that I'm not the only one having this problem. It works as long there is only one country, tax zone, tax rate or whatever the reason is. I have several rates assigned to several countries but still the same rate; 25% tax.

 

When customer enters 100-200, osc searches for 100-200 as a net price. Why is that?

 

Would very much appreciate some help with fixing advanced_search_results.php

 

maybe advanced_search_results.php has a hard time figuring out what country you are from.

Treasurer MFC

Link to comment
Share on other sites

should use the tax if you have the display prices with tax option enabled. Or try removing the check from the advanced_search_result.php see if it helps

 

from:

  if ( (DISPLAY_PRICE_WITH_TAX == 'true') && (tep_not_null($pfrom) || tep_not_null($pto)) ) {

 

to:

  if ( (tep_not_null($pfrom) || tep_not_null($pto)) ) {

Link to comment
Share on other sites

It works with taxes as long as there only is one country/tax rate/zone.

 

I changed as above in three places in the file but then I got an error;

 

Parse error: parse error, unexpected T_VARIABLE in /home/lounge24/public_html/devstore2/advanced_search_result.php on line 293

 

 

Line 293;

 

if ($pto) ? $where_str .= " and (IF(s.status, s.specials_new_products_price, p.products_price) * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) <= " . $pto . ")";

Link to comment
Share on other sites

ok put the original file back and flip the Display prices with tax switch. See if you get an error. Now it will always compare against either the store's country zone or if a customer is logged, against the customer's account zone.

Link to comment
Share on other sites

You mean display prices without tax? Yes, that works with searching by price. But the problem is I must display prices with tax.

 

Strange, when using display with tax and only one country it all works when I search by price. It's when I put more countries in there the advanced search thinks I am searching for prices without tax. But it's a known bug.

Link to comment
Share on other sites

right so you need to change a couple of file and to have a zone for the store setup in order to cover all cases.

 

1. advanced_search_result.php

 

Locate this code

	$from_str .= " left join " . TABLE_TAX_RATES . " tr on p.products_tax_class_id = tr.tax_class_id left join " . TABLE_ZONES_TO_GEO_ZONES . " gz on tr.tax_zone_id = gz.geo_zone_id and (gz.zone_country_id is null or gz.zone_country_id = '0' or gz.zone_country_id = '" . (int)$customer_country_id . "') and (gz.zone_id is null or gz.zone_id = '0' or gz.zone_id = '" . (int)$customer_zone_id . "')";

 

Replace it with this

	$from_str .= " left join " . TABLE_TAX_RATES . " tr on p.products_tax_class_id = tr.tax_class_id left join " . TABLE_ZONES_TO_GEO_ZONES . " gz on (tr.tax_zone_id = gz.geo_zone_id and gz.zone_country_id = '" . (int)$customer_country_id . "' and gz.zone_id = '" . (int)$customer_zone_id . "')";
$rates_query = tep_db_query("select tr.tax_rate from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " gz on (tr.tax_zone_id=gz.geo_zone_id) where gz.zone_id = '" . (int)$customer_zone_id . "'");
if( $rates_array = tep_db_fetch_array($rates_query) ) {
  $tax_rate = $rates_array['tax_rate']/100;
} else {
  $tax_rate = 0;
}

 

Locate this code

	if ($pfrom > 0) $where_str .= " and (IF(s.status, s.specials_new_products_price, p.products_price) * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) >= " . (double)$pfrom . ")";
if ($pto > 0) $where_str .= " and (IF(s.status, s.specials_new_products_price, p.products_price) * if(gz.geo_zone_id is null, 1, 1 + (tr.tax_rate / 100) ) <= " . (double)$pto . ")";

 

Replace it with this

	if ($pfrom > 0) $where_str .= " and (IF(s.status, s.specials_new_products_price, p.products_price) * (1 + " . $tax_rate . " ) >= " . (double)$pfrom . ")";
if ($pto > 0) $where_str .= " and (IF(s.status, s.specials_new_products_price, p.products_price) * (1 + " . $tax_rate . " ) <= " . (double)$pto . ")";

 

2. catalog\includes\functions\general.php Locate this code:

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

 

Replace it with 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 = '" . (int)$country_id . "') and (za.zone_id = '" . (int)$zone_id . "') and tr.tax_class_id = '" . (int)$class_id . "' group by tr.tax_priority");

 

just make sure there is zone that covers the store. works with the default osc.

Link to comment
Share on other sites

Thank you so much for trying to help me! The price search seems to work now but there are duplicates of all products in the search result. A new issue is that all prices are showing whitout tax now, even though display tax is set to true in admin.

 

However, when logged in, prices are including taxes. So this must have to do with my zones, right? I'm not sure what you meant with "just make sure there is zone that covers the store".

 

Just want to list my config below.

 

 

COUNTRIES

 

Denmark

Finland

Norway

Sweden

 

 

ZONES

 

Within EU - Denmark, Finland

Sweden - Sweden

Outside EU - Norway

 

(Sweden is within EU but since there are payment methods restricted to Sweden I wanted to have Sweden in its own zone)

 

 

TAX RATES

 

Within EU 25%

Sweden 25%

Norway 0%

 

Tax Rates are working right now but when not logged in all prices are without tax?

Link to comment
Share on other sites

in osc admin->configuration->My Store->Zone and Country. Make sure whatever you set there is included in the tax zones. The default osc has USA and Florida. And there is a tax zone that covers it. I did not see duplicates when I tried it here. There is a "distinct" with the query so it should return a single product.

Link to comment
Share on other sites

The country is set as Sweden. I have no zones, should I just make on (and call it anything I want) for each country? Or should it do with just one zone for Sweden (the shop is based in Sweden)? There's no need for several zones per country since the shipping rates are the same.

Link to comment
Share on other sites

yes there is a need with the that code I posted. So lets say your store settings are

 

Country: Sweden

Zone: Stockholm

 

Create a tax zone (for example a folder called "default tax" and in the details of it set country:sweden zone:stockholm) and assign a tax rate. That tax rate is used to calculate the taxes when a client is not logged in.

Link to comment
Share on other sites

Oh, I understand. Thank you!

 

I did a zone called "default" assigned to Sweden in "Zones". Then I made a new Tax Zone called "Not logged in" with Sweden in it and zone "default". Finally I gave "Not logged in" a tax rate of 25% in Tax Rates.

 

So the zone "default" are just going to affect those who are not logged in, right? :)

Link to comment
Share on other sites

Hm, I thought it worked but now prices are without tax when choosing Sweden in the address book. Maybe I should not have both Sweden - All Zones (as one Tax Zone) AND Sweden - Zone "default"? I'll try with just Sweden - Zone "default" for swedish customers and people who are not logged in. Confusing.

Link to comment
Share on other sites

I have set the store zone as the zone named "default". "Default" is assigned to Sweden. But shouldn't "default" be included in Sweden - All zones in tax classes then? Sorry for bothering you so much with this.. :/

Link to comment
Share on other sites

sweden is the country. You need to specify the zone and that should be exactly the same as in the store's configuration. Doesn't matter if you also have the Sweden with all zones. But you need to have an entry that matches your store's config. Country + Zone

Link to comment
Share on other sites

I can get some of the things to work with different configurations but I can't get all working at the same time.. the price search wont work if I choose Denmark for example, then it searches without tax again. Hm, this is too complicated for me. I can get everything to work if I just don't mind abot the price search feature.. argh.

 

Thank you for all your help! I will try this again tomorrow.

Link to comment
Share on other sites

Feels like I've tried everything and it still does not work. Price search only works if the prices are without taxes. When displaying prices including taxes the price search still add another 25%..

Link to comment
Share on other sites

  • 1 year later...

@enigma1:

 

$rates_query = tep_db_query("select tr.tax_rate from " . TABLE_TAX_RATES . " tr left join " . TABLE_ZONES_TO_GEO_ZONES . " gz on (tr.tax_zone_id=gz.geo_zone_id) where gz.zone_id = '" . (int)$customer_zone_id . "'");
if( $rates_array = tep_db_fetch_array($rates_query) ) {
  $tax_rate = $rates_array['tax_rate']/100;
} else {
  $tax_rate = 0;
}

 

This will only work if all products have the same tax class.

Marco

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...