Warenkorb, Session, Array, DB

rusak

Grünschnabel
Hallo Leute!

ich habe folgendes Problem, vielleicht kann mir ja jemand helfen.

Es geht um ein Warenkorb. In einer Session("ShoppingCart") sind mehrere Artikel enthalten, die mit ";" getrennt sind. Die Artikel selber sind in drei Werte unterteilt Artikel Nr, Anzahl, Zubehör. Bsp: 12345,5,0;53421,4,1;

Und hier der Code:


<table summary="Warenkorb" align="center" cellpadding="0" cellspacing="2" border="0" width="100%">

<tr bgcolor="#EFEFEF">
<th align="center">Artikel</th>
<th align="center">Anzahl </th>
<th align="center">Eizelpreis* </th>
<th align="center">Gesamtpreis*</th>
</tr>

<%
'split shoppingcart
Dim arrShoppingcart, SplitCart, SplitItem, arrItems, ItemCount, ItemQuantity, ItemTopic, ItemPPT
arrShoppingcart = Split(Left(Session("Shoppingcart"), Len(Session("Shoppingcart")) - 1), ";", -1, 0)


Dim Row, Color(1)
Color(0) = "#cccccc"
Color(1) = "#efefef"
Row = 0

For SplitCart = LBound(arrShoppingcart) To UBound(arrShoppingcart)
Row = Row + 1
Response.Write "<tr bgcolor=" & Color(Row mod 2) & ">"
arrItems = arrShoppingcart(SplitCart)
SplitItem = Split(arrItems, ",", -1, 0)

For ItemCount = LBound(SplitItem) To LBound(SplitItem)
Response.Write "<td>"
ItemTopic = SplitItem(0)
Response.Write (ItemTopic) & "<br>"
Response.Write "Artikel"
If CLng(SplitItem(2)) = 1 Then
Response.Write "<br>"
Response.Write "Zubehöhr"
End If
Response.Write "</td>"
Response.Write "<td align='center'>"
ItemQuantity = SplitItem(1)
Response.Write "<br>"
Response.Write (ItemQuantity)
If CLng(SplitItem(2)) = 1 Then
Response.Write "<br>"
Response.Write "1"
End If
Response.Write "</td>"
Next
Response.Write "</tr>"

Next
%>

<tr bgcolor="#EFEFEF">
<td><strong>Zwischensumme:</strong></td>
<td align="right" colspan="3"><%=(strFormatEuro(dblTotalItemCost))%></td>
</tr>
</table>

Das Auslesen funktioniert ja auch soweit, aber ich möchte noch weitere Daten ausgeben, wie Artikel-Titel und Preis. Diese Werte sind in einer DB gespeichert, Wie kann ich das ganze miteinander verbinden? Oder gibts es eine andere Lösung?

PS: Bin noch Anfänger und hoffe auf Eure Hilfe!
 
Hi

eigentlich kannst Du als Anfänger da überhaupt nix ändern. Diese Extension (shopingCart ist doch die DW-Entensions?) haben ihre vordefinierten Aktionen und sind nicht dafür gedacht, dort manuell einzugreifen. Ich würde auch nicht noch mehr in der Session speichern, warum? Die eindeutige Artikel-Nummer steht doch dort zur Verfügung und kann Dir über ein Select auf die Tabelle alle Daten auslesen, die Du möchtest.

Der Output der Session liefert Dir ein Array, welche Werte Du verarbeiten kannst.

Es werden in der 1. Dim. alle Werte aufgelistet. SplitItem(0) würde Dir z.B. alle Nummern liefern. Auslesen kann man diese Werte dann in Select z.B. über den in-Operator.

dim id
id = id & SplitItem(0) & ","
next
next

id = left(id,len(id)-1)
[...]
select * from artikel where id in (" & id & ")

Ich kenne die shoppingCart leider nicht. Von daher kann ich Dir nur auf der "Vorschlag" - Ebene helfen.
 
Hallo Luzie! Vielen Dank für deine Antwort. Nein, Shoppingcart ist nicht von DW. Ich habe das ganze auch schon kombinieren können:

Code:
    		'*** For ItemDetails
    		If Len(Request.Form("txtItem_PK")) > 0 Then
    			Session("ShoppingCart") = Session("ShoppingCart") & Request.Form("txtItem_PK") & "," & Request.Form("txtItemQuantity_PK") & "," & Request.Form("txtItemPPT_PK") & ";"


  'split shoppingcart
                        Dim arrShoppingcart, SplitCart, SplitItem, arrItems, ItemCount, ItemQuantity, ItemTopic, ItemPPT
                        arrShoppingcart = Split(Left(Session("Shoppingcart"), Len(Session("Shoppingcart")) - 1), ";", -1, 0)
                                            
                        
                        'Open Item in db from selected item from shoppingcart
                        Dim strSQL
                        strSQL = "SELECT * FROM tblProductItems WHERE Item IN ("
                                                
                        For SplitCart = LBound(arrShoppingcart) To UBound(arrShoppingcart)
                            arrItems = arrShoppingcart(SplitCart)
                            SplitItem = Split(arrItems, ",", -1, 0)
                            
                            For ItemCount = LBound(SplitItem) To UBound(SplitItem)
                            ItemTopic = SplitItem(ItemCount)
                            strSQL = strSQL & "'" & (ItemTopic) & "', "
                            ItemQuantity = SplitItem(1)
                            ItemPPT = SplitItem(2)    
                                        
                            Next
                        Next
                    
                        strSQL = Left(strSQL, Len(strSQL) - 2) & ");"
                        
                        Dim rsItemDetails
                        Set rsItemDetails = Server.CreateObject("ADODB.Recordset")
                        With rsItemDetails
                            .ActiveConnection    = Application("DbConn")
                            .CursorType         = 1   ' adOpenKeyset 
                            .CursorLocation     = 2   ' adUseServer
                            .LockType            = 3   ' adLockOptimistic
                            .Source                = strSQL
                            .Open
                        End With
                                                                      
                        'Loop Table Rows
                        While rsItemDetails.EOF = False 
                    
                        Dim dblTotalItemRowscriptCost, dblTotalItemRowPPTCost, dblItemPrice, dblItemPricePPT, dblTotalItemCost
                        dblItemPrice = CDbl(rsItemDetails("Price"))
                        dblItemPricePPT = CDbl(rsItemDetails("PricePPT"))
                        dblTotalItemRowscriptCost = dblItemPrice * ItemQuantity
                        dblTotalItemRowPPTCost = dblItemPricePPT

                        dblTotalItemCost = dblTotalItemCost + dblTotalItemRowscriptCost + dblTotalItemRowPPTCost

da wird aber die Menge nicht richtig zugeordnet. Weiß vielleicht jemand einen anderen Weg?

MfG
 
Hallo,

ich habe das ganze jetzt erstmal so gelöst:
Code:
<table summary="Warenkorb" align="center" cellpadding="0" cellspacing="2" border="1" width="100%">
                    
                    <tr bgcolor="#EFEFEF"> 
                        <th align="center" style="border-bottom: 1px solid #cccccc">Artikel</th>
                        <th align="center" style="border-bottom: 1px solid #cccccc">Anzahl </th>
                        <th align="center" style="border-bottom: 1px solid #cccccc">Eizelpreis* </th>
                        <th align="center" style="border-bottom: 1px solid #cccccc">Gesamtpreis*</th>
                    </tr>
                    <%
                        'split shoppingcart
                        Dim arrShoppingcart, SplitCart, SplitItem, arrItems, ItemCount, ItemQuantity, ItemTopic, ItemPPT
                        arrShoppingcart = Split(Left(Session("Shoppingcart"), Len(Session("Shoppingcart")) - 1), ";", -1, 0)
                                                
                        Dim strSQL
                        Dim rsItemDetails
                        Dim dblTotalItemRowCost, dblTotalItemRowPPTCost, dblItemPrice, dblItemPricePPT, dblTotalItemCost
                        
                        
                        ' Change RowColor
                        Dim Row, Color(1)
                        Color(0) = "#ffffff"
                        Color(1) = "#efefef"
                        Row = 0
                                                
                        For SplitCart = LBound(arrShoppingcart) To UBound(arrShoppingcart)
                            Row = Row + 1
                            Response.Write "<tr bgcolor=" & Color(Row mod 2) & ">"
                            arrItems = arrShoppingcart(SplitCart)
                            SplitItem = Split(arrItems, ",", -1, 0)
                            
                            For ItemCount = LBound(SplitItem) To LBound(SplitItem)
                            Response.Write "<td style='border-bottom: 1px solid #cccccc' nowrap>"
                            ItemTopic = SplitItem(0)
                            
                            strSQL = "SELECT * FROM tblProductItems WHERE Item='" & ItemTopic & "';"
                            
                            'Open Item in db from selected item from shoppingcart
                            Set rsItemDetails = Server.CreateObject("ADODB.Recordset")
                            With rsItemDetails
                                .ActiveConnection    = Application("DbConn")
                                .CursorType         = 1   ' adOpenKeyset 
                                .CursorLocation     = 2   ' adUseServer
                                .LockType            = 3   ' adLockOptimistic
                                .Source                = strSQL
                                .Open
                            End With
                            Response.Write rsItemDetails("Title") & "<br>"
                            Response.Write "Artikel"
                            If CLng(SplitItem(2)) = 1 Then
                            Response.Write "<br>"
                            Response.Write "Zubehör"
                            End If
                            
                            Response.Write "</td>"
                            Response.Write "<td align='center' style='border-bottom: 1px solid #cccccc'>"
                            ItemQuantity = SplitItem(1)
                            Response.Write "<br>"
                            Response.Write (ItemQuantity)
                            If CLng(SplitItem(2)) = 1 Then
                            Response.Write "<br>"
                            Response.Write "1"
                            End If
                            Response.Write "</td>"
                            Response.Write "<td align='right' style='border-bottom: 1px solid #cccccc'>"
                            Response.Write "<br>"
                            dblItemPrice = CDbl(rsItemDetails("Price"))
                            Response.Write (strFormatEuro(dblItemPrice)) & "<br>"
                            If CLng(SplitItem(2)) = 1 Then
                            dblItemPricePPT = CDbl(rsItemDetails("PricePPT"))
                            Response.Write (strFormatEuro(dblItemPricePPT))
                            End If
                            Response.Write "</td>"
                            Response.Write "<td align='right' style='border-bottom: 1px solid #cccccc'>"
                            Response.Write "<br>"
                            dblTotalItemRowCost = dblItemPrice * ItemQuantity
                            Response.Write (strFormatEuro(dblTotalItemRowCost)) & "<br>"
                            If CLng(SplitItem(2)) = 1 Then
                            dblTotalItemRowPPTCost = dblItemPricePPT
                            Response.Write (strFormatEuro(dblTotalItemRowPPTCost))
                            Else
                            dblTotalItemRowPPTCost = 0
                            End If
                            rsItemDetails.Close()
                            Set rsItemDetails = Nothing
                        Next    
                            Response.Write "</tr>"
                            dblTotalItemCost = dblTotalItemCost + dblTotalItemRowCost + dblTotalItemRowPPTCost
                        Next
                        %>
                    <tr bgcolor="#EFEFEF"> 
                        <td style="border-bottom: 1px dashed #cccccc"><strong>Zwischensumme:</strong></td>
                        <td align="right" colspan="3" style="border-bottom: 1px dashed #cccccc"><%=(strFormatEuro(dblTotalItemCost))%></td>
                    </tr>
                </table>

Vielleicht fällt mir später was besseres ein! Danke

MfG
 

Neue Beiträge

Zurück