![]() |
Search Upgrade
Hi Everyone,
I have modified the advanced search so that the customer can search not only the main categories, but also the first level of sub categories. For example currently x-cart has: Code:
All I modified is so that it has the following: Code:
All Here's how I did it. I modified categories.php by adding the following... Code:
# Then I modified the customer/main/advancedsearch.tpl by replacing the drop down box code with the following: Code:
<select name="in_category"> My question is this: Can anyone figure out how I can modify the subcategories so that only the subcategory shows up in the drop down box? So it would be - Code:
All I would really appreciate any help I am brain farting at the moment. So, if you like code return a favor :) Thanks everyone. |
{$categories_level_2[cat_num][0][cat_num1].category_name|escape}
I spend ages working that one out for a drop down menu system for a site. :lol: Nice coding 8) |
FD,
Thanks for the complement. I tried implementing your solution. It printed the values of the select options, but not the select options. I don't have a category_name column in my table (3.3.6) so that may be the problem. Here is a list of my xcart_categories table columns: categoryid image_x image_y category description meta_tags avail views_stats order_by membership threshold_bestsellers Any ideas? Thanks again :!: |
There isn't in mine either - but it does a little ditty with the dbase query in include/categories.php:
This may be missing from your coding :) |
My categories.php code: (version 3.4.2)
Code:
<? Then in the categories.tpl you could have something like: Code:
{section name=cat_num loop=$categories} This shows each main section then that section subsections under it... Cat 1 - sub cat 1 - sub cat 2 Cat 2 - sub cat 3 - sub cat 4 etc hth :) |
Heck yeah, it worked really well. I simply updated my SQL statement from:
Code:
$categories_data2[$key][] = func_query("select * from $sql_tbl[categories] where category LIKE '".$value[category]."/%' and category NOT LIKE '".$value[category]."/%/%' and avail='Y' group by $sql_tbl[categories].categoryid order by order_by"); To: Code:
$categories_data2[$key][] = func_query("select $sql_tbl[categories].*, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', -1) as category_name from $sql_tbl[categories] where category LIKE '".$value[category]."/%' and category NOT LIKE '".$value[category]."/%/%' and avail='Y' group by $sql_tbl[categories].categoryid order by order_by"); Thanks a ton, I would have never of guessed to updated my SQL statement, I was stuck on a PHP solution. :oops: |
I do that...get caught up solving a really big issue and some smart r's comes along :lol:
BTW - if someone wants to use the code above to produce a javascript drop down menu (that's what I used it for - obviously stripped the JS out for this post) then feel free. |
I didn't catch that the first 3 times, can you please repeat it?
:lol: |
Yeah alright already, we heard you the first time ;)
Someone prod funky he's gone into a loop. |
slight connection problem - just kept pressing submit :lol:
Code:
<?php welcome to my loop :) |
yes - i know - i should get a life. :lol:
|
Quote:
OK guys, anyone who got that is now officially a code geek. Welcome to the club. :P |
{assign var="horror" value="on"} :lol:
|
do know what's worse - i just corrected the code cos i was missing a ;
arrrrrrrrrrrrrrrrrrrrrrrrrrrgggggggggghhhhhhhhhhhh hh |
:lol:
|
Anyone figured out how to arrange the results of a search by price but have it go from most expensive to least expensive? I have modified my search so that I can order by add_date which is in DESC order, but I can't crack the price.
Just curious. In return, I can post my add_date mod if someone requests it. Thanks again :!: |
Nevermind, I figured it out.
|
Looking for code clarity
Even though I did understand "funky's loop" I'm not getting this search mod to work.
To my categories.php file I added before the # Assign Smarty variables this code: Quote:
Quote:
Quote:
{ $categories_level_2[cat_num][0][cat_num1].categoryid} with funky's line, but I still get the same results. Can one of the wizards out there post the code I should use? Thanks :-) Cameron |
Cameron,
That code is going to go right in here: Code:
{section name=cat_num1 loop=$categories_level_2} Replace the {$categories_level_2[cat_num][0][cat_num1].category|escape} with {$categories_level_2[cat_num][0][cat_num1].category_name|escape}. Hope that helps. |
Thanks for the fast reply :-)
my advanced_search.tpl file now contains Quote:
{$categories_level_1[cat_num].category|escape} to {$categories_level_1[cat_num].category_name|escape} but that didn't help either. I'm stumped. Could I have gone wrong with putting together the code for categories.php? |
Just out of curiousity, do you have a URL I could look at?
|
Yep :) http://www.strollers.com/store/customer/search.php
I modified my search.php to expand the search to include anything in the descriptions, but other than that it is untouched. and in case I did something wrong in my categories.php, here is my whole file Quote:
Thanks, Cameron |
Cameron,
Glad you posted your code. Add this to the bottom where all the other smarty assignments are: Code:
$smarty->assign("categories_level_1",$categories_data1); Also, You can remove the following "last" line of code: Code:
$categories_data2[$key][category] = strrchr($categories_data2[$key][category], "/"); It should work now, I think :wink: |
Cool! It works!!! One (hopefully) last question though. How do I get it to display all of the subcategories instead of just the first five? I have 20 2nd level categories under one of my main categories, and 7-8 in the others.
Thanks! Cameron |
Cameron,
The mod is designed to only show the first level of sub categories under each main category. If you search any if the categories, the search automatically searchs all the subcategories under it. If you still want all your categories and subcategories listed, do the following: Replace the following lines of code in your advanced_search.tpl file: Code:
<select name="in_category"> with: Code:
<select name="in_category"> It's not as pretty, but it gets the job done. |
I think I asked the question in a murky way. I only have 2 levels of categories. The changes I made so far with your help are working. However, for my second level categories, it is only showing the first 5 second level categories, even if I have 8, 9, or 20 other second level categories.
If you look at http://www.strollers.com/store/customer/home.php?cat=3 and then at http://www.strollers.com/store/customer/search.php you will see that in the drop down box for categories, it shows the first 5 stroller brands only, but I would like it to show all 20 or so. Thanks, Cameron |
Cameron,
Just so I can see your db structure, change the code with the last post I put up and then let me know. I think this might have to do with the way your categories are stored. We'll change the code back after I have a look. |
I see what you're after now. I put it in as {section name=cat_num loop=$allcategories} which is what my categories.php has in it. (all_categories shows no categories.) What is odd is that it shows my main categories, then the rest of the categories aren't there, but there is space where they would be at.
|
Very strange indeed. Good call on the code, I'll edit my previous post now.
What does your xcart_categories table structure look like? PM me the exported file (if you have phpmyadmin) or post it (with contents) on the board, so I can have a look. |
categoryid
image_x image_y category description meta_tags avail views_stats order_by membership threshold_bestsellers Is that what you're looking for? |
Partly, if you could post the contents of the table (along with the headings) it would help. If you don't want that on the boards, pm me it in a CSV file and I can look on my own machine.
|
This is crazy. I got an e-mail that you PM'd me, but the PM isn't in my inbox. I then PM'd you 3 times, but none of them show in my sent items. Can you e-mail me your e-mail address? I'm at cameron@cameron32.com
|
If you use the code that I posted on earlier on this thread for categories.php and use the following for advanced search - it works.
Code:
{* $Id: advanced_search.tpl,v 1.3 2002/10/08 12:01:17 alfiya Exp $ *} |
Unfortunately, I'm still on 3.3.5 so I can't use your categories.php -- What seems so odd is that it was mostly working, but it was only displaying the first 5 second level categories instead of all of them, but I can't see what in either categories.php or advanced_search.tpl is making that happen.
|
I got it!!! Funky, I was looking at the advanced_search.tpl code you had and decided to try using $allcategories for the second level categories.
Machnhed1, I had replaced the whole drop down code with the $allcategories code that you had me put in before instead of only the 2nd level part. If I messed up there and was supposed to do it for just the 2nd level section, I apologize profusely for wasting your time. Thank you both for helping me work this out!!!!!!! :) So, for those who have made it this far through this thread and are using 3.3.x , here is what you need to do: Store/include/categories.php Before the lines for # Assign Smarty variables, add this code: Quote:
Quote:
replace <select name="in_category"> <option value="">All</option> {section name=cat_num loop=$categories} <option value="{ $categories[cat_num].categoryid}" {if $smarty.get.in_category eq $categories[cat_num].categoryid or $cat eq $categories[cat_num].categoryid}selected{/if}>{$categories[cat_num].category|escape}</option> {/section} </select> with this: Quote:
|
Oops...I just hit another snag here. The search function, even though it is now showing all 2nd level categories is ONLY showing results within a category that has products in it as a "main category" The "category #1 #2 #3 & #4" assignments that you can make in the back office to have a product display in other categories aren't being searched.
As an example: Jogging Strollers has about 16 products in it when you browse directly to the category. However, all of those products are assigned to that category as "Category #3" and when I search Jogging Strollers for *anything* no results appear. I am willing to pay for the solution to this so that the search will show results from my second level categories, even if the products in them aren't put in as the "main category" without creating a ton of duplicate searches when somebody doesn't drill down to a sub category. Funky or anybody who can do this, please PM me with a quote. Wait, x-cart PM is being weird. Please *e-mail* me: cameron@cameron32.com Thanks, Cameron |
Used information within to make subcatagories to be listed at all times on the left side's catagory section. Great post, thank you!
|
X-Cart 4.0.17?
Does anyone have a version of this mod that will work with X-Cart Pro 4.0.17?
|
P.S.
I started a new thread for this for 4.0.x users:
http://forum.x-cart.com/viewtopic.php?p=115113 I dunno if this was the right idea or not but what the hey. |
All times are GMT -8. The time now is 03:24 PM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.