You are here:  » Price brackets in search results

Support Forum



Price brackets in search results

Submitted by matthew on Mon, 2008-07-07 22:01 in

Ok, I've been doing some work to add some extra search functionality to the search results page.

I've used the following code to create a breakdown of the prices:

<?php
$bracket = array(
array(number => "1", count => "0", text => "£0.00 – £19.99"),
array(number => "2", count => "0", text => "£20.00 – £39.99"),
array(number => "3", count => "0", text => "£40.00 - £59.99"),
array(number => "4", count => "0", text => "£60.00 - £79.99"),
array(number => "5", count => "0", text => "£80.00 - £99.99"),
array(number => "6", count => "0", text => "£100.00 - £199.99"),
array(number => "7", count => "0", text => "£200.00 - £299.99"),
array(number => "8", count => "0", text => "£300.00 - £399.99"),
array(number => "9", count => "0", text => "£400.00 - £599.99"),
array(number => "10", count => "0", text => "£600.00 - £799.99"),
array(number => "11", count => "0", text => "£800.00 - £999.99"),
array(number => "12", count => "0", text => "£1000.00 - £1199.99"),
array(number => "13", count => "0", text => "£1200.00 - £1399.99"),
array(number => "14", count => "0", text => "£1400.00 - £1599.99"),
array(number => "15", count => "0", text => "£1600.00 - £1799.99"),
array(number => "16", count => "0", text => "£1800.00 - £1999.99"),
array(number => "17", count => "0", text => "£2000+")
);
foreach ($searchresults["products"] as $product){
if ($product["price"] > 0 and $product["price"] < 19.99) {$bracket['1']['count'] = $bracket['1']['count'] + 1;}
if ($product["price"] > 20 and $product["price"] < 39.99) {$bracket['2']['count'] = $bracket['2']['count'] + 1;}
if ($product["price"] > 40 and $product["price"] < 59.99) {$bracket['3']['count'] = $bracket['3']['count'] + 1;}
if ($product["price"] > 60 and $product["price"] < 79.99) {$bracket['4']['count'] = $bracket['4']['count'] + 1;}
if ($product["price"] > 80 and $product["price"] < 99.99) {$bracket['5']['count'] = $bracket['5']['count'] + 1;}
if ($product["price"] > 100 and $product["price"] < 199.99) {$bracket['6']['count'] = $bracket['6']['count'] + 1;}
if ($product["price"] > 200 and $product["price"] < 299.99) {$bracket['7']['count'] = $bracket['7']['count'] + 1;}
if ($product["price"] > 300 and $product["price"] < 399.99) {$bracket['8']['count'] = $bracket['8']['count'] + 1;}
if ($product["price"] > 400 and $product["price"] < 599.99) {$bracket['9']['count'] = $bracket['9']['count'] + 1;}
if ($product["price"] > 600 and $product["price"] < 799.99) {$bracket['10']['count'] = $bracket['10']['count'] + 1;}
if ($product["price"] > 800 and $product["price"] < 999.99) {$bracket['11']['count'] = $bracket['11']['count'] + 1;}
if ($product["price"] > 1000 and $product["price"] < 1199.99) {$bracket['12']['count'] = $bracket['12']['count'] + 1;}
if ($product["price"] > 1200 and $product["price"] < 1399.99) {$bracket['13']['count'] = $bracket['13']['count'] + 1;}
if ($product["price"] > 1400 and $product["price"] < 1599.99) {$bracket['14']['count'] = $bracket['14']['count'] + 1;}
if ($product["price"] > 1600 and $product["price"] < 1799.99) {$bracket['15']['count'] = $bracket['15']['count'] + 1;}
if ($product["price"] > 1800 and $product["price"] < 1999.99) {$bracket['16']['count'] = $bracket['16']['count'] + 1;}
if ($product["price"] > 2000) {$bracket['17']['count'] = $bracket['17']['count'] + 1;}
}
foreach ($bracket as $key => $value){
    if ($value['count'] > 0) {
        echo "<a href=''>".$value['text']."</a> (".$value['count'].")";
        echo "<br/>";
    }
}
?>

This works, but has the following problems:

1) It only shows the price brackets for the results on the page you are viewing. So if you have set a $config_resultsPerPage of 30, you will only get the price brackets for those 30 items.

2) If it was possible to show the price brackets for the entire search results, I think that more often than not, you would end up showing all the price brackets. I have put this down to the way that PT conducts the searches. For example, in my site, if you search for LCD TV, you get approx 400 results, ranging from cables (cheaper brackets), to stands (middle brackets) to tvs (higher brackets).

If the code above can help anyone, or anyone has suggestions for working around these problems...

I am also looking at listing the brands and merchants returned by the search. If anyone has any ideas, can they let me know?

Submitted by shogounou on Tue, 2008-08-12 12:38

hello
You are going to find my question irrelevant but:
Where can I add this portion of code? in search result? Where exactly? In a separate file?
Thank you

Shogounou