X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Search Upgrade (https://forum.x-cart.com/showthread.php?t=3684)

machnhed1 07-21-2003 07:00 PM

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
Books
CD - DVD - Video
Computer hardware
Electronics
Games and toys
Household
Men Clothes
Software
Sport


I modified is so that it has the following:
Code:

All
Books
  Books/Internet
  Books/Software
CD - DVD - Video
  CD - DVD - Video/Subcat1
  CD - DVD - Video/Subcat2
etc...


Here's how I did it. I modified categories.php by adding the following...
Code:

#
# Mod: Get all main categories and level 1 subcatgories and store them in an array
#
$categories_data1 = func_query("select * from $sql_tbl[categories] where category NOT LIKE '%/%' and avail='Y' group by $sql_tbl[categories].categoryid order by order_by");

foreach ($categories_data1 as $key=>$value) {
        $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");
        $categories_data2[$key][category] = strrchr($categories_data2[$key][category], "/");
        }


Then I modified the customer/main/advancedsearch.tpl by replacing the drop down box code with the following:
Code:

<select name="in_category">
          <option value="">All</option>         
{section name=cat_num loop=$categories_level_1}
          <option value="{ $categories_level_1[cat_num].categoryid}" {if $smarty.get.in_category eq $categories_level_1[cat_num].categoryid or $cat eq $categories_level_1[cat_num].categoryid}selected{/if}>
          {$categories_level_1[cat_num].category|escape}
          </option>

{section name=cat_num1 loop=$categories_level_2}
          {if $categories_level_2[cat_num][0][cat_num1].categoryid ne ""}<option value="{ $categories_level_2[cat_num][0][cat_num1].categoryid}" {if $smarty.get.in_category eq $categories_level_2[cat_num][0][cat_num1].categoryid or $cat eq $categories_level_2[cat_num][0][cat_num1].categoryid}selected{/if}>
          {$categories_level_2[cat_num][0][cat_num1].category|escape}
          </option>{/if}     
{/section}
                         
{/section}
        </select>


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
Books
  Internet
  Software
CD - DVD - Video
  Subcat1
  Subcat2
etc...


I would really appreciate any help I am brain farting at the moment. So, if you like code return a favor :)

Thanks everyone.

funkydunk 07-22-2003 11:15 PM

{$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)

machnhed1 07-23-2003 05:43 AM

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 :!:

funkydunk 07-23-2003 06:21 AM

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 :)

funkydunk 07-23-2003 06:28 AM

My categories.php code: (version 3.4.2)

Code:

<?
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart                                                                      |
| Copyright (c) 2001-2003 Ruslan R. Fazliev <rrf@rrf.ru>                      |
| All rights reserved.                                                        |
+-----------------------------------------------------------------------------+
| PLEASE READ  THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE  |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php                    |
|                                                                            |
| THIS  AGREEMENT  EXPRESSES  THE  TERMS  AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE  PROGRAM  AND  ASSOCIATED  DOCUMENTATION  THAT  RUSLAN  R. |
| FAZLIEV (hereinafter  referred to as "THE AUTHOR") IS FURNISHING  OR MAKING |
| AVAILABLE TO YOU WITH  THIS  AGREEMENT  (COLLECTIVELY,  THE  "SOFTWARE").  |
| PLEASE  REVIEW  THE  TERMS  AND  CONDITIONS  OF  THIS  LICENSE AGREEMENT |
| CAREFULLY  BEFORE  INSTALLING  OR  USING  THE  SOFTWARE.  BY INSTALLING, |
| COPYING  OR  OTHERWISE  USING  THE  SOFTWARE,  YOU  AND  YOUR  COMPANY |
| (COLLECTIVELY,  "YOU")  ARE  ACCEPTING  AND AGREEING  TO  THE TERMS OF THIS |
| LICENSE  AGREEMENT.  IF  YOU    ARE  NOT  WILLING  TO  BE  BOUND BY THIS |
| AGREEMENT, DO  NOT INSTALL OR USE THE SOFTWARE.  VARIOUS  COPYRIGHTS  AND |
| OTHER  INTELLECTUAL  PROPERTY  RIGHTS    PROTECT  THE  SOFTWARE.  THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES  YOU  LIMITED  RIGHTS  TO  USE |
| THE  SOFTWARE  AND  NOT  AN  AGREEMENT  FOR SALE OR FOR  TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT.      |
|                                                                            |
| The Initial Developer of the Original Code is Ruslan R. Fazliev            |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2003          |
| Ruslan R. Fazliev. All Rights Reserved.                                    |
+-----------------------------------------------------------------------------+
\*****************************************************************************/

#
# $Id: categories.php,v 1.46.2.1 2003/06/02 11:57:44 svowl Exp $
#

#
# For users some categories may be disabled
#

if ($current_area == "C") {
        $membership_condition = " AND ($sql_tbl[categories].membership='$user_account[membership]' OR $sql_tbl[categories].membership='') ";
} else {
        $membership_condition = "";
}

$categories_data = func_query("select $sql_tbl[categories].*, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', -1) as category_name from $sql_tbl[categories] ".($current_area=="C"?"where $sql_tbl[categories].avail='Y' $membership_condition ":"")." group by $sql_tbl[categories].categoryid order by ".($current_area=="C" ? "order_by" : "category"));


#
# Put all categories into $all_categories array and find current_category
# by categoryid stored in $cat
#
if(!$categories_data) $categories_data = array();


foreach($categories_data as $k=>$category_data) {
        if ($current_area == "C") {
                $int_res = func_query_first("SELECT * FROM $sql_tbl[categories_lng] WHERE code='$store_language' AND categoryid='$category_data[categoryid]'");
                if ($int_res["category"])
                        $categories_data[$k]["category_name"] = $category_data["category_name"] = $int_res["category"];
                if ($int_res["description"])
                        $categories_data[$k]["description"] = $category_data["description"] = $int_res["description"];
        }
        if ($category_data["categoryid"]==$cat) {
                $current_category = $category_data;
        }
       
        // funkydunk code
        // funky
        if(strstr($category_data["category"],"/")) {
        $topcat=strtok($category_data["category"],"/");
        // echo $topcat; // finds the first part of the cat name pre /
        $categories_data[$k]["topcat"]=$topcat;
        $topcat = "";
        }
        // end

}

$all_categories = $categories_data;

#
# Put all root categories to $categories array
# Put all subcategories of current_category to $categories array
#

foreach($all_categories as $all_category) {

        $category=$all_category["category"];

        $cur_dir_len = strlen($current_category["category"]);

        if(!strstr($category,"/")) {
            $categories[]=$all_category;
                        if(empty($current_category)) {
                                $subcategories[]=$all_category;
                        }
        }

        if(substr($category,0,$cur_dir_len+1) == $current_category["category"]."/" and $category!=$current_category["category"])
                if(!strstr(substr($category,$cur_dir_len+1),"/")) {
                        $all_category["category"]=ereg_replace("^.*/","",$all_category["category"]);
                        $subcategories[]=$all_category;
                }

}


#
# Put  subcategory_count  to $subcategories array
#
if ($subcategories)
foreach($subcategories as $key =>$subcategory) {
       
        $subcategory["subcategory_count"]=0;

        foreach($all_categories as $all_category) {
                if ($all_category["categoryid"]==$subcategory["categoryid"]) {               
                        $cur_dir_len = strlen($all_category["category"]);
                        $current_subcategory=$all_category["category"];
                }               
        }
       
        foreach($all_categories as $all_category) {
                $category=$all_category["category"];
                if(substr($category,0,$cur_dir_len+1) == $current_subcategory."/" and $category!=$current_subcategory)
                        if(!strstr(substr($category,$cur_dir_len+1),"/"))
                                $subcategory["subcategory_count"]++;
       
        }
        $subcategories[$key]["subcategory_count"]=$subcategory["subcategory_count"];
       
}
               

#
# Generate category sequence, i.e.
# Books, Books/Poetry, Books/Poetry/Philosophy ...
#

$current_category_array = explode("/",$current_category["category"]);
$prev = $current_category_array[0];
list($key,$val)=each($current_category_array);

$new_array = array($val);

while(list($key,$val)=each($current_category_array)) {
        $new_array[] = $prev."/".$val;
        $prev = $prev."/".$val;
}
unset($current_category_array);

#
# Generate array for displaying categories sequence in location
#

$category_location=array();
reset($all_categories);

$my_cats = array ();

foreach($all_categories as $all_category) {

        $categoryid=$all_category["categoryid"];
        $category=$all_category["category"];

        $my_cats [$categoryid] = $category;
}

asort ($my_cats);

foreach ($my_cats as $categoryid => $category) {
        reset ($new_array);
        while(list($key,$val)=each($new_array)) {
                if ($val==$category) {
                        foreach($categories_data as $category_data) {
                                if ($category_data["categoryid"] == $categoryid)
                                        $val = $category_data["category_name"];
                        }
                        $category_location[]=array(ereg_replace(".*/","",$val),"home.php?cat=".$categoryid);
                }
        }
}

#
# Assign Smarty variables
#

$smarty->assign("allcategories",$all_categories);
$smarty->assign("categories",$categories);
$smarty->assign("subcategories",$subcategories);
$smarty->assign("current_category",$current_category);
$smarty->assign("cat",$cat);
?>


Then in the categories.tpl you could have something like:

Code:

{section name=cat_num loop=$categories}
{ $categories[cat_num].category|escape }
 
{section name=cat_num1 loop=$allcategories}
{if $allcategories[cat_num1].topcat eq $categories[cat_num].category_name}
-{ $allcategories[cat_num1].category_name|escape }

{/if}
{/section}
{/section}


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 :)

machnhed1 07-24-2003 08:04 AM

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:

funkydunk 07-24-2003 08:11 AM

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.

kpayne 07-24-2003 08:14 AM

I didn't catch that the first 3 times, can you please repeat it?

:lol:

groovico 07-24-2003 08:14 AM

Yeah alright already, we heard you the first time ;)

Someone prod funky he's gone into a loop.

funkydunk 07-24-2003 08:30 AM

slight connection problem - just kept pressing submit :lol:

Code:

<?php
$marlboro_light_supply = 20;
while ($workrequired === "shedloads"){
  $caffeine_level ++;
  $sleepmode = "false";
  $mummified_state = "true";
  $chocolate ++;
  $caffeine_level ++;
  $marlboro_light_supply = $marlboro_light_supply - 1;
    {if ($marlboro_light_supply < 2){
    $panicMode = "true";
    $go_to_Shops = "true";
    $run_home_for_money = "true";
    $marlboro_light_supply = 20;
    }
  }
$sleepmode = "true";
?>


welcome to my loop :)

funkydunk 07-24-2003 08:31 AM

yes - i know - i should get a life. :lol:

machnhed1 07-24-2003 08:33 AM

Quote:

Code:
<?php
$marlboro_light_supply = 20;
while ($workrequired === "shedloads"){
$caffeine_level ++;
$sleepmode = "false";
$mummified_state = "true";
$chocolate ++;
$caffeine_level ++;
$marlboro_light_supply = $marlboro_light_supply - 1;
{if ($marlboro_light_supply < 2){
$panicMode = "true";
$go_to_Shops = "true";
$run_home_for_money = "true"
$marlboro_light_supply = 20;
}
}
$sleepmode = "true";
?>


OK guys, anyone who got that is now officially a code geek. Welcome to the club. :P

funkydunk 07-24-2003 08:51 AM

{assign var="horror" value="on"} :lol:

funkydunk 07-24-2003 08:53 AM

do know what's worse - i just corrected the code cos i was missing a ;

arrrrrrrrrrrrrrrrrrrrrrrrrrrgggggggggghhhhhhhhhhhh hh

shan 07-24-2003 12:03 PM

:lol:

machnhed1 07-24-2003 12:29 PM

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 :!:

machnhed1 07-25-2003 11:25 AM

Nevermind, I figured it out.

Cameron 07-25-2003 12:46 PM

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:

#
# Mod: Get all main categories and level 1 subcatgories and store them in an array
#
$categories_data1 = func_query("select * from $sql_tbl[categories] where category NOT LIKE '%/%' and avail='Y' group by $sql_tbl[categories].categoryid order by order_by");

foreach ($categories_data1 as $key=>$value) {
$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");
$categories_data2[$key][category] = strrchr($categories_data2[$key][category], "/");
}
...which I took from two of machnhed1's posts. I think that part is correct. In my advanced_search.tpl I replaced the lines
Quote:

<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:

<select name="in_category">
<option value="">All</option>
{section name=cat_num loop=$categories_level_1}
<option value="{ $categories_level_1[cat_num].categoryid}" {if $smarty.get.in_category eq $categories_level_1[cat_num].categoryid or $cat eq $categories_level_1[cat_num].categoryid}selected{/if}>
{$categories_level_1[cat_num].category|escape}
</option>

{section name=cat_num1 loop=$categories_level_2}
{if $categories_level_2[cat_num][0][cat_num1].categoryid ne ""}<option value="{ $categories_level_2[cat_num][0][cat_num1].categoryid}" {if $smarty.get.in_category eq $categories_level_2[cat_num][0][cat_num1].categoryid or $cat eq $categories_level_2[cat_num][0][cat_num1].categoryid}selected{/if}>
{$categories_level_2[cat_num][0][cat_num1].category|escape}
</option>{/if}
{/section}

{/section}
</select>
But what happens is that in advanced search, the categories list doesn't have any options in it. I saw that funky advised putting in this code: {$categories_level_2[cat_num][0][cat_num1].category_name|escape} but I'm not sure exactly where to put that in. I tried replacing
{ $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

machnhed1 07-25-2003 12:49 PM

Cameron,

That code is going to go right in here:

Code:

{section name=cat_num1 loop=$categories_level_2}
{if $categories_level_2[cat_num][0][cat_num1].categoryid ne ""}<option value="{ $categories_level_2[cat_num][0][cat_num1].categoryid}" {if $smarty.get.in_category eq $categories_level_2[cat_num][0][cat_num1].categoryid or $cat eq $categories_level_2[cat_num][0][cat_num1].categoryid}selected{/if}>
{$categories_level_2[cat_num][0][cat_num1].category|escape}
</option>{/if}
{/section}


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.

Cameron 07-25-2003 01:16 PM

Thanks for the fast reply :-)

my advanced_search.tpl file now contains
Quote:

<select name="in_category">
<option value="">All</option>
{section name=cat_num loop=$categories_level_1}
<option value="{ $categories_level_1[cat_num].categoryid}" {if $smarty.get.in_category eq $categories_level_1[cat_num].categoryid or $cat eq $categories_level_1[cat_num].categoryid}selected{/if}>
{$categories_level_1[cat_num].category|escape}
</option>

{section name=cat_num1 loop=$categories_level_2}
{if $categories_level_2[cat_num][0][cat_num1].categoryid ne ""}<option value="{ $categories_level_2[cat_num][0][cat_num1].categoryid}" {if $smarty.get.in_category eq $categories_level_2[cat_num][0][cat_num1].categoryid or $cat eq $categories_level_2[cat_num][0][cat_num1].categoryid}selected{/if}>
{$categories_level_2[cat_num][0][cat_num1].category_name|escape}
</option>{/if}
{/section}

{/section}
</select>
...but, the categories still don't show. I also tried changing
{$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?

machnhed1 07-25-2003 01:18 PM

Just out of curiousity, do you have a URL I could look at?

Cameron 07-25-2003 01:22 PM

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:

<?
/************************************************** ***************************\
+-----------------------------------------------------------------------------+
| X-Cart |
| Copyright (c) 2001-2002 Ruslan R. Fazliev. All rights reserved. |
+-----------------------------------------------------------------------------+
| The Ruslan R. Fazliev forbids, under any circumstances, the unauthorized |
| reproduction of software or use of illegally obtained software. Making |
| illegal copies of software is prohibited. Individuals who violate copyright |
| law and software licensing agreements may be subject to criminal or civil |
| action by the owner of the copyright. |
| |
| 1. It is illegal to copy a software, and install that single program for |
| simultaneous use on multiple machines. |
| |
| 2. Unauthorized copies of software may not be used in any way. This applies |
| even though you yourself may not have made the illegal copy. |
| |
| 3. Purchase of the appropriate number of copies of a software is necessary |
| for maintaining legal status. |
| |
| DISCLAIMER |
| |
| THIS SOFTWARE IS PROVIDED BY Ruslan R. Fazliev ``AS IS'' AND ANY |
| EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| DISCLAIMED. IN NO EVENT SHALL Ruslan R. Fazliev OR ITS |
| CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| |
| The Initial Developer of the Original Code is Ruslan R. Fazliev. |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2002 |
| Ruslan R. Fazliev. All Rights Reserved. |
+-----------------------------------------------------------------------------+
\************************************************* ****************************/

#
# $Id: categories.php,v 1.43 2002/11/14 07:58:18 zorg Exp $
#

#
# For users some categories may be disabled
#

#for increase speed
$enable_subcategories_count = $config["General"]["count_products"]=="Y"?1:0;

if ($current_area == "C") {
$membership_condition = " AND ($sql_tbl[categories].membership='$user_account[membership]' OR $sql_tbl[categories].membership='') ";
} else {
$membership_condition = "";
}

$categories_data = func_query("select $sql_tbl[categories].*, 0 as product_count from $sql_tbl[categories] ".($current_area=="C"?"where $sql_tbl[categories].avail='Y' $membership_condition ":"")." group by $sql_tbl[categories].categoryid order by ".($current_area=="C" ? "order_by" : "category"));

#
# Put all categories into $all_categories array and find current_category
# by categoryid stored in $cat
#
if(!$categories_data) $categories_data = array();

$all_categories = $categories_data;

foreach($categories_data as $category_data) {
if ($category_data["categoryid"]==$cat) {
$current_category = $category_data;
$current_category["product_count"] = array_pop(func_query_first("SELECT COUNT(*) FROM $sql_tbl[products] WHERE (categoryid=$category_data[categoryid] OR categoryid1=$category_data[categoryid] OR categoryid2=$category_data[categoryid] OR categoryid3=$category_data[categoryid]) and $sql_tbl[products].forsale='Y'"));
}
}

#
# Put all root categories to $categories array
# Put all subcategories of current_category to $categories array
#

foreach($all_categories as $all_category) {

$category=$all_category["category"];

$cur_dir_len = strlen($current_category["category"]);

if(!strstr($category,"/")) {
$categories[]=$all_category;
if(empty($current_category)) {
if($enable_subcategories_count)
$all_category["product_count"]=array_pop(func_query_first("SELECT COUNT(*) FROM $sql_tbl[products] WHERE $sql_tbl[products].forsale='Y' and (categoryid='$all_category[categoryid]' OR categoryid1='$all_category[categoryid]' OR categoryid2='$all_category[categoryid]' OR categoryid3='$all_category[categoryid]')"));
$subcategories[]=$all_category;
}
}

if(substr($category,0,$cur_dir_len+1) == $current_category["category"]."/" and $category!=$current_category["category"])
if(!strstr(substr($category,$cur_dir_len+1),"/")) {
if($enable_subcategories_count)
$all_category["product_count"]=array_pop(func_query_first("select count(*) from $sql_tbl[products] where $sql_tbl[products].forsale='Y' and (categoryid='$all_category[categoryid]' OR categoryid1='$all_category[categoryid]' OR categoryid2='$all_category[categoryid]' OR categoryid3='$all_category[categoryid]')"));
$all_category["category"]=ereg_replace("^.*/","",$all_category["category"]);
$subcategories[]=$all_category;
}

}
#
# Put subcategory_count to $subcategories array
#
if ($subcategories)
foreach($subcategories as $key =>$subcategory) {

$subcategory["subcategory_count"]=0;

foreach($all_categories as $all_category) {
if ($all_category["categoryid"]==$subcategory["categoryid"]) {
$cur_dir_len = strlen($all_category["category"]);
$current_subcategory=$all_category["category"];
}
}

foreach($all_categories as $all_category) {
$category=$all_category["category"];
if(substr($category,0,$cur_dir_len+1) == $current_subcategory."/" and $category!=$current_subcategory)
if(!strstr(substr($category,$cur_dir_len+1),"/"))
$subcategory["subcategory_count"]++;
}
$subcategories[$key]["subcategory_count"]=$subcategory["subcategory_count"];
}

#
# Generate category sequence, i.e.
# Books, Books/Poetry, Books/Poetry/Philosophy ...
#

$current_category_array = explode("/",$current_category["category"]);
$prev = $current_category_array[0];
list($key,$val)=each($current_category_array);

$new_array = array($val);

while(list($key,$val)=each($current_category_array )) {
$new_array[] = $prev."/".$val;
$prev = $prev."/".$val;
}
unset($current_category_array);

#
# Generate array for displaying categories sequence in location
#

$category_location=array();
reset($all_categories);

$my_cats = array ();

foreach($all_categories as $all_category) {

$categoryid=$all_category["categoryid"];
$category=$all_category["category"];

$my_cats [$categoryid] = $category;
}

asort ($my_cats);

foreach ($my_cats as $categoryid => $category) {
reset ($new_array);
while(list($key,$val)=each($new_array))
if ($val==$category) $category_location[]=array(ereg_replace(".*/","",$val),"home.php?cat=".$categoryid);
}

#
# Mod: Get all main categories and level 1 subcatgories and store them in an array
#
$categories_data1 = func_query("select * from $sql_tbl[categories] where category NOT LIKE '%/%' and avail='Y' group by $sql_tbl[categories].categoryid order by order_by");

foreach ($categories_data1 as $key=>$value) {
$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");
$categories_data2[$key][category] = strrchr($categories_data2[$key][category], "/");
}

#
# Assign Smarty variables
#

$smarty->assign("allcategories",$all_categories);
$smarty->assign("categories",$categories);
$smarty->assign("subcategories",$subcategories);
$smarty->assign("current_category",$current_category);
$smarty->assign("enable_subcategories_count",$enable_subca tegories_count);
$smarty->assign("cat",$cat);
?>

Thanks,
Cameron

machnhed1 07-25-2003 01:28 PM

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);
$smarty->assign("categories_level_2",$categories_data2);


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:

Cameron 07-25-2003 01:37 PM

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

machnhed1 07-25-2003 01:43 PM

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">
<option value="">All</option>
{section name=cat_num loop=$categories_level_1}
<option value="{ $categories_level_1[cat_num].categoryid}" {if $smarty.get.in_category eq $categories_level_1[cat_num].categoryid or $cat eq $categories_level_1[cat_num].categoryid}selected{/if}>
{$categories_level_1[cat_num].category|escape}
</option>

{section name=cat_num1 loop=$categories_level_2}
{if $categories_level_2[cat_num][0][cat_num1].categoryid ne ""}<option value="{ $categories_level_2[cat_num][0][cat_num1].categoryid}" {if $smarty.get.in_category eq $categories_level_2[cat_num][0][cat_num1].categoryid or $cat eq $categories_level_2[cat_num][0][cat_num1].categoryid}selected{/if}>
{$categories_level_2[cat_num][0][cat_num1].category_name|escape}
</option>{/if}
{/section}

{/section}
</select>


with:

Code:

<select name="in_category">
<option value="">All</option>
{section name=cat_num loop=$allcategories}
<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>


It's not as pretty, but it gets the job done.

Cameron 07-25-2003 01:51 PM

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

machnhed1 07-25-2003 02:00 PM

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.

Cameron 07-25-2003 02:09 PM

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.

machnhed1 07-25-2003 02:13 PM

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.

Cameron 07-25-2003 02:21 PM

categoryid
image_x
image_y
category
description
meta_tags
avail
views_stats
order_by
membership
threshold_bestsellers


Is that what you're looking for?

machnhed1 07-25-2003 02:26 PM

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.

Cameron 07-25-2003 02:57 PM

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

funkydunk 07-26-2003 01:59 AM

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 $ *}
{include file="location.tpl" last_location=$lng.lbl_advanced_search}
{capture name=adv_search}
<table border=0>
<form action="search.php" name="productsearchbyprice_form">
<tr>
<td>{$lng.lbl_product_title}</td>
<td>
<input type="text" name="substring" size="30" value="{$smarty.get.substring}">
</td>
</tr>
<tr><td>{$lng.lbl_price}, {$config.General.currency_symbol}</td>
<td><input type="text" name="price_search_1" size="6" value="{$smarty.get.price_search_1|escape}"> - <input type="text" name="price_search_2" size="6" value="{$smarty.get.price_search_2|escape}"></td></tr>
<tr><td>{$lng.lbl_category}</td>
<td>
<select name="in_category">
<option value="">All</option>

{section name=cat_num loop=$categories}
<option value="{ $categories[cat_num].categoryid}">{ $categories[cat_num].category|escape }</option>
{section name=cat_num1 loop=$allcategories}
{if $allcategories[cat_num1].topcat eq $categories[cat_num].category_name}
<option value="{ $allcategories[cat_num1].categoryid}">- { $allcategories[cat_num1].category_name|escape }</option>
{/if}
{/section}
{/section}

</select>
</td>
</tr>
<tr><td></td></tr>
<tr><th>{include file="buttons/search.tpl"}</th></tr>
</form>
</table>
{/capture}
{include file="dialog.tpl" title=$lng.lbl_advanced_search content=$smarty.capture.adv_search extra="width=100%"}


Cameron 07-26-2003 09:03 AM

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.

Cameron 07-26-2003 09:19 AM

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:

#
# Mod: Get all main categories and level 1 subcatgories and store them in an array
#
$categories_data1 = func_query("select * from $sql_tbl[categories] where category NOT LIKE '%/%' and avail='Y' group by $sql_tbl[categories].categoryid order by order_by");

foreach ($categories_data1 as $key=>$value) {
$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");
}

at the end of the file, add these lines:
Quote:

$smarty->assign("categories_level_1",$categories_data1);
$smarty->assign("categories_level_2",$categories_data2);

/store/skin1/customer/main/advanced_search.tpl
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:

<select name="in_category">
<option value="">All</option>
{section name=cat_num loop=$categories_level_1}
<option value="{ $categories_level_1[cat_num].categoryid}" {if $smarty.get.in_category eq $categories_level_1[cat_num].categoryid or $cat eq $categories_level_1[cat_num].categoryid}selected{/if}>
{$categories_level_1[cat_num].category|escape}
</option>

{section name=cat_num1 loop=$allcategories}
{if $categories_level_2[cat_num][0][cat_num1].categoryid ne ""}<option value="{ $categories_level_2[cat_num][0][cat_num1].categoryid}" {if $smarty.get.in_category eq $categories_level_2[cat_num][0][cat_num1].categoryid or $cat eq $categories_level_2[cat_num][0][cat_num1].categoryid}selected{/if}>
{$categories_level_2[cat_num][0][cat_num1].category_name|escape}
</option>{/if}
{/section}

{/section}
</select>


Cameron 07-26-2003 09:38 AM

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

Mad 07-27-2003 09:41 AM

Used information within to make subcatagories to be listed at all times on the left side's catagory section. Great post, thank you!

technicaldata 11-16-2005 03:38 PM

X-Cart 4.0.17?
 
Does anyone have a version of this mod that will work with X-Cart Pro 4.0.17?

technicaldata 11-16-2005 03:41 PM

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.