30. september 2004 - 17:10
#6
Jeg har fundet en shop, men nu skal den tilpasses lidt, hvem kan hjælpe, den shop
har en vægt funktion indlagt, så den sætter porto efter vægt, det vil jeg gerne have fjernet, men kan ikek overskue det.
Her er koden.
<%
' ** Inserted by Jon Brohauge 2002/08/08
Dim SQLstmt, itemSQL, RS, itemRs, iMinID, iMaxID, vnr, img, desc, price, sBody
'** Informationer påkrævet til Ordrebekræftelse:
Dim sSellerName, sSellerAdresse, sSellerPostnr, sSellerCity, sSellerPhone, sSellerFax, sSellerEmail, sMailHost
sMailHost = "mail.tele.dk"
sSellerName = "jgsDemo butik"
sSellerAdresse = "jgsVej 999"
sSellerPostnr = "1234"
sSellerCity = "jgsBy"
sSellerPhone = "+45 12345678"
sSellerFax = "+45 98765432"
sSellerEmail = "rmo@pc.dk"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.MapPath("jgs.mdb")
Sub AddItemToCart(iItemID, iItemCount)
If dictCart.Exists(iItemID) Then
dictCart(iItemID) = dictCart(iItemID) + iItemCount
Else
dictCart.Add iItemID, iItemCount
End If
Response.Write iItemCount & " af varenummer " & iItemID & " blev tilføjet indkøbskurven.<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 & " af varenummer " & iItemID & " blev fjernet fra indkøbskurven.<BR><BR>" & vbCrLf
Else
Response.Write "Ingen varer af denne type blev fundet i indkøbskurven.<BR><BR>" & vbCrLf
End If
End Sub
Sub ShowItemsInCart()
Dim Key
Dim aParameters ' as Variant (Array)
Dim sTotal, sShipping
%>
<TABLE Border=1 CellPadding=3 CellSpacing=1>
<TR>
<TD>Varenummer</TD>
<TD>Beskrivelse</TD>
<TD>Antal</TD>
<TD>Ret Antal</TD>
<TD>Enhedspris</TD>
<TD>Subtotal</TD>
</TR>
<%
sTotal = 0
For Each Key in dictCart
aParameters = GetItemParameters(Key)
%>
<TR>
<TD ALIGN="Center"><%= aParameters(0) %></TD>
<TD ALIGN="Left"><%= aParameters(2) %></TD>
<TD ALIGN="Center"><%= dictCart(Key) %></TD>
<TD ALIGN="Left"><A HREF="default.asp?action=add&item=<%= Key %>&count=1&emne=<%=emne%>" title="Tilføj en"><img src="images/ico_add.gif" alt="Tilføj en" width="16" height="16" border="0"></A> <a href="./default.asp?action=del&item=<%= Key %>&count=1&emne=<%=emne%>" title="Fjern en"><img src="images/ico_delete.gif" alt="Fjern en" width="16" height="16" border="0"></A> <A HREF="./default.asp?action=del&item=<%= Key %>&count=<%= dictCart(Key) %>&emne=<%=emne%>" title="Fjern Alle">Fjern</A></TD>
<TD ALIGN="Right"><%=FormatCurrency(aParameters(3))%></TD>
<TD ALIGN="Right"> <%=FormatCurrency(dictCart(Key) * CSng(aParameters(3)),2)%></TD>
</TR>
<%
sTotal = sTotal + (dictCart(Key) * CSng(aParameters(3)))
Next
If sTotal <> 0 Then
Dim shippingRs, shippingWeight, dWeight
shippingWeight = 0
Set shippingRs = Server.CreateObject("ADODB.RecordSet")
For Each Key in dictCart
Set shippingRs = conn.Execute("SELECT weight FROM jgs WHERE id =" & Key)
shippingWeight = cDbl(shippingWeight) + (dictCart(Key)*cDbl(shippingRs("weight")))
Next
dWeight = Replace(FormatNumber(shippingWeight,2), ",", ".")
Set shippingRs = conn.Execute("SELECT weightPrice FROM weight WHERE weightLow <= " & dWeight & " AND " & dWeight & " < weightHigh")
sShipping = shippingRs("weightPrice")
Else
sShipping = 0
End If
sTotal = sTotal + sShipping
%>
<TR><TD COLSPAN=5 ALIGN="Right"><B>Fragt og Ekspedition:</B></TD><TD ALIGN="Right"><%= FormatCurrency(sShipping,2) %></TD></TR>
<TR><TD COLSPAN=5 ALIGN="Right"><B>Total incl. moms:</B></TD><TD ALIGN="Right"><%= FormatCurrency(sTotal,2) %></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
SQLstmt = "SELECT MIN(id) AS MinItemID, MAX(id) AS MaxItemID FROM jgs WHERE emne LIKE '" & emne & "'"
Set RS = Conn.Execute(SQLstmt)
iMinID = RS("MinItemID")
iMaxID = RS("MaxItemID")
%>
<TABLE Border=1 CellPadding=3 CellSpacing=1>
<TR>
<TD>Billede</TD>
<TD>Beskrivelse</TD>
<TD>Enhedspris</TD>
<TD>Tilføj indkøbskurv</TD>
</TR>
<%
For I = iMinID to iMaxID
aParameters = GetItemParameters(I)
%>
<TR>
<TD><IMG SRC="<%= aParameters(1) %>"></TD>
<TD><%= aParameters(2) %></TD>
<TD><%=FormatCurrency(aParameters(3))%></TD>
<TD><A HREF="default.asp?action=add&item=<%= I %>&count=1&emne=<%= emne %>"><img src="images/BUY.GIF" alt="Tilføj til Indkøbskurven" width="16" height="13" border="0"></A></TD>
</TR>
<%
Next 'I
%>
</TABLE>
<%
End Sub
Sub PlaceOrder()
Dim Key
Dim aParameters ' as Variant (Array)
Dim sTotal, sShipping
sBody = "<TABLE Border=1 CellPadding=3 CellSpacing=1>"
sBody = sBody & " <TR>"
sBody = sBody & " <TD>Varenummer</TD>"
sBody = sBody & " <TD>Beskrivelse</TD>"
sBody = sBody & " <TD>Antal</TD>"
sBody = sBody & " <TD>Enhedspris</TD>"
sBody = sBody & " <TD>Subtotal</TD>"
sBody = sBody & " </TR>"
sTotal = 0
For Each Key in dictCart
aParameters = GetItemParameters(Key)
sBody = sBody & " <TR>"
sBody = sBody & " <TD>" & aParameters(0) & "</TD>"
sBody = sBody & " <TD>" & aParameters(2) & "</TD>"
sBody = sBody & " <TD>" & dictCart(Key) & "</TD>"
sBody = sBody & " <TD>" & FormatCurrency(aParameters(3)) & "</TD>"
sBody = sBody & " <TD>" & FormatCurrency(dictCart(Key) * CSng(aParameters(3)),2) & "</TD>"
sBody = sBody & " </TR>"
sTotal = sTotal + (dictCart(Key) * CSng(aParameters(3)))
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
Dim shippingRs, shippingWeight, dWeight
shippingWeight = 0
Set shippingRs = Server.CreateObject("ADODB.RecordSet")
For Each Key in dictCart
Set shippingRs = conn.Execute("SELECT weight FROM jgs WHERE id =" & Key)
shippingWeight = cDbl(shippingWeight) + (dictCart(Key)*cDbl(shippingRs("weight")))
Next
dWeight = Replace(shippingWeight, ",", ".")
Set shippingRs = conn.Execute("SELECT weightPrice FROM weight WHERE weightLow <= " & dWeight & " AND " & dWeight & " < weightHigh")
sShipping = shippingRs("weightPrice")
Else
sShipping = 0
End If
sTotal = sTotal + sShipping
sBody = sBody & "<TR><TD COLSPAN=4 ALIGN=""Right""><B>Fragt og Ekspedition:</B></TD><TD ALIGN=""Right"">" & FormatCurrency(sShipping,2) & "</TD></TR>"
sBody = sBody & "<TR><TD COLSPAN=4 ALIGN=""Right""><B>Total excl. moms:</B></TD><TD ALIGN=""Right"">" & FormatCurrency((sTotal*4/5),2) & "</TD></TR>"
sBody = sBody & "<TR><TD COLSPAN=4 ALIGN=""Right""><B>Total incl. moms:</B></TD><TD ALIGN=""Right"">" & FormatCurrency(sTotal,2) & "</TD></TR>"
sBody = sBody & "</TABLE>"
End Sub
Sub GenerateEmailConfirmation()
Dim sSubject, sBodyText
Dim sUserName, sUserAdresse, sUserPostnr, sUserCity, sUserAtt, sUserTlf, sUserFax, sUserEmail, sDeliveryNavn, sDeliveryAdresse, sDeliveryPostnr, sDeliveryCity, sDeliveryNote
Dim fakturaConn, fInsertSQL, dInsertSQL, faktID, itemSQL, Key, aParameters, sSubTotal, sTotal, sShipping
Set fakturaConn = Server.CreateObject("ADODB.Connection")
fakturaConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.MapPath("faktura.mdb")
sUserName = Request.Form("navn")
sUserAdresse = Request.Form("adresse")
sUserPostnr = Request.Form("postnr")
sUserCity = Request.Form("city")
sUserAtt = Request.Form("att")
sUserTlf = Request.Form("tlf")
sUserFax = Request.Form("fax")
sUserEmail = Request.Form("email")
sDeliveryNavn = Request.Form("dnavn")
sDeliveryAdresse = Request.Form("dadresse")
sDeliveryPostnr = Request.Form("dpostnr")
sDeliveryCity = Request.Form("dcity")
sDeliveryNote = Request.Form("note")
sSubject = "Ordrebekræftelse fra butikken"
' Brug dictCart til at regenerere varene til databasen, samt varelisten i emailordrebekræftelsen
fInsertSQL = "INSERT INTO FKA_FakturaAddress (FKA_BuyerName, FKA_BuyerAddress, FKA_BuyerZipCode, FKA_BuyerCity, FKA_BuyerAtt, FKA_BuyerPhone, FKA_BuyerFax, FKA_BuyerEmail) VALUES ('" & sUserName & "', '" & sUserAdresse & "', '" & sUserPostnr & "', '" & sUserCity & "', '" & sUserAtt & "', '" & sUserTlf & "', '" & sUserFax & "', '" & sUserEmail & "')"
fakturaConn.Execute(fInsertSQL)
Set faktID = fakturaConn.Execute("SELECT @@IDENTITY FROM FKA_FakturaAddress")
If len(sDeliveryNavn)>0 Then
dInsertSQL = "INSERT INTO FKA_FakturaAddress (FKA_ParentID, FKA_BuyerName, FKA_BuyerAddress, FKA_BuyerZipCode, FKA_BuyerCity, FKA_Note) VALUES (" & faktID(0) & ", '" & sDeliveryNavn & "', '" & sDeliveryAdresse & "', '" & sDeliveryPostnr & "', '" & sDeliveryCity & "', '" & sDeliveryNote & "')"
fakturaConn.Execute(dInsertSQL)
End If
sTotal = 0
sBodyText = sBodyText & "Ordrebekræftelse" & vbCrLf
sBodyText = sBodyText & "--- --- --- --- " & vbCrLf & vbCrLf
sBodyText = sBodyText & "Afsender: " & vbCrLf
sBodyText = sBodyText & sSellerName & vbCrLf
sBodyText = sBodyText & sSellerAdresse & vbCrLf
sBodyText = sBodyText & sSellerPostnr & " " & sSellerCity & vbCrLf
sBodyText = sBodyText & "Tlf: " & sSellerPhone & vbCrLf
sBodyText = sBodyText & "Fax: " & sSellerFax & vbCrLf
sBodyText = sBodyText & "Email: " & sSellerEmail & vbCrLf
sBodyText = sBodyText & "--- --- --- --- " & vbCrLf & vbCrLf
sBodyText = sBodyText & "Betalingsadresse: " & vbCrLf
sBodyText = sBodyText & sUserName & vbCrLf
sBodyText = sBodyText & "Att: " & sUserAtt & vbCrLf
sBodyText = sBodyText & sUserAdresse & vbCrLf
sBodyText = sBodyText & sUserPostnr & " " & sUserCity & vbCrLf
If Len(sDeliveryNavn) > 0 Then
sBodyText = sBodyText & "--- --- --- --- " & vbCrLf & vbCrLf
sBodyText = sBodyText & "Leveringsadresse: " & vbCrLf
sBodyText = sBodyText & sDeliveryNavn & vbCrLf
sBodyText = sBodyText & sDeliveryAdresse & vbCrLf
sBodyText = sBodyText & sDeliveryPostnr & " " & sDeliveryCity & vbCrLf
End If
If Len(sBodyText) > 0 Then
sBodyText = sBodyText & "Notat: " & sDeliveryNote & vbCrLf
End If
sBodyText = sBodyText & "--- --- --- --- " & vbCrLf & vbCrLf
sBodyText = sBodyText & "Ordrenummer: " & faktID(0) & vbCrLf
sBodyText = sBodyText & "Ordredato: " & FormatDateTime(now, 1) & vbCrLf
sBodyText = sBodyText & "--- --- --- --- " & vbCrLf & vbCrLf
sBodyText = sBodyText & "Bestilte varer: " & vbCrLf
For Each Key in dictCart
aParameters = GetItemParameters(Key)
itemSQL = "INSERT INTO FKI_FakturaItem (FKI_FKA_ID, FKI_ItemNumber, FKI_ItemCount, FKI_Description, FKI_Pris, FKI_Emne) VALUES (" & faktID(0) & ", '" & aParameters(0) & "', '" & dictCart(Key) & "', '" & aParameters(2) & "', '" & aParameters(3) & "', '" & emne & "')"
fakturaConn.Execute(itemSQL)
sBodyText = sBodyText & "Varenummer: " & aParameters(0) & vbCrLf
sBodyText = sBodyText & "Beskrivelse: " & aParameters(2) & vbCrLf
sBodyText = sBodyText & "Antal: " & dictCart(Key) & vbCrLf
sBodyText = sBodyText & "Enhedspris: " & FormatCurrency(aParameters(3),2) & vbCrLf
sSubTotal = dictCart(Key) * CSng(aParameters(3))
sBodyText = sBodyText & "SubTotal: " & FormatCurrency(sSubTotal,2) & vbCrLf
sBodyText = sBodyText & " --- --- " & vbCrLf
sTotal = sTotal + sSubTotal
Next
If sTotal <> 0 Then
Dim shippingRs, shippingWeight, dWeight
shippingWeight = 0
Set shippingRs = Server.CreateObject("ADODB.RecordSet")
For Each Key in dictCart
Set shippingRs = conn.Execute("SELECT weight FROM jgs WHERE id =" & Key)
shippingWeight = cDbl(shippingWeight) + (dictCart(Key)*cDbl(shippingRs("weight")))
Next
dWeight = Replace(shippingWeight, ",", ".")
Set shippingRs = conn.Execute("SELECT weightPrice FROM weight WHERE weightLow <= " & dWeight & " AND " & dWeight & " < weightHigh")
sShipping = shippingRs("weightPrice")
Else
sShipping = 0
End If
sTotal = sTotal + sShipping
sBodyText = sBodyText & "Fragt og Ekspedition: " & FormatCurrency(sShipping,2) & vbCrLf
sBodyText = sBodyText & "Total excl. moms: " & FormatCurrency((sTotal*4/5),2) & vbCrLf
sBodyText = sBodyText & "Total incl. moms: " & FormatCurrency(sTotal,2)
' Send email til kunde
SendEmailMessage sUserEmail, sSellerEmail, sSubject, sBodyText
' Send email til sælger
SendEmailMessage sSellerEmail, sSellerEmail, sSubject, sBodyText
'** TESTING
End Sub
Function DebugOut(dbgStr)
Response.Write "<small>" & dbgStr & "</small><br>" & vbCrLf
End Function
Function htmlFormat(str)
htmlFormat = Replace(str, vbCrLf, "<br>")
End Function
Function GenerateKeyString()
Dim Key, sTemp
Dim aParameters ' as Variant (Array)
sTemp = ""
For Each Key in dictCart
aParameters = GetItemParameters(Key)
sTemp = sTemp & Key & ":" & dictCart(Key) & "::"
Next
GenerateKeyString = Server.URLEncode(sTemp)
End Function
' 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.
itemSQL = "SELECT varenr, images, beskrivelse, pris FROM jgs WHERE id=" & iItemID
Set itemRs = Conn.Execute(itemSQL)
If not(itemRs.bof or itemRs.eof) Then
vnr = itemRs("varenr")
img = itemRs("images")
desc = itemRs("beskrivelse")
price = CStr(itemRs("pris"))
End If
aParameters = Array(vnr, img, desc, price)
' 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("action"))
iItemID = CInt(Request("item"))
iItemCount = CInt(Request("count"))
emne = Request("emne")
%>
<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="./default.asp?emne=<%=emne%>&action="><IMG SRC="./images/shop_look.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="Find flere varer"></A>
<A HREF="./default.asp?action=checkout&emne=<%=emne%>"><IMG SRC="./images/shop_checkout.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="Indkøbskurv"></A><BR>
<%
Case "del"
RemoveItemFromCart iItemID, iItemCount
ShowItemsInCart
%>
</TD></TR>
<TR><TD ALIGN="right">
<A HREF="./default.asp?emne=<%=emne%>&action="><IMG SRC="./images/shop_look.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="Find flere varer"></A>
<A HREF="./default.asp?action=checkout&emne=<%=emne%>"><IMG SRC="./images/shop_checkout.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="Indkøbskurv"></A><BR>
<%
Case "viewcart"
ShowItemsInCart
%>
</TD></TR>
<TR><TD ALIGN="right">
<A HREF="./default.asp?emne=<%=emne%>&action="><IMG SRC="./images/shop_look.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="Find flere varer"></A>
<A HREF="./default.asp?action=checkout&emne=<%=emne%>"><IMG SRC="./images/shop_checkout.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="Indkøbskurv"></A><BR>
<%
Case "checkout"
' Dim sBody
%>
</TD></TR>
<TR><TD ALIGN="left">
<form action="default.asp?action=sendinfo&emne=<%=emne%>" method="post">
<table border="1" width="400">
<tr>
<td width="100%">
<table border="1" width="100%" height="460">
<tr>
<td width="100%" colspan="2" height="19">Faktura information</td>
</tr>
<tr>
<td width="50%" height="23">Navn</td>
<td width="50%" height="23"><input type="text" name="navn" size="20"></td>
</tr>
<tr>
<td width="50%" height="23">Adresse</td>
<td width="50%" height="23"><input type="text" name="adresse" size="20"></td>
</tr>
<tr>
<td width="50%" height="23">postnr.</td>
<td width="50%" height="23"><input type="text" name="postnr" size="20"></td>
</tr>
<tr>
<td width="50%" height="17">by</td>
<td width="50%" height="17"><input type="text" name="city" size="20"></td>
</tr>
<tr>
<td width="50%" height="19">att.rek</td>
<td width="50%" height="19"><input type="text" name="att" size="20"></td>
</tr>
<tr>
<td width="50%" height="19">Tlf</td>
<td width="50%" height="19"><input type="text" name="tlf" size="20"></td>
</tr>
<tr>
<td width="50%" height="19">fax</td>
<td width="50%" height="19"><input type="text" name="fax" size="20"></td>
</tr>
<tr>
<td width="50%" height="19">email</td>
<td width="50%" height="19"><input type="text" name="email" size="20"></td>
</tr>
<tr>
<td width="100%" colspan="2" height="19"> </td>
</tr>
<tr>
<td width="100%" colspan="2" height="38">Leverings adresse<br>
Udfyldes kun hvis der skal leveres på en anden adresse.</td>
</tr>
<tr>
<td width="50%" height="19">Navn</td>
<td width="50%" height="19"><input type="text" name="dnavn" size="20"></td>
</tr>
<tr>
<td width="50%" height="19">adresse</td>
<td width="50%" height="19"><input type="text" name="dadresse" size="20"></td>
</tr>
<tr>
<td width="50%" height="19">postnr</td>
<td width="50%" height="19"><input type="text" name="dpostnr" size="20"></td>
</tr>
<tr>
<td width="50%" height="19">by</td>
<td width="50%" height="19"><input type="text" name="dcity" size="20"></td>
</tr>
<tr>
<td width="50%" height="19">Note</td>
<td width="50%" height="19"><textarea rows="4" name="note" cols="26"></textarea></td>
</tr>
<tr>
<td width="50%" height="25"><input type="submit" value="Submit" name="B1"></td>
<td width="50%" height="25"><input type="reset" value="Reset" name="B2"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<%
PlaceOrder
Response.Write sBody
Case "sendinfo"
PlaceOrder
GenerateEmailConfirmation
%>
</TD></TR>
<TR><TD ALIGN="right">
<table border="1" width="400">
<tr>
<td width="100%">
<table border="1" width="100%">
<tr>
<td width="100%" height="19">Ordre bekræftelse:</td>
</tr>
<tr>
<td>Tak for ordren. Der er sendt en ordrebekræftelse til den emailadresse noteret på forrige side.</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%"><%=sBody%></td>
</tr>
</table>
<%
Case Else ' Shop
ShowFullCatalog
%>
</TD></TR>
<TR><TD ALIGN="right">
<A HREF="default.asp?action=viewcart&emne=<%=emne%>"><IMG SRC="./images/shop_cart.gif" BORDER=0 WIDTH=46 HEIGHT=46 ALT="Se Indkøbskruv"></A>
<%
End Select
' Return cart to Session for storage
Set Session("cart") = dictCart
%>
</TD></TR>
</TABLE>