Ciao raga...
ho una cosa ke non riesco a correggere:
1) Passo le variabili con un normale form
2) Uso questo codice per il carrello
codice:
<?
define("COD", 0);
define("NOME_PRODOTTO", 1);
define("QUANTITA", 2);
define("PREZZO", 3);
define("PESO", 4);
?>
<table width="500" id="TabellaCarrello" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Nome prodotto</td>
<td>Peso</td>
<td>Quantita</td>
<td>Prezzo</td>
<td>Totale</td>
</tr>
<?
$total = 0;
for ($i=0; $i<$itemcount; $i++)
{
?>
<tr>
<td>
<? echo $cart[NOME_PRODOTTO][$i]; ?>
</td>
<td>
<? echo $cart[PESO][$i]." Kg"; ?>
</td>
<td>
<input type="text" name="quantita<? echo ($i); ?>" value="<? echo $cart[QUANTITA][$i]; ?>" size="3">
</td>
<td>
<? echo number_format($cart[PREZZO][$i],2)." €"; ?>
</td>
<td>
<? echo number_format($cart[PREZZO][$i]*$cart[QUANTITA][$i],2)." €"; ?>
</td>
</tr>
<?
$total = $total + ($cart[PREZZO][$i]*$cart[QUANTITA][$i]);
$peso_tot = $_SESSION['$peso_tot'] = $peso_tot + ($cart[PESO][$i]*$cart[QUANTITA][$i]);
}
?>
<tr>
<td>
</td>
<td>
Totale peso:
<? echo $peso_tot." Kg" ?>
</td>
<td>
</td>
<td>
Totale ordine:
</td>
<td>
<?
if ($peso_tot < 30 || $peso_tot == 30)
echo number_format($total + $_SESSION['$speseSpedizione'], 2)." €";
else
echo number_format($total + $_SESSION['$speseSpedizione1'], 2)." €";
?>
</td>
<div align="left">Spese spedizione:
<?
if ($peso_tot < 30 || $peso_tot == 30)
echo $_SESSION['$speseSpedizione']." €";
else
echo $_SESSION['$speseSpedizione1']." €";
?>
</div>
</tr>
</table>
e queste le funzioni aggiungi e ricalcola carrello
codice:
function AddToCart()
{
$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : '';
$itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;
$cart[COD][$itemcount] = $_POST['cod'];
$cart[NOME_PRODOTTO][$itemcount] = $_POST['nome_prodotto'];
$cart[PESO][$itemcount] = $_POST['peso'];
$cart[QUANTITA][$itemcount] = intval($_POST['quantita']);
$cart[PREZZO][$itemcount] = $_POST['prezzo'];
$itemcount = $itemcount + 1;
$_SESSION['cart'] = $cart;
$_SESSION['itemcount'] = $itemcount;
}
function RecalculateCart()
{
$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : '';
$itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;
for ($i=0; $i<$itemcount; $i++)
{
$quantita = $_POST['quantita'.($i)];
if (empty($quantita))
{
$quantita = 0;
}
else
if (($quantita < 0) || (!is_numeric($quantita)))
{
$quantita = 0;
}
$cart[QUANTITA][$i] = intval($quantita);
}
for ($j=0; $j<$itemcount; $j++)
{
$quantita = $cart[QUANTITA][$j];
if ($quantita == 0)
{
$itemcount--;
$curitem = $j;
while(($curitem+1) < count($cart[0]))
{
for ($k=0; $k<4; $k++)
{
$cart[$k][$curitem] = $cart[$k][$curitem+1];
$cart[$k][$curitem+1] = '';
}
$curitem++;
}
}
}
$_SESSION['itemcount'] = $itemcount;
$_SESSION['cart'] = $cart;
}
3) Il problema e che ho inserito anche il peso dei singoli oggetti ma se scelgo per esempio un oggetto che pesa 10 e uno che pesa 20...elimino dal carrello quello che pesa 10 l'altro oggetto non mantiene il suo peso ma prende quello dell'alltro cancellato =(
come posso risolvere? tnx help