Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

V4 - auto search using vars in url

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #11  
Old 05-13-2005, 12:23 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default

Excellent! Just what I was looking for. I needed to show a list of all products from a link but using a specific sort field and direction:

Code:
<?php $substr = $_GET['q']; $sort_field = $_GET['s']; $sort_direction = $_GET['d']; ?> <HTML> <BODY onLoad="document.process.submit();"> <TABLE width="100%" height="100%"> <TR> <TD align="center" valign="middle" /> <FORM action="search.php" method="POST" name="process" /> <INPUT type="hidden" name="simple_search" value="Y" /> <INPUT type="hidden" name="mode" value="search" /> <INPUT type="hidden" name="posted_data[by_title]" value="Y" /> <INPUT type="hidden" name="posted_data[by_shortdescr]" value="Y" /> <INPUT type="hidden" name="posted_data[by_fulldescr]" value="Y" /> <script>document.write('Please wait while searching...')</script> <noscript> <h3>JavaScript is disabled in your browser.</h3> <INPUT type="submit" name="submit1" value="Continue >>" /> </noscript> <INPUT type="hidden" name="posted_data[substring]" value="<?php echo $substr ?>"> <INPUT type="hidden" name="posted_data[sort_field]" value="<?php echo $sort_field ?>"> <INPUT type="hidden" name="posted_data[sort_direction]" value="<?php echo $sort_direction ?>"> </FORM> </TD> </TR> </TABLE> </BODY>

but sort_field and sort_direction are not recognized like this normally so I added the following to include/search.php:

Code:
if ($posted_data["sort_field"]) $search_data["products"]["sort_field"] = $posted_data["sort_field"]; if ($posted_data["sort_direction"]) $search_data["products"]["sort_direction"] = $posted_data["sort_direction"];

above:

Code:
if (empty($search_data["products"]["sort_field"])) { $posted_data["sort_field"] = "title"; $posted_data["sort_direction"] = 0; }

now a string could be used like:

Code:
/auto_search.php?q=&s=price&d=1

if someone knows an easier way, please post.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
  #12  
Old 06-20-2005, 03:37 PM
  wjbrewer's Avatar 
wjbrewer wjbrewer is offline
Banned
 

X-Adept
  
Join Date: Feb 2005
Location: Pittsburgh, PA
Posts: 504
 

Default

Great Mod!

Add a link to your CSS file and it will match your site.
Reply With Quote
  #13  
Old 06-21-2005, 03:38 PM
  groovico's Avatar 
groovico groovico is offline
 

X-Man
  
Join Date: Apr 2003
Location: Firetanksoftware.com
Posts: 2,326
 

Default

just what i was looking for excellent!
__________________
Groovico

Used by X-carters the world over:
Marketing Manager Pro Bundle For X-cart
Featured Product Manager for X-cart
Feed manager pro for X-cart

http://www.firetanksoftware.com

Celebrating 7 Years of providing quality X-cart Add ons and X-cart Mods for x-cart 3.X to X-cart 4.4.X
Reply With Quote
  #14  
Old 06-25-2005, 10:07 PM
 
bluecat bluecat is offline
 

X-Adept
  
Join Date: Nov 2002
Posts: 674
 

Default

Hmmm, can anyone advise if they DIDN'T get this to work? My page simply freezes when I run a search.
__________________
--------------------
X-Cart Gold 4.1.11
Linux/Apache
--------------------
Reply With Quote
  #15  
Old 06-25-2005, 10:23 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default

Quote:
Originally Posted by bluecat
Hmmm, can anyone advise if they DIDN'T get this to work? My page simply freezes when I run a search.

Not sure what you mean by "freezes"? If you end up with a blank page then it might be an error with your php code.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
  #16  
Old 06-27-2005, 07:16 PM
 
bluecat bluecat is offline
 

X-Adept
  
Join Date: Nov 2002
Posts: 674
 

Default

It shows the "searching products..." page, but never results in any searches. I tried both codes that were posted.
__________________
--------------------
X-Cart Gold 4.1.11
Linux/Apache
--------------------
Reply With Quote
  #17  
Old 06-27-2005, 08:21 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default

Quote:
Originally Posted by bluecat
It shows the "searching products..." page, but never results in any searches. I tried both codes that were posted.

Does it continually say "searching..." or does it eventually come up with a list of 0 products found? Sorry, just trying to clarify.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
  #18  
Old 06-27-2005, 09:58 PM
 
bluecat bluecat is offline
 

X-Adept
  
Join Date: Nov 2002
Posts: 674
 

Default

Np, I appreciate the help. I have to correct myself; I actually let it sit for about 3 to 4 minutes, and it finally resolved; however, it actually lists every product in our store (about 1800 items). So now I'm totally confused, lol.
__________________
--------------------
X-Cart Gold 4.1.11
Linux/Apache
--------------------
Reply With Quote
  #19  
Old 06-30-2005, 12:34 PM
 
bluski bluski is offline
 

Newbie
  
Join Date: May 2005
Posts: 4
 

Default

Got the same thing... all products are coming up when using the $substr= as a call.

But after you've implemented php code:

<?php
$substr = $_GET['q'];
?>

to hide the javascript - I've found that the only way to get your specific results is to use the link code:

(using the words "joe schmoo" as value of an extra field)

test

instead of:

test

I don't know enough about PHP to fix this other than the link code mentioned above.

The extra field is added as a hidden input on search.tpl
<INPUT type="hidden" name="posted_data[extra_fields][1]" value="Y">
__________________
4.1.5 Gold
Reply With Quote
  #20  
Old 06-30-2005, 12:44 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default

Yes, you'd have to use a get string of "...auto_search.php?q=joe..." because "q" is the thing you use with $_GET['q'] (getting 'q').

Also, "...?q=joe&schmoo" is not a search for "joe schmoo". The "schmoo" would get pulled in as a another key, so you would end up searching for just "joe". If you want to add "joe schmoo" to your get string link then it would have to look like "...?q=joe%20schmoo".
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 07:24 AM.

   

 
X-Cart forums © 2001-2020