Hi David,
I have a feed with about 1000 brands. I want to search only some selected brands and show their products.
Is there a way to do this?
Regards
Roland
Exactly that's what I want to to. Sorry.
Regards
Roland
Hi Roland,
Let's say you want to create a saved search to select all products with the brands "Sony", "Panasonic" and "Hitachi". Firstly, think of a name for this search, for example "sph". Now, you need to add code for this saved query to search.php. The format I would suggest would be to support a query URL something like this:
search.php?q=saved:sph:
The code to support this would need to be added into search.php immediately after the following code (at line 37):
switch($parts[0])
{
The code would look like this:
case "saved":
if ($parts[1] == "sph")
{
$where = "brand='Sony' OR brand='Panasonic' OR brand='Hitachi'";
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE ".$where." GROUP BY name";
$sqlResultCount = "SELECT COUNT(DISTINCT(name)) as resultcount FROM `".$config_databaseTablePrefix."products` WHERE ".$where;
$orderBySelection = $orderByDefault;
}
break;
To create more saved searches, simply add more if ($parts[1] == "xxx") blocks to this section of code.
To link to this saved search, you simply need to add code something like the following to your index.php (or any other page)...
<a href='/search.php?q=saved:sph:'>Click here for the latest products from Sony, Panasonic and Hitachi</a>
Don't forget that if your site is not installed in the root directory of your website you will need to put the path to your site infront of /search.php...
Hope this helps!
Cheers,
David.
Hi David a last question concerning that issue: Is it possible to restrict the saved search to a single merchant?
Regards
Roland
Sure - simply extend the WHERE clause, so instead of:
$where = "brand='Sony' OR brand='Panasonic' OR brand='Hitachi'";
...use something like this:
$where = "merchant='Foo' AND (brand='Sony' OR brand='Panasonic' OR brand='Hitachi')";
Notice the brackets around the brand statments; this is required so that you only select products where the merchant is Foo _and_ the brand is one of those listed.
Cheers,
David.
Thanks, it works fine, also the adding of more saved searches.
ROland
Hi Roland,
With that many brands it would not be practical to offer a user input to select multiple brands; but you could do something if you just wanted to display a fixed set of search results for pre-selected brands? Is that what you want to do?
Cheers,
David.