Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/01/2007, 12:46
potenkin
 
Fecha de Ingreso: septiembre-2005
Mensajes: 202
Antigüedad: 19 años, 7 meses
Puntos: 0
Sonrisa Carrito de la compra incompleto

hola,
estoy montando una pequeña tienda con asp y sin DB (solo tiene 7 productos), he adaptado un carrito de la compra muy majo, y funciona bien, hace todas las funciones de añadir producto, eliminarlo, etc. todo en la misma pàgina asp.

el problema es que no esta completo y falta el paso final que es añadir los datos personales del comprador y enviar la info del pedido y los datos del comprador a un e.mail determinado.

alguien podria ayudarme.

Incluyo el codigo
------------------------------------

<% ' ***** Begin the functions to be called by the runtime script *****
' To find the actual runtime code scroll WAY DOWN....

' This function is written to enable the adding of multiples of an item
' but this sample always just adds one. If you wish to add different
' quantities simply replace the value of the Querystring parameter count.
' We didn't do this because we wanted to keep the whole thing simple and
' not get into using forms so it stayed relatively readable.
Sub AddItemToCart(iItemID, iItemCount)
If dictCart.Exists(iItemID) Then
dictCart(iItemID) = dictCart(iItemID) + iItemCount
Else
dictCart.Add iItemID, iItemCount
End If
Response.Write iItemCount & " de " & iItemID & " afegit correctament.<BR><BR>" & vbCrLf
End Sub

Sub RemoveItemFromCart(iItemID, iItemCount)
If dictCart.Exists(iItemID) Then
If dictCart(iItemID) <= iItemCount Then
dictCart.Remove iItemID
Else
dictCart(iItemID) = dictCart(iItemID) - iItemCount
End If
Response.Write iItemCount & " de " & iItemID & " eliminat correctament.<BR><BR>" & vbCrLf
Else
Response.Write "Couldn't find any of that item your cart.<BR><BR>" & vbCrLf
End If
End Sub

Sub ShowItemsInCart()
Dim Key
Dim aParameters ' as Variant (Array)
Dim sTotal, sShipping

%>
<link href="../ssts.css" rel="stylesheet" type="text/css" />

<TABLE Border=0 CellPadding=3 CellSpacing=1>
<TR>
<TD bgcolor="#FFFFCC">Item</TD>
<TD bgcolor="#FFFFCC">Descripci&oacute;n</TD>
<TD bgcolor="#FFFFCC">&nbsp;</TD>
<TD bgcolor="#FFFFCC">&nbsp;</TD>
<TD bgcolor="#FFFFCC">Precio</TD>
<TD bgcolor="#FFFFCC">Total</TD>
</TR>
<%
sTotal = 0
For Each Key in dictCart
aParameters = GetItemParameters(Key)
%>
<TR>
<TD ALIGN="Center"><%= Key %></TD>
<TD ALIGN="Left"><%= aParameters(1) %></TD>
<TD ALIGN="Center"><%= dictCart(Key) %></TD>
<TD ALIGN="Left"></A>&nbsp;<A HREF="./shopping.asp?action=del&item=<%= Key %>&count=<%= dictCart(Key) %>">Eliminar </A></TD>
<TD ALIGN="Right"><%= aParameters(2) %> &euro;</TD>
<TD ALIGN="Right"><%= FormatNumber(dictCart(Key) * CSng(aParameters(2)),2) %> &euro;</TD>
</TR>
<%
sTotal = sTotal + (dictCart(Key) * CSng(aParameters(2)))
Next

'Calculate shipping - you might want to pull this out into a function if your shipping
' calculations are more complicated then ours. ;)
If sTotal <> 0 Then
sShipping = 8.5
Else
sShipping = 0
End If
sTotal = sTotal + sShipping
%>
<TR>
<TD COLSPAN=5 ALIGN="Right"><B>Transporte :</B></TD>
<TD ALIGN="Right"><%= FormatNumber(sShipping,2) %> &euro;</TD>
</TR>
<TR>
<TD COLSPAN=5 ALIGN="Right"><B>Total :</B></TD>
<TD ALIGN="Right"><%= FormatNumber(sTotal,2) %> &euro;</TD>
</TR>
</TABLE>
<%
End Sub

Sub ShowFullCatalog()
Dim aParameters ' as Variant (Array)
Dim I
Dim iItemCount ' Number of items we sell
' If you are really going to use this sample this should probably be pulled from a DB
iItemCount = 7
%>
<link href="../ssts.css" rel="stylesheet" type="text/css" />
<TABLE Border=0 CellPadding=3 CellSpacing=1>
<TR>
<TD bgcolor="#FFFFCC">Imagen</TD>
<TD bgcolor="#FFFFCC">Descripci&oacute;n</TD>
<TD bgcolor="#FFFFCC">Precio</TD>
<TD bgcolor="#FFFFCC">A&ntilde;adir</TD>
</TR>
<%
For I = 1 to iItemCount
aParameters = GetItemParameters(I)
%>
<TR>
<TD><IMG SRC="<%= aParameters(0) %>"></TD>
<TD><%= aParameters(1) %></TD>
<TD><%= aParameters(2) %> &euro;</TD>
<TD><A HREF="./productos.asp?action=add&item=<%= I %>&count=1">Comprar</A></TD>
</TR>
<%
Next 'I
%>
</TABLE>
<%
End Sub

Sub PlaceOrder()
Dim Key
Dim aParameters ' as Variant (Array)
Dim sTotal, sShipping

%>
<link href="../ssts.css" rel="stylesheet" type="text/css" />
<TABLE Border=0 CellPadding=3 CellSpacing=1>
<TR>
<TD bgcolor="#FFFFCC">Item</TD>
<TD bgcolor="#FFFFCC">Descripci&oacute;n</TD>
<TD bgcolor="#FFFFCC">N&ordm;</TD>
<TD bgcolor="#FFFFCC">Precio</TD>
<TD bgcolor="#FFFFCC">Total</TD>
</TR>
<%
sTotal = 0
For Each Key in dictCart
aParameters = GetItemParameters(Key)
%>
<TR>
<TD ALIGN="Center"><%= Key %></TD>
<TD ALIGN="Left"><%= aParameters(1) %></TD>
<TD ALIGN="Center"><%= dictCart(Key) %></TD>
<TD ALIGN="Right"><%= aParameters(2) %> &euro;</TD>
<TD ALIGN="Right"><%= FormatNumber(dictCart(Key) * CSng(aParameters(2)),2) %> &euro;</TD>
</TR>
<%
sTotal = sTotal + (dictCart(Key) * CSng(aParameters(2)))
Next

'Calculate shipping - you might want to pull this out into a function if your shipping
' calculations are more complicated then ours. ;)
If sTotal <> 0 Then
sShipping = 7.5
Else
sShipping = 0
End If
sTotal = sTotal + sShipping
%>
<TR>
<TD COLSPAN=4 ALIGN="Right"><B>Transporte :</B></TD>
<TD ALIGN="Right"><%= FormatNumber(sShipping,2) %> &euro;</TD>
</TR>
<TR>
<TD COLSPAN=4 ALIGN="Right"><B>Total :</B></TD>
<TD ALIGN="Right"><%= FormatNumber(sTotal,2) %> &euro;</TD>
</TR>
</TABLE>
<%
End Sub

' We implemented this this way so if you attach it to a database you'd only need one call per item
Function GetItemParameters(iItemID)
Dim aParameters ' Will contain 3 string values : image path, description, price
' However we need to keep price so it can be converted to a
' single for computation hence no currency symbol. This array
' can also be expanded to contain any other information about the
' product that you might want to pull from the DB.
Select Case iItemID
Case 1
aParameters = Array("../img/envases/vidrio15.jpg", "Botella 1/4 litre, vidre", "5,00")
Case 2
aParameters = Array("../img/envases/vidrio30.jpg", "Botella 1/2 litre, vidre", "17,50")
Case 3
aParameters = Array("../img/envases/vidrio45.jpg", "Botella 3/4 litre, vidre", "35,00")
Case 4
aParameters = Array("../img/envases/vidrio5l.jpg", "Botella 5 litres, vidre", "5,00")
Case 5
aParameters = Array("../img/envases/plastic2l.jpg", "Botella 2 litres, plastic", "5,00")
Case 6
aParameters = Array("../img/envases/plastic5l.jpg", "Botella 5 litres, plastic", "5,00")
Case 7
aParameters = Array("../img/envases/caixa_regal.jpg", "Caixa regal, 2 botelles 1/2 litre, vidre", "5,00")
End Select
' Return array containing product info.
GetItemParameters = aParameters
End Function
%>




<% ' ***** Begin the infamous runtime script *****
' Declare our Vars
Dim dictCart ' as dictionary
Dim sAction ' as string
Dim iItemID ' as integer
Dim iItemCount ' as integer

' Get a reference to the cart if it exists otherwise create it
If IsObject(Session("cart")) Then
Set dictCart = Session("cart")
Else
' We use a dictionary so we can name our keys to correspond to our
' item numbers and then use their value to hold the quantity. An
' array would also work, but would be a little more complex and
' probably not as easy for readers to follow.
Set dictCart = Server.CreateObject("Scripting.Dictionary")
End If

' Get all the parameters passed to the script
sAction = CStr(Request.QueryString("action"))
iItemID = CInt(Request.QueryString("item"))
iItemCount = CInt(Request.QueryString("count"))
%>
<link href="../ssts.css" rel="stylesheet" type="text/css" />
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR><TD>
<%
' Select action based on user input
Select Case sAction
Case "add"
AddItemToCart iItemID, iItemCount
ShowItemsInCart
%>
</TD></TR>
<TR><TD ALIGN="right">
<A HREF="./productos.asp?action="><IMG SRC="../carrito/volver.gif" BORDER=0 WIDTH=88 HEIGHT=20 ALT="Continuar Comprando"></A>
<A HREF="./productos.asp?action=checkout"><IMG SRC="../carrito/pagar.gif" BORDER=0 WIDTH=88 HEIGHT=20 ALT="Checkout"></A><BR>
<%
Case "del"
RemoveItemFromCart iItemID, iItemCount
ShowItemsInCart
%>
</TD></TR>
<TR><TD ALIGN="right">
<A HREF="./productos.asp?action="><IMG SRC="../carrito/volver.gif" BORDER=0 WIDTH=88 HEIGHT=20 ALT="Continuar Comprando"></A>
<A HREF="./productos.asp?action=checkout"><IMG SRC="../carrito/pagar.gif" BORDER=0 WIDTH=88 HEIGHT=20 ALT="Checkout"></A><BR>
<%
Case "viewcart"
ShowItemsInCart
%>
</TD></TR>
<TR><TD ALIGN="right">
<A HREF="./productos.asp?action="><IMG SRC="../carrito/volver.gif" BORDER=0 WIDTH=88 HEIGHT=20 ALT="Continuar Comprando"></A>
<A HREF="./productos.asp?action=checkout"><IMG SRC="../carrito/pagar.gif" BORDER=0 WIDTH=88 HEIGHT=20 ALT="Checkout"></A><BR>
<%
Case "checkout"
PlaceOrder
%>
</TD></TR>
<TR><TD ALIGN="left">
<p><BR>
Gracias por su compra</p>
<p><br />
<%
Case Else ' Shop
ShowFullCatalog
%>
</p></TD>
</TR>
<TR><TD ALIGN="right">
<A HREF="./productos.asp?action=viewcart"><IMG SRC="../carrito/ver_carrito_cast.gif" BORDER=0 WIDTH=100 HEIGHT=20 ALT="Ver Carrito"></A>
<%
End Select

' Return cart to Session for storage
Set Session("cart") = dictCart
%>