Hey David,
Is it possible for users to be able to search for a merchant? So they can just type in a retailers name and the merchants list will appear with all the merchants matching the keywords?
Cheers,
Steven
That's great, I think a separate form would be better as a few merchants have names that could match products being searched for. Such as the merchant "CDwow" and someone searching for "CD".
But what would be great, is if any keywords do match any merchants then the user would be told at the top of search results. Such as:
Were you searching for a merchant? As your keyword matched the following merchants: CDwow.
Then the products mathced below this as normal.
But if this isn't possible, a separate form is best.
Thanks for your help, this mod will be great.
Steven
Hi Steven,
Essentially this is very straight forward - all that is needed is a test in merchants.php to check for a "q" parameter, and then use that term in the SQL (if it exists). In that file, look for the following code on line 7:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."feeds` ORDER BY merchant";
...and replace this with:
if ($_GET["q"])
{
$sql = "SELECT * FROM `".$config_databaseTablePrefix."feeds` WHERE merchant LIKE '%".database_safe($_GET["q"])."%' ORDER BY merchant";
}
else
{
$sql = "SELECT * FROM `".$config_databaseTablePrefix."feeds` ORDER BY merchant";
}
Then all you need is a form on your home page. Because of the way Price Tapestry generates search engine friendly URLs the following PHP will create a form that submits to the correct URL depending on whether or not this option is set:
<?php
$action = $config_baseHREF.($config_useRewrite?"merchant/":"merchants.php");
print "<form action='".$action."' method='GET'>";
print "<input type='text' name='q' /> ";
print "<input type='submit' value='Merchant Search' />";
print "</form>";
?>
(if the script you want to insert this form into is already in PHP mode simply exclude the PHP tags)
Finally, if doing this it might be nice to add a "no results" message if there are no merchants found matching the search. To do this, back in merchants.php, look for the following code on line 39:
require("html/atoz.php");
...and replace this with:
if (count($atoz["items"]))
{
require("html/atoz.php");
}
else
{
print "<p>Sorry, there are no merchants matching your query.</p>";
}
Cheers,
David.
Hi David,
I can't thankyou enough for the help with some of the mods over the last week. This is the last one on my list and thanks in advance for helping me out.
The above mod for searching for merchants works great, can you tell me how to incorporate this into the existing search so users don't need to use two different forms. If any merchants match the search term, they will be displayed at the top and the product results displayed below this.
Cheers David!
Steven
Hi Steve,
You could retrofit the merchant search code into search.php quite easily. To display merchants (partially) matching the query above the results (i.e. just after the "banner"), replace the following code (line 183 in the distribution):
require("html/banner.php");
...with
require("html/banner.php");
$sql = "SELECT * FROM `".$config_databaseTablePrefix."feeds` WHERE merchant LIKE '%".database_safe($_GET["q"])."%' ORDER BY merchant";
if (database_querySelect($sql,$feeds))
{
print "<p>Were you looking for the following merchants?</p>";
print "<ul>";
foreach($feeds as $feed)
{
if ($config_useRewrite)
{
$href = $config_baseHREF."merchant/".tapestry_hyphenate($feed["merchant"])."/";
}
else
{
$href = $config_baseHREF."search.php?q=merchant:".urlencode($feed["merchant"]).":";
}
print "<li><a href='".$href."'>".$feed["merchant"]."</a></li>";
}
print "</ul>";
}
Cheers,
David.
Hi Steven,
Reasonably straight forward I think with a redirect from search.php to merchants.php with a small mod at the top of merchants.php to support a ?q= variable.
Do you want it to work so that if 1 or more merchants is found matching the search term you get merchant results; otherwise search results as normal (so you only have one form); or would you like a separate "Merchant Search" form?
Cheers,
David.