Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Product is in these categories

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 05-22-2006, 09:50 AM
 
jamesc jamesc is offline
 

Member
  
Join Date: Feb 2003
Location: Nontron, France
Posts: 12
 

Default Product is in these categories

This was just a quick hack to get a result I needed for a product display page. It's messy and I'm sure someone will tidy it up and make it nice, but someone may be trying to do the same thing.

I have a selection of DVDs organised by studio using the manufacturer feature of X-Cart 4.0.15. Then my categories include things such as "comedy", "action", "thriller", etc. On the product display page I want a clickable graphic representation of the categories each DVD is in (comedy thriller, for example). So I put this quick botch in to product.php:

Code:
$cat_result = db_query(" SELECT xcart_products_categories.categoryid,xcart_categories.category FROM xcart_products_categories, xcart_categories WHERE xcart_products_categories.productid = $productid AND xcart_categories.categoryid = xcart_products_categories.categoryid"); while ($category = db_fetch_row($cat_result)) { if ($category) { $product_categories[] = $category; } } $smarty->assign("product_categories",$product_categories);

In product.tpl I can now loop through $product_categories and use {$product_categories[loop].0} for each category id and {$product_categories[loop].1} for each category name. Or, in the case I'll be using it, .0 to provide an icon and href and .1 for the alt text.

Hope that helps someone. Sorry it's so messy; I should probably use the correct variables for table/column names but .... YMMV.



James.
__________________
www.affection.net
Reply With Quote
  #2  
Old 05-22-2006, 10:00 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

Moving to Custom Mods, thanks for contributing!
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #3  
Old 05-29-2006, 07:48 AM
 
dgreen dgreen is offline
 

Advanced Member
  
Join Date: May 2005
Posts: 85
 

Default sample code, please

Could you post exactly how to use this? I think this is what I have been trying to do but I couldn't figure out how to implement it.
Thanks
__________________
X-Cart version 4.1.10
upgraded from 4.0.13 myself slowly and with help from xcart forums. Thanks all!

http://www.discountseforim.com
Hebrew Seforim and Jewish Books
Reply With Quote
  #4  
Old 05-29-2006, 11:29 AM
 
jamesc jamesc is offline
 

Member
  
Join Date: Feb 2003
Location: Nontron, France
Posts: 12
 

Default Re: sample code, please

Quote:
Originally Posted by dgreen
Could you post exactly how to use this? I think this is what I have been trying to do but I couldn't figure out how to implement it.

This is a very quick and dirty solution which doesn't use the "xcart" way of creating database queries by using variable names, but it works. I inserted the following code at line 143 of "product.php":

Code:
$cat_result = db_query(" SELECT xcart_products_categories.categoryid,xcart_categories.category,xcart_categories.parentid FROM xcart_products_categories, xcart_categories WHERE xcart_products_categories.productid = $productid AND xcart_categories.categoryid = xcart_products_categories.categoryid AND xcart_categories.parentid != 0"); while ($category = db_fetch_row($cat_result)) { if ($category) { $product_categories[] = $category; } } $smarty->assign("product_categories",$product_categories);

This selects all the categories that this product is in, unless they are parent categories, and assigns the array (where each row =array(category id, category name)) to Smarty as $product_categories.

In skin1/customer/main/product.tpl I added an include to call my new ugly "categories.tpl" which in its most basic (and quite ugly) form looks like this:

Code:
{section name=category loop=$product_categories} [img]{$ImagesDir}/categories/{$product_categories[category].0}.gif[/img] {/section}

James.
xx
__________________
www.affection.net
Reply With Quote
  #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
  #6  
Old 07-06-2006, 04:35 AM
 
Jerrad Jerrad is offline
 

X-Adept
  
Join Date: Nov 2004
Location: The Netherlands
Posts: 484
 

Default

Thanks for this usefull mod!
Is it possible to see it somewehere in 'action'?
__________________
X-Cart 4.0.12
Heavy modified with paid, free and forum mods.
PHP 5.2.5 | MYSQL 5.0.51a
Reply With Quote
  #7  
Old 07-06-2006, 11:18 AM
 
Hunabku Hunabku is offline
 

Advanced Member
  
Join Date: Jun 2006
Posts: 47
 

Default

Quote:
Originally Posted by Jerrad
Thanks for this usefull mod!
Is it possible to see it somewehere in 'action'?

Well thanks Jerrad but perhaps not so useful - just yet. There is a category sorting step(s) that needs to be added.

In my test I put a sub-sub category into the very last sub category and it worked fine - it showed up where it should - at the end. Recently however when I entered a sub-sub category to a sub category in the middle of my list it also showed up at the end - since the defaut sort order for categories is the time they were added.

One of the things I like about this code so far is that it only searches the catagory table once and then works with the array. I have a feeling that inorder to have nested subs with proper ordering it will require multiple (looped) searches of categories table - unless there is a way to cleverly reorder the array - that might be some involved programming though.

Back to the drawing board.... Can anyone help?

PS: I'll give you the URL to my store as soon as this is cleared up.
__________________
Version 4.1.3
Reply With Quote
  #8  
Old 07-06-2006, 11:23 AM
 
Jerrad Jerrad is offline
 

X-Adept
  
Join Date: Nov 2004
Location: The Netherlands
Posts: 484
 

Default

I'm looking forward to your url, when you're finished at the drawingboard...
Thanks!
__________________
X-Cart 4.0.12
Heavy modified with paid, free and forum mods.
PHP 5.2.5 | MYSQL 5.0.51a
Reply With Quote
  #9  
Old 07-09-2006, 02:52 PM
 
wendy.email wendy.email is offline
 

Advanced Member
  
Join Date: Jun 2005
Location: Canada
Posts: 90
 

Default

I think this is what I have been looking for... is that something like product advisor? I want to make something like the following link.

http://www.vitabase.com/tools/product-advisor.asp
__________________
Version 4.1.11
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

   

 
X-Cart forums © 2001-2020