Jump to content

Recommended Posts

Hi All

I need a bit of help.

I am trying to set a e-commerce page for a charms website. The problem is that each product carries 6 different prices depending on what type of metal it uses.

I have tried my scipt but I can't seem to get it to pick up the different prices here are the two scipts the first one adds the products to the cart and the second one views the cart

<?php
$qty1 = $_POST['qty'];
$metal_out = $_POST['metal'];

// This page adds products to the shopping cart
	if (is_numeric ($_GET['pid'])) { // check for a product id
	$pid = $_GET['pid'];
	// check to see if the cart already contains one of these products
	if (isset ($_session['cart'][$pid])) {
	$qty_out = $_SESSION['cart'][$pid] + $qty1;
	} else {
	$qty = $qty1;
	}
	// add to the cart session variable
	$_SESSION['cart'][$pid] = $qty;
	// Display a message
	print <<<ANOTHER
	<table border="0"cellpadding="3" align="center">
					<tr><td>
	<table summary="" align="center" width="400" border="1">
					<tr>
					<td>
					<table border="0" width="400" cellpadding="3">
					<tr><td align="center">
ANOTHER;
	echo '<p>The product has been added to your shopping cart';
	echo '<p>';

echo '<form action="ch_main.php" target="mainFrame" method="post"><input type="submit" name="more_pur" value="More Purchases"></form>';echo '<form action="view_cart.php" target="_self" method="post"><input type="submit" name="view_cart" value="View Cart"></form>';

}

// This page displays the contents of the cart
	// check to see if the form has been submitted (to update the cart).
	if (isset($_POST['submit'])) {
		foreach ($_POST['qty'] as $key => $value) {
			if (($value == 0) AND (is_numeric($value))) {
				unset ($_SESSION['cart'][$key]);
				} elseif (is_numeric($value) AND ($value > 0)) {
					$_SESSION['cart'][$key] = $value;
				}
			}
		}
		// check if the shopping cart is empty
		$empty = TRUE;
		if (isset($_SESSION['cart'])) {
			foreach($_SESSION['cart'] as $key => $value) {
				if (isset($value)) {
					$empty = FALSE;

				}
			}
		}
	// Display the cart if it is not empty
	if (!$empty) {
		include 'includes/conn_db.php';
		// Retrieve all of the information for the products in the cart
		$query = 'SELECT * FROM products WHERE Prod_id IN (';
		foreach ($_SESSION['cart'] as $key => $value) {
			$query .= $key . ',';
		}
		$query = substr ($query, 0, -1) . ') ORDER BY prod_name ASC';
		$result = mysql_query($query);

		// create a table and a form
		print <<<TOP
					<table summary="" border="1" width="610"><tr><td><table summary="" border="0" width="610">

<tr>
<td nowrap align="center"><font face="Arial" size="2"> <b>YOUR SHOPPING CART</b></font></tr></table>
					<table summary="" width="600" border="0">
					<tr>
					<td>
					<table border="0" width="600" cellpadding="3">
					<tr>
					<td align="left" width="230"><font face="arial" size="2" color="#5e5d5d"><b>Product</b></font></td>
					<td align="center" width="70"><font face="arial" size="2" color="#5e5d5d"><b>Qty</b></font></td>
					<td align="right" width="120"><font face="arial" size="2" color="#5e5d5d"><b>Unit Price</b></font></td>
					<td align="right" width="120"><font face="arial" size="2" color="#5e5d5d"><b>Line Total</b></font></td>
					</tr>
					<form action="view_cart.php" method="post">
TOP;
		// Print each item
		$total = 0; // total cost of the order
		while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

		// Calculate the total and subtotals
		$subtotal = $_SESSION['cart'][$row['prod_id']] * $row['price'];

		$subtotal = number_format($subtotal, 2, '.', '');
		$total += $subtotal;
		$total = number_format($total, 2, '.', '');

		// print the row
		print <<<ROW
					<tr>
					<td align="left"><font face="arial" size="2" color="#5e5d5d">{$row['Prod_name']} ({$row['type']})</font></td>
					<td align="center"><input type="text" size="3" name="qty[{$row['Prod_id']}]" value="{$_SESSION['cart'][$row['Prod_id']]}"></td>
<td align="right"><font face="arial" size="2" color="#5e5d5d">R {$row['price']}</font></td>
<td align="right"><font face="arial" size="2" color="#5e5d5d">R $subtotal</font></td>
</tr>
ROW;

 

Thanks

 

Lional

Link to comment
https://forums.phpfreaks.com/topic/64803-e-commerce-with-multiple-prices/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.