|    
			
				27/05/2003, 10:58
			
			
			  | 
  |   |  |  |  Fecha de Ingreso: mayo-2003 
						Mensajes: 22
					 Antigüedad: 22 años, 5 meses Puntos: 0 |  | 
  |  ayuda:borrar elementos carrito  
  saludos a todos
 tengo un carrito de la compra, y cada vez que lo abro me aparecen los elementos de la compra anterior y me gustaria que esto no pasara.
 
 Espero que podais ayudarme aqui os dejo el codigo
 GArcias
 
 
 
 <%@LANGUAGE="VBSCRIPT"%>
 <%Option Explicit%>
 <%Response.Buffer=True%>
 <%
 Sub MostrarCatalogo
 'Muestra el catalogo con enlaces para ir comprando
 
 Dim oRs, SQL
 Dim referencia
 
 'conexion sin DSN a la base de datos
 
 set oRs=Server.CreateObject("ADODB.Recordset")
 
 SQL="SELECT * FROM Productos;"
 
 oRs.open SQL, oConn
 
 
 
 'Dibujo la tabla
 %>
 <TABLE BORDER="1" CELLSPACING="1" CELLPADDING="1">
 <TR>
 <TD><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Descripcion</TD></font>
 <TD><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Material</TD></font>
 <TD><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Referencia</TD></font>
 <TD><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Precio</TD> </Font>
 <TD></TD>
 
 
 <%
 do until oRs.EOF
 %>
 
 <TR>
 <TD><%=oRs.Fields("Descripcion")%></TD>
 <TD><%=oRs.Fields("Material")%></TD>
 <TD><%=oRs.Fields("Referencia")%></TD>
 <TD><%=oRs.Fields("Precio")%></TD>
 <TD><A HREF="Tienda.asp?ac=meter&prod=<%=oRs.Fields("Refe  rencia")%>"><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Comprar</font></A></TD>
 </TR>
 <%
 
 oRs.MoveNext
 loop
 'Termino la tabla
 %>
 </TABLE>
 <%
 oRs.Close
 set oRs=nothing
 
 ' Pinto opciones
 %>
 <center><A HREF=Tienda.asp?ac=ver><FONT SIZE="5" COLOR="NAVY" FACE="HOBO">Ver Carrito</font></A></center>
 
 <%
 End Sub
 
 '-----------------------------------------------------------
 
 Sub MostrarCarrito
 ' Muestra el contenido del carrito de la compra
 
 Dim oRs, SQL
 
 Dim clave
 
 Dim gastos	' Gastos de envio
 Dim total, subtotal
 
 gastos=2500	' Para todo el mundo
 total=0
 subtotal=0
 
 ' Conexión sin DSN a la base de datos
 
 set oRs=Server.CreateObject("ADODB.Recordset")
 
 
 'Pinto la tabla
 
 
 %>
 <TABLE BORDER="1" CELLPADDING="1" CELLSPACING="1">
 <TR>
 <TD><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Artículo</TD></font>
 <TD><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Cantidad</TD></font>
 <TD><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Precio/unidad</TD></font>
 <TD><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Quitar del carrito</TD></font>
 <TD><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Total</TD></Font>
 </TR>
 <%
 For Each clave in carrito
 subtotal=0		' Total de cada artículo en el carrito
 'Pinto la línea de este producto
 SQL="SELECT * FROM Productos WHERE Referencia="&clave&";"
 set oRs=oConn.Execute(SQL)
 
 %>
 <TR>
 
 <TD><%=oRs.Fields("Descripcion")%></TD>
 <TD><%=carrito(clave)%></TD>
 <TD><%=oRs.Fields("Precio")%></TD>
 <TD><A HREF="Tienda.asp?ac=sacar&prod=<%=clave%>&cant=1">  Quitar Uno</A>
 <A HREF="Tienda.asp?ac=sacar&prod=<%=clave%>&cant=<%=  carrito(clave)%>">Quitar Todos</A>
 </TD>
 <%
 ' Multiplico el precio por la cantidad. FormatNumber me asegura que es un nº válido
 ' y convierto todo a tipo Single con CSng.
 subtotal=CSng(FormatNumber(carrito(clave))*oRs.Fie  lds("Precio"))
 total=total+subtotal
 %>
 <TD><%= subtotal %></TD>
 </TR>
 <%
 Next
 
 if carrito.Count > 0 then
 oRs.Close
 set oRs=nothing
 end if
 
 'Pinto el final de la tabla
 
 %>
 <TR>
 <TD COLSPAN=4><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Gastos de envío</font></TD>
 <TD>
 <%
 if total=0 then
 Response.Write("0") 	' Sin compra no hay gastos de envío
 else
 Response.Write(gastos)
 end if
 %>
 </TD>
 <TR>
 <TD COLSPAN=4><B><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Total:</font></B></TD>
 <TD>
 <%if total=0 then
 Response.Write("0")
 else
 Response.Write(total+gastos)
 end if
 %>
 </TD>
 </TABLE>
 <%
 ' Pinto los enlaces
 ' si no he llamado desde PasarPorCaja
 if accion<>"fin" then
 %>
 <center>
 <A HREF=Tienda.asp><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Seguir mirando</A></font> / <A HREF=Tienda.asp?ac=fin><FONT SIZE="3" COLOR="NAVY" FACE="HOBO">Pasar por caja</font></A>
 </center>
 <%
 end if
 End Sub
 '----------------------------------------------------------
 '----------------------------------------------------------
 
 Sub MeterArticulo (id)
 ' Añade el producto id al carrito de la compra
 ' En un caso real se deberían poder añadir más de una unidad
 ' bien desde el catálogo, bien editando en el carrito
 
 ' Si ya tengo el artículo en el carrito sumo 1 a la cantidad
 if carrito.Exists(id) then
 carrito(id)=carrito(id)+1
 else
 ' Si no lo añado
 carrito.Add id, 1
 end if
 
 Response.Write ("Se ha añadido el artículo al carrito<br>")
 End Sub
 
 Sub SacarArticulo (id, cantidad)
 ' Saca un numero "cantidad" de articulos "id" del carrito
 if not carrito.Exists(id) then
 Response.Write("¡No tienes eso en tu carrito!")
 else
 if cantidad>1 then
 'Quito todos así que quito ese articulo del carrito
 carrito.Remove(id)
 else
 'Quito uno
 carrito(id)=carrito(id)-1
 if carrito(id)<1 then
 carrito.Remove(id)
 end if
 end if
 end if
 
 End Sub
 
 Sub PasarPorCaja
 
 'Se lista el carrito una vez más
 ' y se muestra un mensaje de agradecimiento
 %>
 <H1><FONT  COLOR="NAVY" FACE="HOBO">¡Gracias por comprar!</font></H1>
 <%
 MostrarCarrito
 %>
 <br>
 <br>
 <FONT SIZE="3" COLOR="NAVY" FACE="HOBO">POR FAVOR Rellene el Formulario y en breve le llegarán a su casa los productos.<br> Gracias por
 comprar en <u><FONT SIZE="5" >La Corrala</u>.</Font></FONT>
 <br>
 
 <%
 ' Para el ejemplo, aquí libero la variable de sesión
 set Session("carrito")=nothing
 End Sub
 
 
 
 '---------------------------------
 ' Programa "principal"
 '---------------------------------
 Dim carrito
 Dim accion
 Dim producto
 Dim cant
 Dim oConn
 
 set oConn=Server.CreateObject("ADODB.Connection")
 oConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Tienda.mdb")
 
 
 ' Si no existe el carrito lo creo
 ' si existe lo referencio
 
 if isobject(Session("carrito")) then
 set carrito=Session("carrito")
 else
 set carrito=Server.CreateObject("Scripting.Dictionary"  )
 end if
 
 accion=CStr(Request.QueryString("ac"))	'Paso el parámetro a cadena
 producto=CInt(Request.QueryString("prod"))	'Paso el parámetro cant a número entero
 cant=CInt(Request.QueryString("cant"))	'Paso el parámetro cant a número entero
 
 Select Case accion
 
 Case "ver"
 'Muestro el carrito
 MostrarCarrito
 
 Case "meter"
 'Añado articulo al carrito
 MeterArticulo producto
 MostrarCarrito
 
 Case "sacar"
 ' Quito el numero 'cant' de articulos 'producto' del carrito
 call SacarArticulo (producto, cant)
 MostrarCarrito
 
 Case "fin"
 ' Muestro las compras y termino
 PasarPorCaja
 
 Case else
 'Muestro el catálogo
 MostrarCatalogo
 
 End Select
 
 set Session("carrito")=carrito
 oConn.Close
 set oConn=nothing
 
 %>
     |