You are here:  » Create category from search


Create category from search

Submitted by wilkins on Tue, 2015-06-30 17:51 in

Hi David

Is there any way to create a category from a search term, ie blue toaster as a search term would then be made into a category on the site. The idea to create unique categories that are different to the norm.

regards

brent

Submitted by support on Wed, 2015-07-01 10:00

Hello Brent,

It would be no problem to use the WHERE clause generated for the query and use that to SET category='{keywords}' if category was currently empty, if you wanted to experiment, look for the following code at line 312 in search.php:

    if ($resultCount)
    {

...and REPLACE with:

    if ($resultCount)
    {
      if (!isset($parts[1]) && ($page==1))
      {
        $sql2 = "UPDATE`".$config_databaseTablePrefix."products`
                   SET category='".database_safe($q)."'
                   WHERE ".$where." AND category=''";
        database_queryModify($sql2,$result2);
      }

You might want to think about only applying the process under certain conditions, for example no more than 2 keywords, in which case you could add another IF condition to the 3rd line of the replacement above, e.g.

  if (!isset($parts[1]) && ($page==1) && (count($words)<=2))

Bear in mind that the process would reset at the next import since the import process first DELETEs all product records and then INSERTs from the latest feed but it would certainly give some rolling URL variety for your site if you wanted to experiment with the above.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com