Guest_imported
New member
- Jan 1, 1970
- 0
Hello,
I have been trying to write my own ASP shopping cart, but I've run into a problem. I want it that when the user sets the quantity to zero, the item is removed from the shopping cart. At the current time, all it does is display the quantity is 0 and the user still sees the item. I figured this is not that helpful for it only clutters up the shopping cart. I've been trying to do this-
if i = 0 then
redim sCartItemNums(ItemID)
- but I've had no luck. This uses sessions, so here is the global.asa file-
"Global.asa"
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
SUB Session_OnStart
dim sItemNums(0), nItemQtys(0)
sItemNums(0) = ""
nItemQtys(0) = 0
session("CartItemNumArray" = sItemNums
session("CartItemQtyArray" = nItemQtys
END SUB
</SCRIPT>
"END GLOBAL.ASA"
Here is the shopping cart page. Since all you need to see is the scripting, I've deleted all other code (navigation page code) and only left the shopping cart code. I've put a { symbol where I've been trying to put the i = 0 code, but I'm not sure it goes there...
"CART.ASP"
<!--#INCLUDE FILE="adovbs.inc"-->
<%
sCartItemNums = session("cartitemnumarray"
nCartItemQtys = session("cartitemqtyarray"
nNumCartItems = ubound(sCartItemNums)
'Determine the mode of this page's operation. If we got here from a
' link that had a "mode" querystring of "add", mode is add:
sMode = request.querystring("mode"
'Or, we could have gotten here from a form:
select case request.form("cmdSubmit"
case "Proceed to Checkout"
sMode = "checkout"
case "Recalculate Order"
sMode = "recalc"
case "Continue Shopping"
sMode = "continue"
end select
if sMode = "add" then
nThisItemIndex = 0
sItemNo = ucase(request.querystring("ItemID")
if nNumCartItems > 0 then
for i = 1 to nNumCartItems
if ucase(scartitemnums(i)) = sItemNo then
nThisItemIndex = i
exit for
end if
next
end if
if nThisItemIndex = 0 then
nThisItemIndex = nNumCartItems + 1
redim Preserve sCartItemNums(nThisItemIndex)
redim Preserve nCartItemQtys(nThisItemIndex)
sCartItemNums(nThisItemIndex) = sItemNo
nCartItemQtys(nThisItemIndex) = 1
else
nCartItemQtys(nThisItemIndex) = nCartItemQtys(nThisItemIndex) + 1
end if
session("cartitemnumarray" = sCartItemNums
session("cartitemqtyarray" = nCartItemQtys
nNumCartItems = ubound(sCartItemNums)
end if
if sMode = "recalc" or sMode = "checkout" or sMode = "continue" then
for i = 1 to nNumCartItems
nThisQty = int(request.form("txtItemQty" & i))
nCartItemQtys(i) = nThisQty
next
session("cartitemnumarray" = sCartItemNums
session("cartitemqtyarray" = nCartItemQtys
{ INSERTED THE I = 0 INFORMATION
{ WHICH DID NOT WORK.
end if
'Move to another page based on mode.
' If mode is "add" or "recalc", we stay here.
' If mode is "continue", we move back to the main page so the user
' can shop more.
' If mode is "checkout", we stay here but change the mode th
select case sMode
case "continue"
response.redirect("index.asp"
end select
set dbMain = server.createobject("ADODB.Connection"
dbMain.open "DSN=Products"
%>
<% if sMode = "checkout" then %>
<form action="submitorder.asp" method="POST">
<% else %>
<form action="cart.asp" method="POST">
<% end if %>
<%
if nNumCartItems = 0 then
response.write "There are no items in your shopping cart.<br>"
else
if sMode = "checkout" then
%>
Your order is ready to submit. Please provide the following information
and click the "Submit Order" button.
<br><br>
<table align="center" border="0">
<tr bgcolor="#c0c0c0">
<th colspan="2" align="center"><font face="Verdana,Arial" size="-1">
Customer Information</td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">Name:</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Text" name="txtCustomerName" size="30" maxlength="30">
</td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">Address:</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Text" name="txtAddress" size="30" maxlength="30"></td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">
City/State/ZIP:</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Text" name="txtCity" size="25" maxlength="30">
<input type="Text" name="txtState" size="4" maxlength="4">
<input type="Text" name="txtZIP" size="7" maxlength="7"></td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">
Daytime Phone:</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Text" name="txtPhone" size="15" maxlength="15"></td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">
Payment Method:</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Radio" name="optPaymentType" value="visa">
Visa
<input type="Radio" name="optPaymentType" value="mc">
Mastercard
<input type="Radio" name="optPaymentType" value="amex">
American Express
</td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">
Account Number:</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Text" name="txtAcctNo" size="20" maxlength="20"></td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">
Expiration (mm/yyyy):</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Text" name="txtExpDate" size="10" maxlength="7"></td>
</tr>
</table>
<%
else
response.write "Your shopping cart currently contains these items:"
end if
%>
<br><br>
<table align="center" border="0">
<tr bgcolor="#ff0066">
<th><font face="Verdana,Arial" color="#ffff33" size="-1">
Quantity</font></td>
<th><font face="Verdana,Arial" color="#ffff33" size="-1">
Item No.</font></td>
<th><font face="Verdana,Arial" color="#ffff33" size="-1">
Item Name</font></td>
<th><font face="Verdana,Arial" color="#ffff33" size="-1">
Price</font></td>
<th><font face="Verdana,Arial" color="#ffff33" size="-1">
Extension</font></td>
</tr>
<%
cSubTotal = 0
nNumItems = 0
for i = 1 to nNumCartItems
Set rsProducts = Server.CreateObject("ADODB.Recordset"
sSQL = "SELECT * FROM Products WHERE ItemID = '" & _
sCartItemNums(i) & "'"
rsProducts.open sSQL, dbMain, adopenstatic, _
adlockpessimistic, adcmdtext
%>
<tr bgcolor="#99ccff">
<%
sTemp = "<input type='Text' name='txtItemQty" & i & "' value='" & _
nCartItemQtys(i) & "' size='3'>"
nNumItems = nNumItems + nCartItemQtys(i)
%>
<td align="center">
<font face="Verdana,Arial" color="#000000" size="-1">
<% = sTemp %></font></td>
<td align="center">
<font face="Verdana,Arial" color="#000000" size="-1">
<% = rsProducts("ItemID" %></font></td>
<td><font face="Verdana,Arial" color="#000000" size="-1">
<% = rsProducts("ItemName" %></font></td>
<%
cPrice = rsProducts("Price"
%>
<td align="center">
<font face="Verdana,Arial" color="#000000" size="-1">
<% = formatcurrency(cPrice) %></font></td>
<%
cExtension = nCartItemQtys(i) * cPrice
cSubTotal = cSubTotal + cExtension
%>
<td align="right">
<font face="Verdana,Arial" color="#000000" size="-1">
<% = formatcurrency(cExtension) %></font></td>
</tr>
<% next %>
<tr bgcolor="#c5c5c5">
<td align="center" colspan="4">
<font face="Verdana,Arial" size="-1">Subtotal</font></td>
<td align="right"><font face="Verdana,Arial" size="-1">
<% = formatcurrency(cSubTotal) %></font></td>
</tr>
<% cShipping = 4.50 + (1.25 * nNumItems) %>
<tr bgcolor="#c5c5c5">
<td align="center" colspan="4">
<font face="Verdana,Arial" size="-1">Shipping & Handling</font></td>
<td align="right"><font face="Verdana,Arial" size="-1">
<% = formatcurrency(cShipping) %></font></td>
</tr>
<% cTotal = cSubTotal + cShipping %>
<tr bgcolor="#66ff00">
<td align="center" colspan = "4">
<font face="Verdana,Arial" size="-1">Grand Total</font></td>
<td align="right"><font face="Verdana,Arial" size="-1">
<% = formatcurrency(cTotal) %></font></td>
</tr>
</table>
<br><div align="center">
<input type="Submit" name="cmdSubmit" value="Continue Shopping">
<input type="Submit" name="cmdSubmit" value="Recalculate Order"><br><br>
<% if sMode = "checkout" then %>
<input type="Submit" name="cmdSubmit" value="Submit Order">
<% else %>
<input type="Submit" name="cmdSubmit" value="Proceed to Checkout">
<% end if %>
</div></form>
</font>
<% end if %>
"END CART.ASP"
Any Help would be much appreciated!!!
Thanks,
"Scotty"
I have been trying to write my own ASP shopping cart, but I've run into a problem. I want it that when the user sets the quantity to zero, the item is removed from the shopping cart. At the current time, all it does is display the quantity is 0 and the user still sees the item. I figured this is not that helpful for it only clutters up the shopping cart. I've been trying to do this-
if i = 0 then
redim sCartItemNums(ItemID)
- but I've had no luck. This uses sessions, so here is the global.asa file-
"Global.asa"
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
SUB Session_OnStart
dim sItemNums(0), nItemQtys(0)
sItemNums(0) = ""
nItemQtys(0) = 0
session("CartItemNumArray" = sItemNums
session("CartItemQtyArray" = nItemQtys
END SUB
</SCRIPT>
"END GLOBAL.ASA"
Here is the shopping cart page. Since all you need to see is the scripting, I've deleted all other code (navigation page code) and only left the shopping cart code. I've put a { symbol where I've been trying to put the i = 0 code, but I'm not sure it goes there...
"CART.ASP"
<!--#INCLUDE FILE="adovbs.inc"-->
<%
sCartItemNums = session("cartitemnumarray"
nCartItemQtys = session("cartitemqtyarray"
nNumCartItems = ubound(sCartItemNums)
'Determine the mode of this page's operation. If we got here from a
' link that had a "mode" querystring of "add", mode is add:
sMode = request.querystring("mode"
'Or, we could have gotten here from a form:
select case request.form("cmdSubmit"
case "Proceed to Checkout"
sMode = "checkout"
case "Recalculate Order"
sMode = "recalc"
case "Continue Shopping"
sMode = "continue"
end select
if sMode = "add" then
nThisItemIndex = 0
sItemNo = ucase(request.querystring("ItemID")
if nNumCartItems > 0 then
for i = 1 to nNumCartItems
if ucase(scartitemnums(i)) = sItemNo then
nThisItemIndex = i
exit for
end if
next
end if
if nThisItemIndex = 0 then
nThisItemIndex = nNumCartItems + 1
redim Preserve sCartItemNums(nThisItemIndex)
redim Preserve nCartItemQtys(nThisItemIndex)
sCartItemNums(nThisItemIndex) = sItemNo
nCartItemQtys(nThisItemIndex) = 1
else
nCartItemQtys(nThisItemIndex) = nCartItemQtys(nThisItemIndex) + 1
end if
session("cartitemnumarray" = sCartItemNums
session("cartitemqtyarray" = nCartItemQtys
nNumCartItems = ubound(sCartItemNums)
end if
if sMode = "recalc" or sMode = "checkout" or sMode = "continue" then
for i = 1 to nNumCartItems
nThisQty = int(request.form("txtItemQty" & i))
nCartItemQtys(i) = nThisQty
next
session("cartitemnumarray" = sCartItemNums
session("cartitemqtyarray" = nCartItemQtys
{ INSERTED THE I = 0 INFORMATION
{ WHICH DID NOT WORK.
end if
'Move to another page based on mode.
' If mode is "add" or "recalc", we stay here.
' If mode is "continue", we move back to the main page so the user
' can shop more.
' If mode is "checkout", we stay here but change the mode th
select case sMode
case "continue"
response.redirect("index.asp"
end select
set dbMain = server.createobject("ADODB.Connection"
dbMain.open "DSN=Products"
%>
<% if sMode = "checkout" then %>
<form action="submitorder.asp" method="POST">
<% else %>
<form action="cart.asp" method="POST">
<% end if %>
<%
if nNumCartItems = 0 then
response.write "There are no items in your shopping cart.<br>"
else
if sMode = "checkout" then
%>
Your order is ready to submit. Please provide the following information
and click the "Submit Order" button.
<br><br>
<table align="center" border="0">
<tr bgcolor="#c0c0c0">
<th colspan="2" align="center"><font face="Verdana,Arial" size="-1">
Customer Information</td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">Name:</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Text" name="txtCustomerName" size="30" maxlength="30">
</td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">Address:</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Text" name="txtAddress" size="30" maxlength="30"></td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">
City/State/ZIP:</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Text" name="txtCity" size="25" maxlength="30">
<input type="Text" name="txtState" size="4" maxlength="4">
<input type="Text" name="txtZIP" size="7" maxlength="7"></td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">
Daytime Phone:</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Text" name="txtPhone" size="15" maxlength="15"></td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">
Payment Method:</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Radio" name="optPaymentType" value="visa">
Visa
<input type="Radio" name="optPaymentType" value="mc">
Mastercard
<input type="Radio" name="optPaymentType" value="amex">
American Express
</td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">
Account Number:</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Text" name="txtAcctNo" size="20" maxlength="20"></td>
</tr>
<tr>
<td align="right"><font face="Verdana,Arial" size="-1">
Expiration (mm/yyyy):</td>
<td><font face="Verdana,Arial" size="-1">
<input type="Text" name="txtExpDate" size="10" maxlength="7"></td>
</tr>
</table>
<%
else
response.write "Your shopping cart currently contains these items:"
end if
%>
<br><br>
<table align="center" border="0">
<tr bgcolor="#ff0066">
<th><font face="Verdana,Arial" color="#ffff33" size="-1">
Quantity</font></td>
<th><font face="Verdana,Arial" color="#ffff33" size="-1">
Item No.</font></td>
<th><font face="Verdana,Arial" color="#ffff33" size="-1">
Item Name</font></td>
<th><font face="Verdana,Arial" color="#ffff33" size="-1">
Price</font></td>
<th><font face="Verdana,Arial" color="#ffff33" size="-1">
Extension</font></td>
</tr>
<%
cSubTotal = 0
nNumItems = 0
for i = 1 to nNumCartItems
Set rsProducts = Server.CreateObject("ADODB.Recordset"
sSQL = "SELECT * FROM Products WHERE ItemID = '" & _
sCartItemNums(i) & "'"
rsProducts.open sSQL, dbMain, adopenstatic, _
adlockpessimistic, adcmdtext
%>
<tr bgcolor="#99ccff">
<%
sTemp = "<input type='Text' name='txtItemQty" & i & "' value='" & _
nCartItemQtys(i) & "' size='3'>"
nNumItems = nNumItems + nCartItemQtys(i)
%>
<td align="center">
<font face="Verdana,Arial" color="#000000" size="-1">
<% = sTemp %></font></td>
<td align="center">
<font face="Verdana,Arial" color="#000000" size="-1">
<% = rsProducts("ItemID" %></font></td>
<td><font face="Verdana,Arial" color="#000000" size="-1">
<% = rsProducts("ItemName" %></font></td>
<%
cPrice = rsProducts("Price"
%>
<td align="center">
<font face="Verdana,Arial" color="#000000" size="-1">
<% = formatcurrency(cPrice) %></font></td>
<%
cExtension = nCartItemQtys(i) * cPrice
cSubTotal = cSubTotal + cExtension
%>
<td align="right">
<font face="Verdana,Arial" color="#000000" size="-1">
<% = formatcurrency(cExtension) %></font></td>
</tr>
<% next %>
<tr bgcolor="#c5c5c5">
<td align="center" colspan="4">
<font face="Verdana,Arial" size="-1">Subtotal</font></td>
<td align="right"><font face="Verdana,Arial" size="-1">
<% = formatcurrency(cSubTotal) %></font></td>
</tr>
<% cShipping = 4.50 + (1.25 * nNumItems) %>
<tr bgcolor="#c5c5c5">
<td align="center" colspan="4">
<font face="Verdana,Arial" size="-1">Shipping & Handling</font></td>
<td align="right"><font face="Verdana,Arial" size="-1">
<% = formatcurrency(cShipping) %></font></td>
</tr>
<% cTotal = cSubTotal + cShipping %>
<tr bgcolor="#66ff00">
<td align="center" colspan = "4">
<font face="Verdana,Arial" size="-1">Grand Total</font></td>
<td align="right"><font face="Verdana,Arial" size="-1">
<% = formatcurrency(cTotal) %></font></td>
</tr>
</table>
<br><div align="center">
<input type="Submit" name="cmdSubmit" value="Continue Shopping">
<input type="Submit" name="cmdSubmit" value="Recalculate Order"><br><br>
<% if sMode = "checkout" then %>
<input type="Submit" name="cmdSubmit" value="Submit Order">
<% else %>
<input type="Submit" name="cmdSubmit" value="Proceed to Checkout">
<% end if %>
</div></form>
</font>
<% end if %>
"END CART.ASP"
Any Help would be much appreciated!!!
Thanks,
"Scotty"