diff --git a/index.php b/index.php index 4217bee..5725a04 100644 --- a/index.php +++ b/index.php @@ -9,6 +9,7 @@ $products = Product::all(array("order" => "name ASC")); $sizes = Size::all(array("order" => "id ASC")); $colors = Color::all(array("order" => "name ASC")); +$first_color_id = $colors[0]->id(); // make sure the images line up with the select box include "app/includes/header.php"; @@ -22,7 +23,7 @@ g("name") ?> - category_names()) ?> - " width="300" height="300" class="product_photo"> + " width="300" height="300" class="product_photo">
diff --git a/js/master.js b/js/master.js index e69de29..28393a1 100644 --- a/js/master.js +++ b/js/master.js @@ -0,0 +1,16 @@ +$(function() { + + if ($("ul.products li").length > 0) { + $("ul.products li select[name=color_id]").change(function() { + var product_id = $(this).parent().find("input[name=product_id]").val(); + var image_tag = $(this).parents("li").find("img.product_photo"); + + $.get( + "/photos/image_tag.php", + { product_id:product_id, color_id:this.value }, + function(data) { $(image_tag).replaceWith(data); } + ); + }); + } + +}); \ No newline at end of file diff --git a/photos/image_tag.php b/photos/image_tag.php new file mode 100644 index 0000000..dc43e15 --- /dev/null +++ b/photos/image_tag.php @@ -0,0 +1,16 @@ + array( + "product_id = ? AND color_id = ?", + $_REQUEST["product_id"], + $_REQUEST["color_id"] + ) +)); + +?> +" width="300" height="300" class="product_photo"> \ No newline at end of file