%
'Richiamo l' id del prodotto da inserire
id_prodotto = request("id")
'Aggiunta nuovo prodotto nel Carrello
'Controllo che il prodotto sia già presente nel carrello
if len(id_prodotto) <> 0 then
strSQL = "select id_prodotto, id_user from tbl_Carrello where id_prodotto = " & id_prodotto & " and stato=0 and id_user = " & session("id_utente")
set rs = DBConn.execute(strSQL)
'Se il prodotto non esiste, lo aggiungo
'Altrimenti aggiorno la quantita' di 1 unità
if rs.eof then
'Aggiungo il prodotto
strSQL = "insert into tbl_Carrello(id_user, id_prodotto, quantita) values(" & session("id_utente") & ", " & id_prodotto & ", 1)"
DBConn.execute(strSQL)
else
'Aggiorno la quantità
strSQL = "update tbl_Carrello set quantita = quantita + 1 where id_prodotto = " & id_prodotto & " and id_user = " & session("id_utente")
DBConn.execute(strSQL)
end if
rs.close
set rs = nothing
end if
'Fine
'Aggiorno il carrello
if request("azione") = "aggiorna" then
'Controllo quali prodotti aggiornare o eliminare
set rs = Server.CreateObject("ADODB.Recordset")
rs.activeconnection = DBConn
rs.cursortype = adOpenDynamic
rs.locktype = adLockOptimistic
strsql = "select * from tbl_Carrello where stato=0 and id_user = " & session("id_utente")
rs.open strsql
'Elenco dei prodotti nel carrello
'E modifica...
while not rs.eof
pc = request("pc_" & rs("id_prodotto"))
if isnumeric(pc) then
if pc = 0 then
rs.delete
else
rs("quantita") = pc
end if
end if
rs.movenext
wend
'Fine
rs.close
set rs = nothing
'Fine
end if
%>
<%
DEL=Request("DEL")
If Not Nullo(DEL) Then
ID=Request("ID")
SQL="UPDATE tbl_carrello SET Quantita=0 WHERE stato=0 and id_prodotto=" & ID
DBConn.Execute(SQL)
Redirect "acquista_carrello_personale.php"
End If
%>
<%
Svuota=Request("Svuota")
If Not Nullo(Svuota) Then
ID=Request("ID")
SQL="UPDATE tbl_carrello SET Quantita=0 WHERE stato=0 and id_user = " & session("id_utente")
DBConn.Execute(SQL)
Redirect "acquista_carrello_personale.php"
End If
%>
<%
EshopSex=Request("EshopSex")
If Not Nullo(EshopSex) Then
EshopSexNum=GeneraNumeroCasuale(1000000,9999999)
SQL="UPDATE tbl_carrello SET id_ordine="& EshopSexNum &" WHERE stato=0 and id_user = " & session("id_utente")
DBConn.Execute(SQL)
Redirect "acquista_carrello_inoltra_ordine.php"
End If
%>