blithe
Jan 29th, 2004, 10:53 PM
Willing to pay for the solution. Email me ur price. Me need this urgently.Problem as follow:
done with the shopping cart thing, everything works okie except one thing, if the quantity is in textbox format and buyer can enter a number and click on a button to recalculate the prices and at the same time, store it into the dictionary. How can it be done? email me at chinestelle@hotmail.com
===========================================
<%
Sub AddItemToCart(iItemID, iItemCount)
If dictCart.Exists(iItemID) Then
dictCart(iItemID) = dictCart(iItemID) + iItemCount
Else
dictCart.Add iItemID, iItemCount
End If
Response.Write "Product has been added to your cart.<BR><BR>" & vbCrLf
End Sub
Sub RemoveItemFromCart(iItemID, iItemCount)
If dictCart.Exists(iItemID) Then
Response.Write iItemCount
If dictCart(iItemID) <= iItemCount Then
dictCart.Remove iItemID
Else
dictCart(iItemID) = len(dictCart(iItemID)) - 1
End If
Response.Write iItemCount & " of item # " & iItemID & " have been removed from your cart.<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
%>
<TABLE Border=1 CellPadding=5 CellSpacing=0 class=black width=600>
<TR>
<TD width=100>Item #</TD>
<TD width=100>Description</TD>
<TD>Quantity</TD>
<TD width=100>Remove From Cart</TD>
<TD width=100>Price</TD>
<TD width=100>Totals</TD>
</TR>
<%
dim sqltemp
dim category
set rst5=Server.CreateObject("ADODB.Recordset")
dim counterr
dim totall
totall = 0
For Each Key in dictCart
sqltemp="select * from Product where "
sqltemp=sqltemp & "Product_id="
sqltemp=sqltemp & "'"
sqltemp=sqltemp & key
sqltemp=sqltemp & "'"
rst5.open sqltemp, connection
counterr = len(dictCart(Key))
totall = totall + (counterr * rst5("price"))
%>
<TR>
<TD ALIGN="Center"><%= rst5("Product_ID") %></TD>
<TD ALIGN="Left"><%=rst5("model")%></TD>
<TD ALIGN="Center"><input size=3 type=textbox value="<%= counterr%>"></TD>
<TD ALIGN="Left"><A HREF="add.asp?action=del&item=<%= Key %>&count=<%= dictCart(Key) %>">Remove</A></TD>
<TD ALIGN="left">S$ <%= rst5("price") %></TD>
<TD ALIGN="left">S$ <%=counterr * rst5("price")%></TD>
</TR>
<%
rst5.close
Next
%>
</tr><Tr><td colspan=5 align=right bgcolor=lightblue>Total</td><td align=left bgcolor=lightblue>S$ <%=totall%></td>
</tr>
</TABLE>
<%
End Sub
%>
<% ' ***** 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
Set dictCart = Server.CreateObject("Scripting.Dictionary")
End If
' Get all the parameters passed to the script
sAction = Request.QueryString("action")
iItemID = Request.QueryString("item")
iItemCount = Request.QueryString("count")
%>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 width=600>
<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="<%=session("hpcat")%>">Continue Shopping</A>
<A HREF="confirm.asp">Checkout</A><BR>
<%
Case "del"
RemoveItemFromCart iItemID, iItemCount
ShowItemsInCart
%>
</TD></TR>
<TR><TD ALIGN="right">
<A HREF="<%=session("hpcat")%>">Continue Shopping</A>
<A HREF="confirm.asp">Checkout</A><BR>
<%
Case "viewcart"
ShowItemsInCart
%>
</TD></TR>
<TR><TD ALIGN="right">
<A HREF="add.asp?action="><IMG SRC="./images/shop_look.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="Continue Looking"></A>
<A HREF="add.asp?action=checkout"><IMG SRC="./images/shop_checkout.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="Checkout"></A><BR>
<%
Case "checkout"
PlaceOrder
%>
</TD></TR>
<TR><TD ALIGN="left">
<BR>
<H2>Thank you for your order!</H2>
If this had been an actual shopping cart, this is where you would have had them enter
their personal information and payment method and then taken care of any backend
processing before finalizing their order. However as this is a shopping cart sample
and this is where security becomes a problem, we'll leave it for a future sample.
<%
Case Else ' Shop
' ShowFullCatalog
ShowItemsInCart
%>
</TD></TR>
<TR><TD ALIGN="right">
<A HREF="add.asp?action=viewcart"><IMG SRC="./images/shop_cart.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="View Cart Contents"></A>
<%
End Select
' Return cart to Session for storage
Set Session("cart") = dictCart
%>
</TD></TR>
</TABLE>
</BODY>
</HTML>
done with the shopping cart thing, everything works okie except one thing, if the quantity is in textbox format and buyer can enter a number and click on a button to recalculate the prices and at the same time, store it into the dictionary. How can it be done? email me at chinestelle@hotmail.com
===========================================
<%
Sub AddItemToCart(iItemID, iItemCount)
If dictCart.Exists(iItemID) Then
dictCart(iItemID) = dictCart(iItemID) + iItemCount
Else
dictCart.Add iItemID, iItemCount
End If
Response.Write "Product has been added to your cart.<BR><BR>" & vbCrLf
End Sub
Sub RemoveItemFromCart(iItemID, iItemCount)
If dictCart.Exists(iItemID) Then
Response.Write iItemCount
If dictCart(iItemID) <= iItemCount Then
dictCart.Remove iItemID
Else
dictCart(iItemID) = len(dictCart(iItemID)) - 1
End If
Response.Write iItemCount & " of item # " & iItemID & " have been removed from your cart.<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
%>
<TABLE Border=1 CellPadding=5 CellSpacing=0 class=black width=600>
<TR>
<TD width=100>Item #</TD>
<TD width=100>Description</TD>
<TD>Quantity</TD>
<TD width=100>Remove From Cart</TD>
<TD width=100>Price</TD>
<TD width=100>Totals</TD>
</TR>
<%
dim sqltemp
dim category
set rst5=Server.CreateObject("ADODB.Recordset")
dim counterr
dim totall
totall = 0
For Each Key in dictCart
sqltemp="select * from Product where "
sqltemp=sqltemp & "Product_id="
sqltemp=sqltemp & "'"
sqltemp=sqltemp & key
sqltemp=sqltemp & "'"
rst5.open sqltemp, connection
counterr = len(dictCart(Key))
totall = totall + (counterr * rst5("price"))
%>
<TR>
<TD ALIGN="Center"><%= rst5("Product_ID") %></TD>
<TD ALIGN="Left"><%=rst5("model")%></TD>
<TD ALIGN="Center"><input size=3 type=textbox value="<%= counterr%>"></TD>
<TD ALIGN="Left"><A HREF="add.asp?action=del&item=<%= Key %>&count=<%= dictCart(Key) %>">Remove</A></TD>
<TD ALIGN="left">S$ <%= rst5("price") %></TD>
<TD ALIGN="left">S$ <%=counterr * rst5("price")%></TD>
</TR>
<%
rst5.close
Next
%>
</tr><Tr><td colspan=5 align=right bgcolor=lightblue>Total</td><td align=left bgcolor=lightblue>S$ <%=totall%></td>
</tr>
</TABLE>
<%
End Sub
%>
<% ' ***** 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
Set dictCart = Server.CreateObject("Scripting.Dictionary")
End If
' Get all the parameters passed to the script
sAction = Request.QueryString("action")
iItemID = Request.QueryString("item")
iItemCount = Request.QueryString("count")
%>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 width=600>
<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="<%=session("hpcat")%>">Continue Shopping</A>
<A HREF="confirm.asp">Checkout</A><BR>
<%
Case "del"
RemoveItemFromCart iItemID, iItemCount
ShowItemsInCart
%>
</TD></TR>
<TR><TD ALIGN="right">
<A HREF="<%=session("hpcat")%>">Continue Shopping</A>
<A HREF="confirm.asp">Checkout</A><BR>
<%
Case "viewcart"
ShowItemsInCart
%>
</TD></TR>
<TR><TD ALIGN="right">
<A HREF="add.asp?action="><IMG SRC="./images/shop_look.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="Continue Looking"></A>
<A HREF="add.asp?action=checkout"><IMG SRC="./images/shop_checkout.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="Checkout"></A><BR>
<%
Case "checkout"
PlaceOrder
%>
</TD></TR>
<TR><TD ALIGN="left">
<BR>
<H2>Thank you for your order!</H2>
If this had been an actual shopping cart, this is where you would have had them enter
their personal information and payment method and then taken care of any backend
processing before finalizing their order. However as this is a shopping cart sample
and this is where security becomes a problem, we'll leave it for a future sample.
<%
Case Else ' Shop
' ShowFullCatalog
ShowItemsInCart
%>
</TD></TR>
<TR><TD ALIGN="right">
<A HREF="add.asp?action=viewcart"><IMG SRC="./images/shop_cart.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="View Cart Contents"></A>
<%
End Select
' Return cart to Session for storage
Set Session("cart") = dictCart
%>
</TD></TR>
</TABLE>
</BODY>
</HTML>