View Single Post
  #1  
Old 03-31-2005, 09:48 PM
 
Gibberish Gibberish is offline
 

Senior Member
  
Join Date: Sep 2003
Posts: 182
 

Default change product on drop down select

I created this for a site I am doing and I thought I would post it for anyone looking to do the same since I could not find it posted here.

What I have is t-shirts that are the exact are same type just either a differnet size or a different color. So I created a dynamically populated drop down system on the product detail that shows the colors and sizes available for the current product and on select of a new color or size the page updates to the new product.

It's pretty simple. This is all assuming you have a field named 'size' that has the value of (small, medium,large,etc) and a field color with all or any colors (Black, White, Blue, Read, etc). These are both varchar fields in my products table.

This was done on version 4.0.9

Add this to your product.php page anywhere after line 50 (on unmodded product.php)
Code:
$vCategory = $product_info["categoryid"]; $vProduct = $product_info["product"]; $vColor = $product_info["color"]; $vSize = $product_info["size"]; # # Get all sizes # $all_sizes = func_query("SELECT DISTINCT $sql_tbl[products].productid, size FROM $sql_tbl[products] INNER JOIN $sql_tbl[products_categories] USING (productid) WHERE product = '$vProduct' AND categoryid = '$vCategory' AND color = '$vColor'"); $smarty->assign("all_sizes", $all_sizes); # # Get all colors # $all_colors = func_query("SELECT DISTINCT $sql_tbl[products].productid, color FROM $sql_tbl[products] INNER JOIN $sql_tbl[products_categories] USING (productid) WHERE product = '$vProduct' AND categoryid = '$vCategory' AND size = '$vSize'"); $smarty->assign("all_colors", $all_colors);

Place these in customer/main/product.tpl - anywhere you want them to show on the page.

Size Drop down:
Code:
<SELECT name="product_sizes" class="InputWidth" onChange="self.location=this.options[this.selectedIndex].value"> {section name=size_num loop=$all_sizes} <OPTION value="product.php?productid={$all_sizes[size_num].productid}&cat={$cat}"{if $product.size eq $all_sizes[size_num].size} selected{/if}>{$all_sizes[size_num].size}</OPTION> {/section} </SELECT>

Color drop down:
Code:
<SELECT name="product_colors" class="InputWidth" onChange="self.location=this.options[this.selectedIndex].value"> {section name=color_num loop=$all_colors} <OPTION value="product.php?productid={$all_colors[color_num].productid}&cat={$cat}"{if $product.color eq $all_colors[color_num].color} selected{/if}>{$all_colors[color_num].color}</OPTION> {/section} </SELECT>

I hope this helps someone.
__________________
Gibberish
[Unix] X-Cart 4.0.12
Reply With Quote