View Single Post
  #5  
Old 07-05-2006, 11:37 PM
 
Hunabku Hunabku is offline
 

Advanced Member
  
Join Date: Jun 2006
Posts: 47
 

Default Categories for product (Cleaned up & with nesting)

I have cleaned up and added to jamesc code to include sub category nesting(indenting). I used a spacer.gif for indenting but you can substitute with unordered list, character space, etc.

In product.php around line 143 insert the following:

Code:
# This mod comes from xcart user forum - http://forum.x-cart.com/viewtopic.php?t=29077 # It puts a product's categories into an array so we can access them from the added template: customer/categories_for_selected_product.tpl. # In the SELECT below [categories].categoryid_path contains the path or nesting of categoryid(s) ex. "256/262/270". $cat_result = db_query(" SELECT $sql_tbl[products_categories].categoryid,$sql_tbl[categories].category,$sql_tbl[categories].parentid,$sql_tbl[categories].categoryid_path FROM $sql_tbl[products_categories], $sql_tbl[categories] WHERE $sql_tbl[products_categories].productid = $productid AND $sql_tbl[categories].categoryid = $sql_tbl[products_categories].categoryid AND $sql_tbl[categories].parentid != 0"); $i = 0; while ($category = db_fetch_row($cat_result)) { if ($category) { $product_categories[] = $category; # The following two lines of code create the subcategory nesting(indent) values. # $category_path_chars gets an array of ascii character counts from categoryid_path. $category_path_chars = count_chars($product_categories[$i][3],1); # Replace the categoryid_path element with the number of times "/"(ascii char 47) occurs in categoryid_path. Subtract 1 from this value and multiply by 12 (12px) for the pixel width of spacer.gif to indent each nested subcategory - see customer/categories_for_selected_product.tpl. $product_categories[$i][3] = ($category_path_chars['47']-1)*12; $i++; } } $smarty->assign("product_categories",$product_categories);

Now create a new template in the customer directory and call it "categories_for_selected_product.tpl" - this is just a modified "categories.tpl" file from the same directory. Include the following code:

Code:
{* $Id: categories_for_selected_product.tpl based on categories.tpl,v 1.23 2004/06/24 09:53:29 max Exp $ *} {*** See product.php for the creation of the $product_categories array used below. ***} {capture name=menu} {section name=category loop=$product_categories} <FONT class="CategoriesList"> {if $product_categories[category].3 > 0} {*** Do indenting ***} [img]{$ImagesDir}/spacer.gif[/img] {/if} {$product_categories[category].1}</FONT> {/section} {/capture} { include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_title=$lng.lbl_categories menu_content=$smarty.capture.menu }

Now just include "categories_for_selected_product.tpl" in your customer/main/product.tpl.
__________________
Version 4.1.3
Reply With Quote