Hej
Kender i ikke det. Det har virket engang, men gør det ikke længere. Jeg har
prøvet alt, men det virker ikke mere.
Jeg har gennem længere tid arbejdet på en webbutik. Det virker også meget
godt det meste, men ved selve indkøbskurven, der virker det ikke når man
ændre antallet, da den bliver ved at at skrive at man kun har bestilt 1 stk.
Jeg tror derfor det er et problem med min Recalcute Sub men er ikke sikker.
Er der nogen der kan hjælpe ?
Den kan testes "live" på
www.brygladen.dk/katalog.asp
Koden ser således ud:
<%
nVarenummer = Trim(Request.QueryString("id"))
nSide = Trim(Request.QueryString ("Side"))
bValid = True
If "" = nVarenummer Or Not IsNumeric(nVarenummer) Then
bValid = False
Else
Dim Conn
function OpenConn (DBName)
Set Conn = Server.CreateObject("ADODB.Connection")
ODBCpath = left(request.ServerVariables("PATH_TRANSLATED"),
instrrev(request.ServerVariables("PATH_TRANSLATED"), "\"))
Conn.Open "DBQ=" & ODBCpath & DBName & ";DefaultDir=" & ODBCpath &
";Driver={Microsoft Access Driver (*.mdb)}"
End function
OpenConn("bryg.mdb")
Set rs = Server.CreateObject ("ADODB.Recordset")
rs.ActiveConnection = Conn
rs.Open "Select Varenummer, Varetekst, Pris FROM katalog WHERE Varenummer="
& nVarenummer
If rs.EOF And rs.BOF Then
bValid = False
Else
avarProdukt = rs.GetRows ()
End If
Conn.Close
Set rs = Nothing
Set Conn = Nothing
End If
Set XMLDoc = Server.CreateObject ("Microsoft.XMLDOM")
If Not IsEmpty(Session("BagItems")) Then
XMLDOC.loadXML CStr(Session("BagItems"))
Set BagItems = XMLDoc.documentElement
Else
Set BagItems = XMLDoc.createElement("BagItems")
Set XMLDoc.documentElement = BagItems
End IF
If bValid then
Set nodeFind = BagItems.selectNodes("produkt[@Varenummer=""" & nVarenummer &
"""]")
If Not nodeFind.length > 0 Then
Set produkt = XMLDoc.createElement("produkt")
Set attr = XMLDOC.createAttribute ("Varenummer")
attr.Text = avarProdukt(0,0)
produkt.attributes.SetNamedItem(attr)
Set attr = XMLDoc.createAttribute ("Varetekst")
attr.Text = Server.HtmlEncode (avarProdukt(1,0))
produkt.attributes.SetNamedItem(attr)
Set attr = XMLDoc.createAttribute ("Pris")
attr.Text = avarProdukt(2,0)
produkt.attributes.setNamedItem(attr)
produkt.text = "1"
BagItems.appendChild(produkt)
End If
End If
Session("BagItems") = BagItems.XML
Sub Out(strOut)
Response.Write strOut
End Sub
Sub PrintBag(BagItems)
%>
<form ACTION="<% Request.ServerVariables("SCRIPT_NAME")%>" METHOD="POST">
<%
Out "<FORM METHOD=""POST"" ACTION="""
Out Request.ServerVariables("SCRIPT_NAME") & """>"
Out "<TABLE Align=""Center""><TR><TH Bgcolor=""9999ff"">Antal</TH><TH
COLSPAN=1 Bgcolor=""9999ff"">"
Out "Varenummer</TH><TH COLSPAN=2 BGcolor=""9999ff"">Varetekst</TH><TH
Bgcolor=""9999ff"">a Pris</TH><TH Bgcolor=""9999ff"">Ialt DKK</TH>"
Out "</TR>" & vbCrLf
For Each item In BagItems.childNodes
Out "<TR><TD><input type=""TEXT"" NAME=""Qty" & "</TD>"
Out """ VALUE=""" & item.text & """ SIZE=""3"">"
Out "<TD Align=""Center"">" & item.getAttribute("Varenummer")
Out "<TD>" & item.getAttribute("Varetekst") & "<TD></TD>"
nPris = item.getAttribute("Pris")
nSubTotal = item.text * nPris
nTotal = nTotal + nSubTotal
Out "<TD Align=""Right"">" & nPris & ",00" & "</TD>"
Out "<TD Align=""Right""><B>" & nSubTotal & ",00" & "</B></TD>"
Out "</TR>" & vbCRLF
Next
Out "<TR><TD COLSPAN=5></TD></TR>"
Out "<TR><TD COLSPAN=4></TD><TD><B>Total:</B></TD>"
Out "<TD Align=""Right""><B>" & FormatCurrency(nTotal) & "</B></TD></TR>" &
vbCrLf
Out "<TR><TD COLSPAN=5 ALIGN=""RIGHT"">"
Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Shop for more""> "
Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Recalculate""> "
Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Check out""> "
Out "</TD></TR></TABLE></FORM>"
End Sub
Sub Recalculate (BagItems)
For Each item in BagItems.childNodes
nQty = Trim(Request.Form("Qty" & item.getAttribute("Varenummer")))
If "" <> nQty And IsNumeric(nQty) Then
If nQty = 0 Then
BagItems.removeChild item
Else
item.text = nQty
End If
End If
Next
End Sub
%>
<% Response.Buffer = True %>
<%
%>
<html>
<head>
<title>Implementing the shopping Bag </title>
<h2 Align="Center">Indkøbskurv</h2>
</head>
<body bgcolor="#ffffff">
<%
XMLDOC.loadXML CStr(Session("BagItems"))
Set BagItems = XMLDOC.documentElement
If Request.ServerVariables("CONTENT_LENGTH") > 0 Then
Select Case Trim(Request.Form("DO"))
Case "Shop for more"
If nSide = "Kemi" then Response.Redirect "katalog.asp"
If nSide = "Sukker" then Response.Redirect "sukker.asp"
If nSide = "Tilbehør" Then Response.Redirect "tilbehor.asp"
If nSide = "Gær" Then Response.Redirect "gar.asp"
If nSide = "Malt" Then Response.Redirect "malt.asp"
If nSide = "Ekstrakt" Then Response.Redirect "ekstrakt.asp"
If nSide = "Humle" Then Response.Redirect "humle.asp"
If nSide = "Fadøl" Then Response.Redirect "fadol.asp"
If nSide = "Tilbud" Then Response.Redirect "tilbud.asp"
Response.End
Case "Recalculate"
Recalculate BagItems
Case "Check out"
Recalculate BagItems
Response.Redirect "checkout.asp"
Response.End
End Select
Else
End If
'Session("BagItems") = BagItems.XML
If BagItems.hasChildNodes Then
PrintBag BagItems
Else
Response.Write "Sorry, you have no items in your bag!"
End If
%>
</body>
</html>