I finally had a free moment to make the minor changes for 3.3.1. Please remember that this will only show the category and one level of sub-category. A completely different approach would need to be taken to cascade to more levels.
Here are the 3.3.1 changes required:
I preserved the "root categories" function from the General Settings, so you will need to turn it to "N" for the code below to work.
/xcart/include/categories.php
Code:
<?
#
# $Id: categories.php,v 1.43 2002/11/14 07:58:18 zorg Exp $
#
##BEGIN
# Register "lastsub" array for use throughout site
#
session_register("lastsub");
#
# If new category was selected, dump the old subcategories
if($topcat == ""){
$lastsub="";
}
##END
#
# 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;
##BEGIN
# Add values to lastsub array if at first subcategory level
if($topcat == ""){
$lastsub[] = $all_category;
}
##END
}
}
#
# 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);
}
#
# Assign Smarty variables
#
##BEGIN
$smarty->assign("lastsub",$lastsub);
$smarty->assign("topcat",$topcat);
##END
$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_subcategories_count);
$smarty->assign("cat",$cat);
?>
/xcart/skin1/customer/categories.tpl
Code:
{* $Id: categories.tpl,v 1.16 2002/10/21 07:06:43 zorg Exp $ *}
<TABLE border=0 cellPadding=5 cellSpacing=0 width=100%>
<TR>
<TD class=VertMenuTitle height=26 width=26 valign=center>[img]{$ImagesDir}/dingbats_categorie.gif[/img]</TD>
<TD class=VertMenuTitle height=26 valign=center width="80%"><FONT class=VertMenuTitle>{$lng.lbl_categories}</FONT></TD>
</TR>
<tr><td colspan=2 nowrap>
{if $config.General.root_categories eq "Y"}
{section name=cat_num loop=$categories}
<font class=CategoriesList>
{ $categories[cat_num].category|escape }</font>
{/section}
{else}
{* BEGIN *}
{section name=cat_num1 loop=$categories}
{ $categories[cat_num1].category|escape }
{if $categories[cat_num1].categoryid eq $cat}
{section name=cat_num2 loop=$subcategories}
<a class=CategoriesList href="home.php?cat={ $subcategories[cat_num2].categoryid }&topcat={$cat}">
{ $subcategories[cat_num2].category|escape }</a>
{/section}
{else}
{if $categories[cat_num1].categoryid == $topcat}
{section name=cat_num3 loop=$lastsub}
<a class=CategoriesList href="home.php?cat={ $lastsub[cat_num3].categoryid }&topcat={$topcat}">
{ $lastsub[cat_num3].category|escape }</a>
{/section}
{/if}
{/if}
{* END *}
{* OLD CODE
{section name=cat_num loop=$subcategories}
<font class=CategoriesList>
{ $subcategories[cat_num].category|escape }</font>
*}
{/section}
{/if}
</td></tr>
</TABLE>
/xcart/skin1/customer/main/subcategories.tpl
Code:
{* $Id: subcategories.tpl,v 1.29 2002/11/26 14:55:13 alfiya Exp $ *}
{ include file="location.tpl" }
{if $active_modules.Bestsellers ne "" and $config.Modules.bestsellers_menu ne "Y"}
{include file="modules/Bestsellers/bestsellers.tpl"}
{/if}
{ include file="customer/main/navigation.tpl" }
{if ($navigation_page eq "")||($navigation_page eq "1")}{$current_category.description|regex_replace:"/[\n]/":"
"}
{/if}
{capture name=dialog}
{assign var="tmp" value="0"}
{section name=cat_num loop=$subcategories}
{if $subcategories[cat_num].category}{assign var="tmp" value="1"}{/if}
{/section}
{section name=cat_num loop=$subcategories}
{ if %cat_num.first% }
{if $tmp} [img]../icon.php?categoryid={$cat}[/img] {/if}
<table border=0 cellspacing=5>
{/if}
{*if $subcategories[cat_num].product_count or $subcategories[cat_num].subcategory_count*}
<tr><td align=left nowrap width=95%>
{* BEGIN CHANGED LINE - ADDED topcat condition *}
<a href="home.php?cat={ $subcategories[cat_num].categoryid }&topcat={if $topcat == ""}{$cat}{else}{$topcat}{/if}">
<font class="ItemsList">{ $subcategories[cat_num].category|escape }</font></a>
</td>
<td align=right nowrap><font class=Text>
{if $subcategories[cat_num].product_count}
{ $subcategories[cat_num].product_count } {$lng.lbl_products}
{elseif $subcategories[cat_num].subcategory_count}
{ $subcategories[cat_num].subcategory_count } {$lng.lbl_categories|lower}
{/if}
</font></td>
</tr>
{*/if*}
{ if %cat_num.last% }
</table>
{/if}
{/section}
{if $tmp and $products ne "" }
<br clear=_all><hr size=1 noshade>
{/if}
{include file="customer/main/products.tpl" products=$products}
{if $products eq "" and $tmp eq "0"}
{$lng.txt_no_products_in_cat}
{/if}
{/capture}
{include file="dialog.tpl" title=$current_category.category|regex_replace:"/.*\//":"" content=$smarty.capture.dialog extra="width=100%"}
{if $products eq ""}
{if $f_products ne ""}
{include file="customer/main/featured.tpl"}
{/if}
{/if}
{ include file="customer/main/navigation.tpl" }
/xcart/skin1/customer/main/products.tpl
Code:
{* $Id: products.tpl,v 1.21 2002/11/19 12:57:48 alfiya Exp $ *}
{section name=product loop=$products}
<table border=0 width=100%>
<tr><td width=90 align=center valign=top>
{* BEGIN *}
<a href=product.php?productid={$products[product].productid}&cat={$cat}&page={$navigation_page}&topcat={if $topcat == ""}{$cat}{else}{$topcat}{/if}>{include file="product_thumbnail.tpl" productid=$products[product].productid image_x=70 product=$products[product].product}
{ $lng.lbl_see_details }</a>
</td>
<td valign=top>
<font class=TableCenterProductTitleBlue>{$products[product].product|escape}</font>
{* END *}
{* OLD CODE
<a href=product.php?productid={$products[product].productid}&cat={$cat}&page={$navigation_page}>{include file="product_thumbnail.tpl" productid=$products[product].productid image_x=70 product=$products[product].product}
{$lng.lbl_see_details}</a>
</td>
<td valign=top>
{$products[product].product|escape}</font>
*}
<font size=1>
{$products[product].descr|truncate:300:"...":true}
</font>
<hr size=1 noshade width=230 align=left>
{if $active_modules.Subscriptions ne "" and $products[product].catalogprice}
{include file="modules/Subscriptions/subscription_info_inlist.tpl"}
{else}
{if $products[product].price ne 0}
{if $products[product].discount ne 0}
<font class=MarketPrice>{$lng.lbl_market_price}: <s>
{math equation="price/(1-(discount/100))" price=$products[product].price discount=$products[product].discount format="%d.00" assign=unformatted}{include file="currency.tpl" value=$unformatted}
</s></font>
{/if}
<font class=ProductPrice>{$lng.lbl_our_price}: {include file="currency.tpl" value=$products[product].price}</font><font class=MarketPrice>{include file="customer/main/alter_currency_value.tpl" alter_currency_value=$products[product].price}</font>{if $products[product].discount ne 0}, save {$products[product].discount}%{/if}{if $config.General.use_vat eq "Y"}, including VAT {$products[product].vat}%{/if}
{else}
<font class=ProductPrice>{$lng.lbl_enter_your_price}</font>
{/if}
{/if}
</td></tr>
</table>
{/section}
/xcart/skin1/location.tpl
Code:
{* $Id: location.tpl,v 1.7 2002/10/17 13:54:56 zorg Exp $ *}
{strip}
<a href="home.php">
<font class=NavigationPath>{$config.Company.company_name}</font>
</a>
{if $last_location ne ""}
::
{if $last_url ne ""}
<a href="{$last_url}">
{/if}
<font class=NavigationPath>{$last_location}</font>
{if $last_url ne ""}
</a>
{/if}
{/if}
::
{section name=position loop=$location}
{if $location[position].1 ne "" }
{* BEGIN *}
<a href="{$location[position].1}&topcat={if $topcat == ""}{$cat}{else}{$topcat}{/if}">
{* END *}
{* OLD CODE
<a href="{$location[position].1}">
*}
{/if}
<font class=NavigationPath>{$location[position].0|escape}</font>
{if $location[position].1 ne "" }</a>{/if}
{if %position.last% ne "true"}::
{/if}
{/section}
{/strip}
/xcart/customer/main/navigation.tpl
Code:
{* $Id: navigation.tpl,v 1.6 2002/10/22 10:27:05 olga Exp $ *}
{if $total_pages gt 2}
<table cellpadding=0 border=0>
<tr height=14>
{section name=page loop=$total_pages start=1}
{if %page.index% eq 1}
<td>{$lng.lbl_result_pages}: </td>
{if $navigation_page gt 1}
{* ADDED &topcat={$topcat} *}
<td valign=middle>
[img]{$ImagesDir}/larrow.gif[/img]</td>
{/if}
{/if}
{if %page.index% eq $navigation_page}
<td align=center>
{%page.index%}
</td>
{else}
<td width=17 background="{$ImagesDir}/page.gif" align=center>
{* ADDED &topcat={$topcat} *}
{%page.index%}
</td>
{/if}
{if %page.last%}
{capture name=total_pages_minus}
{math equation="pages-1" pages=$total_pages}
{/capture}
{if $navigation_page lt $smarty.capture.total_pages_minus}
<td valign=middle>
[img]{$ImagesDir}/rarrow.gif[/img]</td>
{/if}
{/if}
{/section}
</tr></table>
{/if}
I think that is it. If you just pull the changed lines you can use the same code changes for 3.2.1 and 3.2.2. Just be sure and only use the changed lines and get them inserted into the comparable positions.
Enjoy.
-Derrick