Ciao, avevo semplicemente l'esigenza di integrare un carrello in un sito già esistente.

Qui di seguito uno script che ho trovato:

codice:
<?
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>phpCart</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="phpCart_style.css" rel="stylesheet" type="text/css">
</head>

<body>
				<form name="update" method="post" action="phpCart_manage.php">
				<table width="100%"  border="0" cellspacing="0" cellpadding="5">
				<tr bgcolor="#EEEEEE">
				<td width="10%" class="bottomline"></td>
				<td width="10%" class="bottomline">Qty</td>
				<td width="60%" class="bottomline">Product</td>
				<td width="10%" class="bottomline">Price</td>
				<td width="10%" class="bottomline">Line Total </td>
				</tr>
<?
include "functions_cart.php";
$totalvalue = 0;

session_start();
// If no sessions has been started $_SESSION["cart"] equals null, thus showing the message no items.
if (!isset($_SESSION["cart"])) {
	$_SESSION["cart"] = NULL;
}

if (validate() == TRUE && $_SESSION["cart"] != NULL) {
					
	foreach ($_SESSION["cart"] as $key => $session_data) {
		
		list($ses_id, $ses_quan) = $session_data;
						
			// call database connect function
			db_connect();
			$sel_products = mysql_query("SELECT * FROM $mysql_tablename WHERE id=".$ses_id."");
			$item = mysql_fetch_array($sel_products);
				
			$totalvalue = $totalvalue + ($item["price"]*$ses_quan);
			$subtotal = ($item["price"]*$ses_quan);
					
	?>
				<tr>
				<td class="dividingborder">">[img]img/icon_del.gif[/img]</td>
				<td class="dividingborder"><input name="newquan[]" type="text" id="newquan[]3" value="<? echo $ses_quan; ?>" size="5" maxlength="4">
				<input name="eid[]" type="hidden" id="eid[]" value="<? echo $ses_id; ?>"></td>
				<td class="dividingborder"><? echo $item["product"]; ?></td>
				<td class="dividingborder"><? echo $cur_symbol."".number_format($item["price"], 2, '.', ''); ?></td>
				<td class="dividingborder"><? echo $cur_symbol."".number_format($subtotal, 2, '.', ''); ?></td>
				</tr>
	<?
	} // end foreach loop
	
} elseif ($_SESSION["cart"] == NULL) {

	echo "<td colspan=\"5\"><center>

Your basket is currently empty.</p></center></td>";
			
} else {
	
	echo "<td colspan=\"5\"><center>

Unknown Error.</p></center></td>";

}
	?>
				<tr>
				<td> [img]img/icon_del.gif[/img] - delete</td>
				<td><? if ($_SESSION["cart"] != NULL) { echo "<input name=\"UpdateChg\" type=\"submit\" id=\"UpdateChg\" value=\"Update\">"; } ?></td>
				<td>Continue Shopping</td>
				<td>Cart Total</td>
				<td><? echo $cur_symbol."".number_format($totalvalue, 2, '.', ''); ?></td>
				</tr>
				</table>
				</form>
</body>
</html>
<?
ob_end_flush();
?>

Adesso non riesco a risolvere due problemi:

1) Lo script di mi fa vedere gli articoli in sessione e il loro costo, la possibilità di cambiare quantità e la somma progressiva.

Come posso modificare lo scritp per inserire un menu a tendina con tutti le possibili modalità di spedizione, in modo che, scegliendone una, si modifichi in automatico anche il totale?

Se scelgo da questo menu a tendina "posta celere 1", la pagina dovrebbe ricaricarsi, scriverlo nella lista alla fine, e modificare il prezzo.


Come dovrei modificarlo?


La pagina che gestisce l'aggiunta e la sottrazione dal carrello è questa:

codice:
<?
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>phpCart</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="phpCart_style.css" rel="stylesheet" type="text/css">
<?
// UPDATE BASKET QUANTITY
if (isset($_POST["UpdateChg"])) {

	session_start();
	include "functions_cart.php";
		
		$i = 0;
		$size = count($_POST["eid"]);

		for ($i = 0; $i <= $size-1; $i++) {
			
			// call remove bad characters function
			$badsymbols = array(" ","-","+","*","/",".");
			$_POST["newquan"][$i] = str_replace($badsymbols,"", $_POST["newquan"][$i]);
		
			if (is_numeric($_POST["newquan"][$i])) {
				
				// if any quantity's equal 0 then remove from cart
				if ($_POST["newquan"][$i] == 0) {
					unset($_SESSION["cart"][$_POST["eid"][$i]]);
				}

				// update quantity in cart.
				if (array_key_exists($_POST["eid"][$i], $_SESSION["cart"])) {
					
					add_item_to_cart($_POST["eid"][$i], $_POST["newquan"][$i]);
				
				} 
				
			} // END IF NUMERIC
		
		}
						
		header ("location:".$_SERVER['HTTP_REFERER']);
	
} // END BASKET QUANTITY

// TEXT LINKS
if (isset($_GET["act"])) {

	// ADD ITEM!
	if ($_GET["act"] == "add") {
		
		session_start();
		include "functions_cart.php";
		//unserialize($_SESSION["cart"]);
		if (!isset($_SESSION["cart"])) {
			
			// add first item
			add_item_to_cart($_GET["pid"],1);
		
		} else if (array_key_exists($_GET["pid"], $_SESSION["cart"])) {
			
			// add 1 to quantity if item in cart already
			add_item_to_cart($_GET["pid"],++$_SESSION["cart"][$_GET["pid"]][1]);
			
		} else {
		
			// add any other items after first item
			add_item_to_cart($_GET["pid"],1);
			
		}
		
	}	
	
	
	// DELETE ITEM!
	if ($_GET["act"] == "del") {
		
		include "functions_cart.php";
		del_item($_GET["pid"]);
		
	}
		
} // END ISSET
?>
</body>
</html>
<?
ob_end_flush();
?>


2) Noto un problema con le sessioni. Se inserisco il primo codice all'interno di un'altra pagina e faccio un refresh, la pagina non mostra più il totale degli oggetti acquistati, ma "Unknown Error.", quindi lo script non vede come NULLA la sessione, ma neanche come verificata.

Come mai accade ciò? Come posso evitare questo problema


In caso, qualche amico del forum ha uno script semplice alternativo da passarmi o segnalarmi per integrare questa funzionalità?


GRAZIE