peachsnapple Posted May 15, 2009 Share Posted May 15, 2009 Hi, I have a coding problem. The way that I had it in the first coding example if a customer chooses two items of the same product but in different colors my code doesn't take that into consideration. It overides the same product information and just change the color instead of adding another line of the product with the different color. Instead of one line it should be two line with the same products but different color, but it does not show that way because the cart is being override by the new color added instead of making an additonal line of product with the new color. My question and concern is, is there a way to write this page so that everytime a customer choose a product with an additional different color, a seperate line of the product with the new color will display? Example: Punk Hair - Red Punk Hair - Blue and not the blue replacing the red? I really appreciate your time and help, thank you in advance. <?php $prodid = $_POST['prodid']; $quantity = $_POST['quantity']; if (isset($_POST['item_color'])) { $item_color = $_POST['item_color']; if (!isset($_SESSION['item_color'])) { $_SESSION['item_color'] = array(); } $_SESSION['item_color'][$prodid] = $item_color; $query = "SELECT quantity, description FROM products WHERE prodid = $prodid"; $result = mysql_query($query); $row = mysql_fetch_row($result); $stock = $row[0]; $description = $row[1]; if (isset($_SESSION['cart'][$prodid])) { $total = $_SESSION['cart'][$prodid] + $quantity; if ($total > $stock) { echo "<h2>Sorry, there are only $stock $description left in stock</h2>\n"; echo "<h2>Please select another quantity</h2>\n"; } else { $_SESSION['cart'][$prodid] += $quantity; echo "<h2>Product added to cart.</h2>\n"; } } else { if ($quantity > $stock) { echo "<h2>Sorry, there are only $stock $description left in stock</h2>\n"; echo "<h2>Please select another quantity</h2>\n"; } else { $_SESSION['cart'][$prodid] = $quantity; echo "<h2>Product added to cart.</h2>\n"; } } echo "<a href=\"index.php\">Continue shopping</a><br>\n"; echo "<a href=\"index.php?content=checkout\">Check out</a>\n"; ?><?php $prodid = $_POST['prodid']; $quantity = $_POST['quantity']; if (isset($_POST['item_color'])) { $item_color = $_POST['item_color']; if (!isset($_SESSION['item_color'])) { $_SESSION['item_color'] = array(); } $_SESSION['item_color'][$prodid] = $item_color; $query = "SELECT quantity, description FROM products WHERE prodid = $prodid"; $result = mysql_query($query); $row = mysql_fetch_row($result); $stock = $row[0]; $description = $row[1]; if (isset($_SESSION['cart'][$prodid])) { $total = $_SESSION['cart'][$prodid] + $quantity; if ($total > $stock) { echo "<h2>Sorry, there are only $stock $description left in stock</h2>\n"; echo "<h2>Please select another quantity</h2>\n"; } else { $_SESSION['cart'][$prodid] += $quantity; echo "<h2>Product added to cart.</h2>\n"; } } else { if ($quantity > $stock) { echo "<h2>Sorry, there are only $stock $description left in stock</h2>\n"; echo "<h2>Please select another quantity</h2>\n"; } else { $_SESSION['cart'][$prodid] = $quantity; echo "<h2>Product added to cart.</h2>\n"; } } echo "<a href=\"index.php\">Continue shopping</a><br>\n"; echo "<a href=\"index.php?content=checkout\">Check out</a>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/158321-how-to-stop-the-overide-of-a-product-in-the-cart/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.