Instant Search

Views: 59,248

Results 21 to 40 of 262
19 Jan 2012, 5:18 PM
#21
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Instant Search

AyoobG:

  1. About the Admin panel! to be honest i have no plans in creating it, but if anyone other is interested, then by all means feel free to take over:wink:

Hmm, I have just invested a whole five minutes in looking at this...which is my limit on javascript.

Apart from the obvious stuff, getting the js to load on the categories.php and changing the "watched" box name from "keyword" to "searches", off the top of your head is there anything else that should need changing for the admin?
thanks
Steve

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

20 Jan 2012, 3:39 PM
#22
ayoobg avatar

ayoobg

New Zenner

Join Date:
Nov 2011
Posts:
34
Plugin Contributions:
1

Re: Instant Search

torvista:

Hmm, I have just invested a whole five minutes in looking at this...which is my limit on javascript.

Apart from the obvious stuff, getting the js to load on the categories.php and changing the "watched" box name from "keyword" to "searches", off the top of your head is there anything else that should need changing for the admin?
thanks
Steve

Hi Steve,

The links that will be generated once the user clicks on the search result will have to be different for the admin file. This can be done by editing the js file:

Replace:
index.php?main_page=product_info&products_id=

with:
categories.php?blahblahblah

but i have to warn you that links must be exactly structured as how they are displayed in the admin file links, otherwise your whole shop can mess up.

too much headache i would say!:no:

20 Jan 2012, 11:20 PM
#23
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: Instant Search

too much headache i would say!:no:Thanks! You are right, there are bigger fish to fry than this!

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

23 Jan 2012, 1:36 PM
#24
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Instant Search

Is it possible to show current stock levels for product results?

23 Jan 2012, 3:25 PM
#25
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Instant Search

DigitalShadow:

Is it possible to show current stock levels for product results?

I've tried my hardest, and I can't figure out how to edit the code to use the 'c' return field to display the stock level for the product. It shouldn't be too hard as it is setup to show the product count for categories.

23 Jan 2012, 4:49 PM
#26
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Instant Search

Done it.

"SELECT " . TABLE_PRODUCTS_DESCRIPTION . ".products_name, " . TABLE_PRODUCTS . ".products_quantity
		$prodquantity = ($dbProducts->fields['products_quantity']);
		$prodResult = strip_tags($dbProducts->fields['products_name']);
		if (strtolower(substr($prodResult,0,strlen($wordSearch))) == strtolower($wordSearch)){
			$results[] = array(
				//we have 4 seperate variables that will be passed on to instantSearch.js
				//'q' is the result thats been found
				//'c' is the number of item within a category search (we leave this empty for product search, look at the example bellow for category search)
				//'l' is used for creating a link to the product or category
				//'pc' lets us know if the word found is a product or a category
				'q'=>$prodResult,
				'c'=>$prodquantity,
				'l'=>$dbProducts->fields['products_id'],
				'pc'=>"p"
			);
		}else{
			$resultsAddAfter[] = array(
				'q'=>$prodResult,
				'c'=>$prodquantity,
				'l'=>$dbProducts->fields['products_id'],
				'pc'=>"p"

yay

23 Jan 2012, 5:02 PM
#27
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Instant Search

It would be great to be able to separate the in stock results from those out of stock.... hmmmm

23 Jan 2012, 8:23 PM
#28
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Instant Search

figure that out too,

modify this

if (strtolower(substr($prodResult,0,strlen($wordSearch))) == strtolower($wordSearch)){
$results[] = array(

24 Jan 2012, 6:34 PM
#29
ayoobg avatar

ayoobg

New Zenner

Join Date:
Nov 2011
Posts:
34
Plugin Contributions:
1

Re: Instant Search

DigitalShadow:

figure that out too,

modify this

if (strtolower(substr($prodResult,0,strlen($wordSearch))) == strtolower($wordSearch)){
$results[] = array(

Not Bad!

25 Jan 2012, 7:15 AM
#30
li_he_qi avatar

li_he_qi

New Zenner

Join Date:
Dec 2010
Posts:
12
Plugin Contributions:
0

Re: Instant Search

Thank you AyoobG for your long answer!
For my customized need, I have found a very similar add-on from: advancebydesign dot com , which exactly do what I expect. many thanks to Robert, the author.
After testing it for some time, I also made a little changes to it to resolve known issues:

1.change:

$sql = "SELECT products_name,products_id from ". TABLE_PRODUCTS_DESCRIPTION ." ORDER BY products_name ASC";

to:

$sql = "SELECT " . TABLE_PRODUCTS_DESCRIPTION . ".products_name, " . TABLE_PRODUCTS_DESCRIPTION . ".products_id, " . TABLE_PRODUCTS .
".products_status
FROM " . TABLE_PRODUCTS_DESCRIPTION . ", " . TABLE_PRODUCTS . "
WHERE " . TABLE_PRODUCTS . ".products_id = " . TABLE_PRODUCTS_DESCRIPTION . ".products_id
AND " . TABLE_PRODUCTS . ".products_status <> 0
AND language_id = '" . (int)$_SESSION['languages_id'] . "'
ORDER BY " . TABLE_PRODUCTS_DESCRIPTION . ".products_name ASC";

  1. to disable links in the search results, change:

1:0

to

0:0

edit the correponding file where you plan to put the search box, such as: tpl_search_header.php, tpl_advance_search_default.php, tpl_search.php

the only remaining problem is that it comflicts with almost all the JS-related add-ons, such as "JQ lightbox, click-show-hide-category, bcastr header banner player", not big issue, all the add-ons still work
if you look at the source code, once we begin to type in the search box, all the loaded files from this add-on come into the <body> part from the <header> part.

5 Feb 2012, 1:27 AM
#31
mikeyg avatar

mikeyg

Totally Zenned

Join Date:
May 2005
Posts:
515
Plugin Contributions:
0

Re: Instant Search

I have just installed this mod and it works as expected. However I then realised that my AJAX Image swapper was not working.

There appears to be a conflict with the JQuery.js file. if I remove it ( and the call to it in the instantsearch.js file as explained above in an earlier post then the AJAX IMAGE SWAPPER mode works again but not the instant search.

I seem to have so many versions of Jquery, mootools, slimbox in various subdirectories under ...mytemplate/jscript/... I am not sure which are needed as they have obviously been installed by various modules.

Can you explain how to avoid the conflict and is it possible to call the correct file that is required by each specific module to avoid the conflict.

Thanks

7 Feb 2012, 10:10 PM
#32
ayoobg avatar

ayoobg

New Zenner

Join Date:
Nov 2011
Posts:
34
Plugin Contributions:
1

Re: Instant Search

MikeyG:

I have just installed this mod and it works as expected. However I then realised that my AJAX Image swapper was not working.

There appears to be a conflict with the JQuery.js file. if I remove it ( and the call to it in the instantsearch.js file as explained above in an earlier post then the AJAX IMAGE SWAPPER mode works again but not the instant search.

I seem to have so many versions of Jquery, mootools, slimbox in various subdirectories under ...mytemplate/jscript/... I am not sure which are needed as they have obviously been installed by various modules.

Can you explain how to avoid the conflict and is it possible to call the correct file that is required by each specific module to avoid the conflict.

Thanks

It seems to me you may have 2 or more different versions of jQuery (i.e 1.3---1.4...). One version works perfectly with the image swapper and the other works perfectly with the instant search.

Instant search uses jQuery v1.6.4.
If you want you can remove the jQuery file that came with instant search and then recode instantSearch.js to work with the same version of jQuery you are using for image swapper.

8 Feb 2012, 12:47 AM
#33
lala_rock avatar

lala_rock

New Zenner

Join Date:
Dec 2011
Posts:
41
Plugin Contributions:
0

Re: Instant Search

Hi, I would like to customise the look of this module for my site. Managed to make some changes but noticed that some of the letters are cut. For instance when I typed in Magnetic Clamp, the letters g and p are cut. And can you explain to me why on my screen it was aligned with the edge of the site (the red band) while on other resolutions it was not aligned. Here are the screenshots for you to understand more

Here is output on my screen (1280 x 1024 screen resolution)

Attachment #10113

here is for the 1366 x 768 screen resolution

Attachment #10114

and here is for the 1920 x 1080 screen resolution

Attachment #10115

Thanks in advance

8 Feb 2012, 12:12 PM
#35
mikeyg avatar

mikeyg

Totally Zenned

Join Date:
May 2005
Posts:
515
Plugin Contributions:
0

Re: Instant Search

I did have a go at that by changing the reference to a different file but it did not seem to work.

I will look again at what I did.... unfortunately I am a small business owner with a programming interest rather than a developer with Jquery or php skills and so my atttempts are more than likely to have missed somethinig or been miss directed. Any clues or pointers to the bits to amend would be gladley welcome.

Thank you in advance.

Mikeyg

9 Feb 2012, 6:57 PM
#36
ayoobg avatar

ayoobg

New Zenner

Join Date:
Nov 2011
Posts:
34
Plugin Contributions:
1

Re: Instant Search

lala rock:

and BTW here is the link to my site https://spares.cncmachinery.com.au

The words get cut off because the product name is too big to fit into the search box, so infact it gets hidden under the next line.

sometimes you can just about see these words so if you want to show or hide them then you need to increase/decrease the line-height or decrease/increase the height value in instantSearch.css for .resultsContainer a

to sort out the screen resolution problem backup and replace your instantSearch.js with the following:

/**
 * @package Instant Search Results
 * @copyright Copyright Ayoob G 2009-2011
 * @copyright Portions Copyright 2003-2006 The Zen Cart Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 */


//This jScript file is used to create our instant search box


//these var's will be used to maintain multiple request
var runningRequest = false;
var request;

//if you want to manually position the result box you can set autoPosition to false
//but make sure to provide the top and left value in instantSearch.css
var autoPosition = true;
var offset_left = 280;
var offset_top = 0;


var inputboxCurrent;

//checks to see if the document has loaded and is ready
$(document).ready(function () {


	//this will apply the instant search feature to all the search boxes
    var inputBox = $('input[name="keyword"]');

	//if you want to add instant search to only a specific box then comment out the var inputBox above
	//and uncomment out the specific search box selector bellow:
	
	//var inputBox = $('#navMainSearch > form[name="quick_find_header"] > input[name="keyword"]');
    //var inputBox = $('#navColumnTwoWrapper > form[name="quick_find_header"] > input[name="keyword"]');
	//var inputBox = $('#searchContent > form[name="quick_find"] > input[name="keyword"]');
	
	
	//this adds a instant search container bellow the search box
	inputBox.before('<div class="resultsContainer" ></div>');
	inputBox.attr('autocomplete', 'off');
	
	//re-position all the instant search container correctly into their places
	if (autoPosition == true){
		inputBox.each(function (index) {
			var offset = $(this).offset();
			$(this).prev().css("left", offset.left + "px");
			$(this).prev().css("top", ($(this).outerHeight(true) + offset.top) + "px");
		});
	}


	//if the search box losses focus, then the instant search container will be hidden
    inputBox.blur(function () {
        if (inputboxCurrent) {
            var resultsContainer = inputboxCurrent.prev();
            resultsContainer.delay(300).slideUp(200);
        }
    });


	//if we resize the browser or zoom in or out of a page then the instant search container will be hidden
	$(window).resize(function() {
        if (inputboxCurrent) {
            var resultsContainer = inputboxCurrent.prev();
            resultsContainer.hide();
        }
	});


	//the user starts to enter a few characters into the search box
    inputBox.keyup(function () {

		//only the currently selected search box will be used
        inputboxCurrent = $(this);

		//assign a variable to the instant search container
        var resultsContainer = $(this).prev();

        //we capture the words that are being typed into the search box
        var searchWord = $(this).val();
		var replaceWord = searchWord;
		
		//we clean up the word for any unnecessary characters or double spaces
        searchWord = searchWord.replace(/^\s+/, "");
        searchWord = searchWord.replace(/  +/g, ' ');

       
        if (searchWord == "") {

            //if the search value entered is empty, we then hide the instant search container	
            resultsContainer.hide();

        } else {

            //if multiple requests are sent to the server, we then abort any previous request, before a new request is sent
			//this only comes in use if user is a fast typer
            if (runningRequest) {
                request.abort();
            }

            runningRequest = true;
           
			//we then pass on the search word to searches.php
			//searches.php will then look for all the search results 
            request = $.getJSON('searches.php', {query: searchWord}, function (data) {
                
				
                if (data.length > 0) {
                    var resultHtml = '';
                    $.each(data, function (i, item) {
						//if any search result are found, a link will be created and placed into the instant search container
                        resultHtml += '<li><a href="' + generateLink(item.pc,item.l) + '"><span class="alignRight" style="border:1px solid #fff;">' + formatNumber(item.c) + '</span>' + highlightWord(replaceWord,item.q) + '</a></li>';
                    });

					
					//fill the container with the matching products and categories
                    resultsContainer.html('<ul><li><span style="font:12px; font-weight:bold; border:1px #fff; position:relative; left:5px; top:9px; ">Quick Search Result</span> <span class="No_text" style="border:1px #fff">No.</span><hr/></li>'+resultHtml+'</ul>');

					
                    if (!resultsContainer.is(':visible')) {
						
						//auto position container if needs be
						if (autoPosition == true){
							autoPositionContainer(inputboxCurrent, resultsContainer);
						}
						
						//drop down instant search box
                        resultsContainer.slideDown(100);
                    }
					
                } else {
                    resultsContainer.hide();

                }

                runningRequest = false;
            });
        }
    });
});

//this function auto positions the container
function autoPositionContainer(inputBoxCurr, resltsContainer){
	var offsetInput = inputBoxCurr.offset();
	var overFlow = offsetInput.left + resltsContainer.outerWidth(true);
	var winWidth = $(document).width();
	
	if (overFlow > winWidth){ // this checks to see if the container overflows on the right of the window
		var dif = overFlow - winWidth;
		
		if ((offsetInput.left - dif) < 0){// this checks to see if the container overflows on the left of the window
			resltsContainer.css("left", 0 + "px");
		}else{
			if (offset_left > 0){
				resltsContainer.css("left", (offsetInput.left - offset_left)  + "px");
			}else{
				resltsContainer.css("left", (offsetInput.left - dif) + "px");
			}
		}
	}else{
		resltsContainer.css("left", (offsetInput.left - offset_left)  + "px");
	}
	resltsContainer.css("top", (inputBoxCurr.outerHeight(true) + offsetInput.top + offset_top) + "px");
}

//this function creates the link back to the matching products or categories
function generateLink(productORcategory, productCategoryID)
{
	var l = "";
	if (productORcategory == "p"){
		l = "index.php?main_page=product_info&products_id=" + productCategoryID;
	}else{
		l = "index.php?main_page=index&cPath=" + productCategoryID;
	}
	
	return l;

}


function highlightWord(findTxt,replaceTxt)
{
	var f = findTxt.toLowerCase();
	var r = replaceTxt.toLowerCase();
	var regex = new RegExp('(' + f + ')', 'i');
	return r.replace(regex, '<span class="thinFont" style="background-color:#f8ee4e; border:1px solid #fff;">' + f + '</span>')
	
}

function formatNumber(num)
{
	return num.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
	
}

then locate and change the values for:

var offset_left = 280;
var offset_top = 0;

and change them to your desired positions i.e if i want my box to be 30px left and 20px top then:

var offset_left = 30;
var offset_top = 20;

9 Feb 2012, 6:57 PM
#37
ayoobg avatar

ayoobg

New Zenner

Join Date:
Nov 2011
Posts:
34
Plugin Contributions:
1

Re: Instant Search

MikeyG:

I did have a go at that by changing the reference to a different file but it did not seem to work.

I will look again at what I did.... unfortunately I am a small business owner with a programming interest rather than a developer with Jquery or php skills and so my atttempts are more than likely to have missed somethinig or been miss directed. Any clues or pointers to the bits to amend would be gladley welcome.

Thank you in advance.

Mikeyg

if you give me a link to your site i will try to locate the problem

10 Feb 2012, 8:11 AM
#38
lala_rock avatar

lala_rock

New Zenner

Join Date:
Dec 2011
Posts:
41
Plugin Contributions:
0

Re: Instant Search

hi thanks a lot! it worked except for one. Why is it the letter being highlighted is cut horizontally? like the letter g and p for instance?. Ive tried to increase the height of .alignRight but it only increases the height but the letter is still cut. Again thanks a lot for your help.

11 Feb 2012, 12:15 AM
#39
ayoobg avatar

ayoobg

New Zenner

Join Date:
Nov 2011
Posts:
34
Plugin Contributions:
1

Re: Instant Search

lala rock:

hi thanks a lot! it worked except for one. Why is it the letter being highlighted is cut horizontally? like the letter g and p for instance?. Ive tried to increase the height of .alignRight but it only increases the height but the letter is still cut. Again thanks a lot for your help.

Hi,
I now understand what you mean. I was viewing your site in firefox, so i couldn't understand what was going on. The tails get cut of horizontally because the height of the line is small, you will need to open **instantSearch.css **and increase the **height **in .resultsContainer a { you will also need to add line-height

Here's a brief explanation of these properties:
height: this controls the height of the line if its small then the words get cut off. if its big, then it looks stupid.
line-height: this controls the line seperation for long product names (i.e product names that can not fit into 1 line)

Change your code from:

.resultsContainer a {
display : block;
color : #000;
background-color : #fff;
padding : 0.1em 0.4em;
text-decoration : none;
overflow:hidden;
height:18px;
}

into:
**
.resultsContainer a {
display : block;
color : #000;
background-color : #fff;
padding : 0.1em 0.4em;
text-decoration : none;
overflow:hidden;
height:100%;
line-height:100%;
}**

You then have to test different values for both height: and line-height: to see which works best. (if you want to work in pixels then change **% **into px)

for compatibility you may have to see how it looks in chrome and firefox (a lot of users use these browsers)

12 Feb 2012, 11:34 AM
#40
mikeyg avatar

mikeyg

Totally Zenned

Join Date:
May 2005
Posts:
515
Plugin Contributions:
0

Re: Instant Search

AyoobG,

Thank you. it currently sits on my testing server at home so not visible to the public. Is it as simple as just making sure each mod points to its own file or once they are loaded are the clashes related to the names of functions etc in the various jquery files being loaded a few times from different versions ( I belive these files get preloaded)