X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Categories Menu - Showing Subcategories (https://forum.x-cart.com/showthread.php?t=3242)

maki 08-13-2003 05:04 AM

only a sublevel
 
hi !!!

indeed, it seems to be that single it shows to the first level of sub categories

B00MER 01-01-2004 10:54 PM

Since I've seen many requests for a "how the color changes happen on aheadgames?" Here's my take on how to achieve this easily.

First thing that needs to be established is the root category, keeping the same category ID's is important.

Second, add a bit of custom code to customer/home.tpl replacing the style sheet reference link with something similar to this:
Code:

<link rel="stylesheet" href="{$SkinDir}/{if $cat eq "250"}skin1_blue.css{elseif $cat eq "251}skin1_red.css{/if}">
Note that your category ID's will differ as to what color you want to switch into.

Third, you will need to create these new style sheets for each color change that you want to switch into on particular cats.

Also, if you notice on aheadgames, after clicking a root cat, and viewing a subcat of the selected root cat, the simple script above will need to know the root category of the sub category as to keep the proper skin style sheet color.

Code:

http://www.aheadgames.com/cart/customer/home.php?cat=350&topcat=249

Note that cat=350 is a subcat of 249, which is being specified in the links.

So you will need to modify your categories.tpl to keep a tab on the root category of the current select subcat.

OR, Here's a more simpler approach that won't require you to specify the rootcat of any product link that needs to stay the same color in your anchor or ahref links:

Edit customer/cateogries.php and modify the $categories_data SQL query to:
Code:

$categories_data = func_query("select $sql_tbl[categories].*, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', -1) as category_name, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', 1) as root_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"));

Note we are now keeping tabs of root_category_name, category_name

Now you would need to change the {if} statements we have setup in customer/home.tpl to reflect these new changes.

Code:

<link rel="stylesheet" href="{$SkinDir}/{if $root_category_name eq "Root category one"}skin1_blue.css{elseif $root_category_name eq eq "Root category two"}skin1_red.css{/if}">
NOTE that you will now specify the root category name vs the ID, so make sure your if statements are setup case senstive.

Anyhow, if this still isn't very clear, please feel free to PM me for a service request to have it setup on your x-cart.

Kudos! :wink:

jordan0 01-04-2004 01:51 PM

$rot_category_name...
 
Boomer,
I have modified the SQL query in /include/categories.php as you instructed above, but my code (from products.tpl) below still does not work:

Code:

{if $root_category_name eq "Chain"}

{include file="customer/main/products_struc.tpl" products=$products}

{else}


The "Chain" cat has only one subcat, and products.tpl doesn't include products_struc.tpl when listing its products.

I was thinking about a different solution to this problem that might work better for me. Would it be possible to create an extra column in the xcart_categories table for "listing style"? It could contain a path to a custom products.tpl that the regular products.tpl would load if this column contained any data.
How would I write the code for this? Do I just have to add the column and then use $categories[cat_num].listingstyle ? Or is there somewhere I have to tell xcart to put the listingstyle info into $categories?

The way I'm doing it right now, which I have to change, is with a massive set of {if} statements that check $cat for each category and subcategory...

This seems like something fairly common... How has everyone else handled the problem of making custom products.tpl pages for specified categories?

Example of what I have now:
Structural Materials: http://www.kitkraft.biz/customer/home.php?cat=20
Acrylic Paint: http://www.kitkraft.biz/customer/home.php?cat=12

Thanks
- Jordan

Xixao 01-04-2004 03:43 PM

The file you should be modifying is the Skin1/customer/category.tpl

jordan0 01-04-2004 05:08 PM

Xixao,

The products.tpl that I am referring to is skin1/customer/products.tpl Б─⌠ I have been working with that file and with /include/categories.php .

======== ** Edit ** =========

Sorry about that, I misread your posting. For some reason I had thought you wrote "products.tpl" and not "categories.tpl".

I was under the impression that categories.tpl is only responsible for the "categories" menu at the left of the page. I am trying to customize the products.tpl pages to load special templates for certain categories. I'm going to have a lot of categories, so using my current method of {if $cat eq "xx" or $cat eq "xx" etc...} is going to get rather cumbersome.

I have been trying to figure out how to add and implement an extra column to the "categories" table in the SQL db, but have been unsuccessful. I am able to add the column to the database and put info into it, but I don't know how to get xcart to read that info.

Any other threads on adding and using additional columns to the database?

Taekwondo 01-07-2004 09:33 AM

Anyone have fix for sub catagory mod ?
 
Please post. Excellent mod, just need the fix to maintain sub-cat list.

Thx

finestshops 01-09-2004 01:23 PM

Hi,

Below is a small mod for showing all categories and subcategories on all pages. It's combined from several modes posted on this forum (most by funkydunk =D> ).

- Cat A
--- Sub Cat 1
--- Sub Cat 2
--- Sub Cat 3
- Cat B
- Cat C
- Cat D

Example is here: http://earthbab.finestshops.com (v. 3.5.2 but should work in any version - just small changes in the categories.php are required for 3.4.*)

include/categories.php

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 = "";
}

// funkydunk modification
// amended query to get the main cat and subcat for each record
$categories_data = func_query("select $sql_tbl[categories].*, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', -1) as category_name, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', 1) as maincat, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', 2) as subcat 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
  if(strstr($category_data["category"],"/")) {
      if ($category_data["category"] == $category_data["subcat"]){
      // echo "got one";
      // after taking off the initial category name this checks to see if this is only a sub category with no categories below it.
      // if i didn't do this the subcategory would be duplicated in the list
      $categories_data[$k]["subcatonly"]="true";
      }
  }
  // end of funkydunk amended code


$all_categories = $categories_data;
// func_print_r ($all_categories);
}

#
# 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);
      }
  }
}

if ($current_area == "C" and !empty($current_category) and $config["Images"]["icons_location"] == "FS") {
        $current_category["image_path"] = array_pop(func_query_first("SELECT image_path FROM $sql_tbl[icons] WHERE categoryid='$cat'"));
        if (eregi("^(http|ftp)://", $current_category["image_path"])) {
        # image_path is an URL
                $current_category["icon_url"] = $current_category["image_path"];
        }
        elseif (eregi($xcart_dir, $current_category["image_path"])) {

        # image_path is an locally placed image
                $current_category["icon_url"] = $http_location.ereg_replace($xcart_dir, "", $current_category["image_path"]);
        }
}


#
# 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);
?>


skin1/customer/categories.tpl

Code:

{* $Id: categories.tpl, modified *}

{capture name=menu}

{section name=cat_num loop=$categories}
{assign var="tmp" value="0"}

{section name=cat loop=$allcategories}
{if $allcategories[cat].maincat eq $categories[cat_num].category_name}
{if $allcategories[cat].subcatonly}{assign var="tmp" value="1"}{/if}
{/if}
{/section}

<font class=CategoriesList>
<a href="home.php?cat={ $categories[cat_num].categoryid }" class="VertMenuItems">
{ $categories[cat_num].category_name|escape }</a></font>
 

  {if $tmp eq 1}

{assign var="temp" value="0"}
{section name=cat loop=$allcategories}
{if $allcategories[cat].maincat eq $categories[cat_num].category_name}
{if $allcategories[cat].subcatonly}


{if $temp gt 0}
- {$allcategories[cat].category_name}
{else}
- {$allcategories[cat].category_name}
{/if}

{math equation="temp+1" temp=$temp assign=temp}

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

  {/if}

<hr>
{/section}


{/capture}
{ include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title=$lng.lbl_categories menu_content=$smarty.capture.menu }


:wink:

funkydunk 01-09-2004 10:59 PM

nice work :)

B00MER 01-26-2004 10:17 AM

skin1/customer/categories.tpl

Code:

{section name=cat_num loop=$categories}[*]б╥ {if $cat eq $categories[cat_num].categoryid}{/if}{ $categories[cat_num].category_name|escape }{if $cat eq $categories[cat_num].categoryid}{/if}
{/section}


The code above should make the current category bold.

zman9696 06-19-2005 02:20 PM

boomer

do you have a link to a site that has the above sub cat fix in it? so i can see exactly what it does

thanks


All times are GMT -8. The time now is 06:45 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.