Hi there,
At the moment, if a user searches for prodcuts within a category they receive results for products in that category only. That's great, but if a user then clicks on a product from the search results, they see prices for the same product across multiple categories.
In my market, the same product can exist in different formats (I have sorted these into categories).
Therefore, what I need is for prices to be compared between merchants in the same category only.
Help! :)
Thanks,
Matt
David,
Excellent customer service, you are a credit to yourself and the community. Thanks loads, will give it a try.
Matt
Okay, to further this request a little...
On my index page, I have added radio buttons for the form to search by category... I tried setting the value of the radio buttons to:
<div class='searchform'>
<form name='search' action='<?php print $config_baseHREF ?>search.php'>
<input type='text' name='q' id='q' size='35' value='<?php print (isset($q)?$q:""); ?>' />
<!-- Cat Search Test: --->
<br> cat1<input type='radio' name='q' value='category:cat1'> cat2<input type='radio' name='q' value='category:cat2'> cat3<input type='radio' name='q' value='cat3'> <br><br>
<!-- end cat test: -->
<input type='submit' value='<?php print translate("Search"); ?>' />
</form>
</div>
I also didn't really want the category in the search field box, perhaps I should use sessions or hide the cat as a hidden post in the form?
----
To Clarify, what I need is for the user to hit the homepage, select which cat they want to search in the radio button, enter their search into the text field, then click go and see a list of products for the chosen cat (via radio button). Make sense?
Hi,
You would need to use a different field name as "q" is already in use as the main query. I would simply use "category" as the field name for the radio buttons, and then the value for each radio button the category name itself.
Then, at the top of search.php check for $_GET["category"] and reconstruct the appropriate $_GET["q"]. To do this, at the top of search.php look for the following code (line 4):
$q = (isset($_GET["q"])?tapestry_normalise($_GET["q"],":\."):"");
..and replace this with the following code:
if ($_GET["category"])
{
$_GET["q"] = "category:".$_GET["category"].":".$_GET["q"];
}
$q = (isset($_GET["q"])?tapestry_normalise($_GET["q"],":\."):"");
This will ensure that the correct search value "category:CatName:SearchTerm" is propagated to all the follow on pages (change sort order, page 2..3..4 etc.) and is also passed through to the product page as per the earlier mods...
Cheers,
David.
Hi Dave,
Thanks for your response!
Question though, this seems to affect category mapping. Is it because category mapping uses $q and not $category?
Cheers,
Matt.
Hi Matt,
This shouldn't affect category mapping at all as this is applied at import so the alternative category names never make it to the database. Could you perhaps post (or email me if you like) a link to an example so that I can see what's going on...
Cheers,
David.
This was my error, I didn't import the feeds after configuring the category mapping! Doh! Thanks again
Hi Matt,
This is relatively straight forward to do. First, a category parameter needs to be passed in the link from the search results (if the search is a category search). To do this, look for the following block of code starting at 164 of search.php:
if ($config_useRewrite)
{
$searchresults["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
if ($rewrite) $searchresults["products"][$k]["productHREF"] = "../../".$searchresults["products"][$k]["productHREF"];
}
else
{
$searchresults["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
}
...and replace it with:
if ($config_useRewrite)
{
$searchresults["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
if ($rewrite) $searchresults["products"][$k]["productHREF"] = "../../".$searchresults["products"][$k]["productHREF"];
if ($parts[0]=="category")
{
$searchresults["products"][$k]["productHREF"] .= "?category=".urlencode($parts[1]);
}
}
else
{
$searchresults["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
if ($parts[0]=="category")
{
$searchresults["products"][$k]["productHREF"] .= "&category=".urlencode($parts[1]);
}
}
(note that added code is very slightly different (& instead of ?) in each section of the IF statement!)
Then, to use this parameter on the products page, look for following code on line 12 of products.php:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' ORDER BY price LIMIT ".$config_resultsPerPage;
...and replace this with:
if ($_GET["category"])
{
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' AND category='".database_safe($_GET["category"])."' ORDER BY price LIMIT ".$config_resultsPerPage;
}
else
{
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' ORDER BY price LIMIT ".$config_resultsPerPage;
}
That should do the trick!
Cheers,
David.