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"); 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. |
Moving to Custom Mods, thanks for contributing!
|
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 |
Re: sample code, please
Quote:
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"); 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} James. xx |
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 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 $ *} Now just include "categories_for_selected_product.tpl" in your customer/main/product.tpl. |
Thanks for this usefull mod!
Is it possible to see it somewehere in 'action'? :D |
Quote:
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. |
I'm looking forward to your url, when you're finished at the drawingboard... :lol:
Thanks! |
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 |
All times are GMT -8. The time now is 01:42 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.