Jump to content

[Tutorial] Save your visitors searchwords


Recommended Posts

hi guys

 

i'm running a shop with presta version 0.9.7

 

i've noticed that in the database there is a table

to save the searchs the user starts in you shop.

 

unfortunately this feature seems not ready yet

but with very little tweak your shop will do this task

 

step 1:

 

change the ps_search table to autoincrement the id column

ALTER TABLE `ps_search` CHANGE `id_search` `id_search` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT

 

step 2:

 

add this little line of code after $smarty->assign('query', $query); in the file search.php in the root dir

DB::getInstance()->autoExecute(_DB_PREFIX_.'search', array('keyword'=>$query, 'results'=>$nbProducts, 'date'=>date('Y-m-d H:i:s')), 'INSERT');

 

ready!

 

dont forget to backup your data before you try it for yourself.

 

hope that helps. :)

 

Link to comment
Share on other sites

  • 1 month later...

Great tip d:rk

 

Pity since upgrading to RC3 I cannot get the search to return the correct data any more - but at least I can see what people were searching for - even if they can't find it :-(

 

I guess this will be added to the standard functionality soon.

 

It would also be nice to see whether the search was from the search bar or the tag cloud (where the search does work - even with the same search string) as the search is actually coded twice.

 

- Andrew

www.brilliantbikes.co.uk

Link to comment
Share on other sites

  • 2 months later...

Now that there are also tags (as well as the search) I have added slightly to this functionality.

I have added 2 columns to the ps_search table:
id_lang - type int - to store the language being searched
search_type - type varchar - to store the type of search (there are three types now - search, tag and ref)

In the search.php change the code in the three places:
For search:

DB::getInstance()->autoExecute(_DB_PREFIX_.'search', array('keyword'=>$query, 'results'=>$nbProducts, 'date'=>date('Y-m-d H:i:s'),'id_lang'=>(intval($cookie->id_lang)), 'search_type'=>"search"), 'INSERT');            



For tag:

DB::getInstance()->autoExecute(_DB_PREFIX_.'search', array('keyword'=>$tag, 'results'=>$nbProducts, 'date'=>date('Y-m-d H:i:s'),'search_type'=>"tag",'id_lang'=>(intval($cookie->id_lang))), 'INSERT');        



For ref:

DB::getInstance()->autoExecute(_DB_PREFIX_.'search', array('keyword'=>$query, 'results'=>$nbProducts, 'date'=>date('Y-m-d H:i:s'),'search_type'=>"ref",'id_lang'=>(intval($cookie->id_lang))), 'INSERT');        



And you will have a table showing what searches were mad on your site - and whether they came from the search box or a tag click.

Good luck.

- Andrew

Link to comment
Share on other sites

  • 9 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...