IBM®
Skip to main content
    Country/region select      Terms of use
 
 
   
     Home      Products      Services & solutions      Support & downloads      My account     
 
developerWorks
AIX and UNIX
Information Mgmt
Lotus
New to Lotus
Products
How to buy
Downloads
Live demos
Technical library
Training
Support
Forums & community
Events
Rational
Tivoli
WebSphere
Java™ technology
Linux
Open source
SOA and Web services
Web development
XML
My developerWorks
About dW
Submit content
Feedback



developerWorks  >  Lotus  >  Technical Library
developerWorks

[back to Anatomy of a Domino e-commerce Web site (Part 3)]

The UpdateCart agent
Here is the code for the UpdateCart agent:

Sub Initialize
    Dim s As New NotesSession, db As NotesDatabase
    Dim doc As NotesDocument, oiDoc As NotesDocument

    Set db = s.CurrentDatabase
    Set doc = s.DocumentContext

    Dim vCartID As Variant, vPath As Variant, vContent As Variant
    Dim vDelete As Variant, vQuantity As Variant, vISBN As Variant, vSessionID As Variant
    Dim emptyQuantity As Integer

    'Establish the CartID

    vCartID= Evaluate({@Middle(@LowerCase(HTTP_COOKIE) + ";";"cartid=";";")}, doc)
    If vCartID(0) = "" Then
      vCartID = Evaluate ({@Middle (@LowerCase(HTTP_Referer) + "&"; "&cartid="; "&")}, doc)
    End If

    'Explode Request_Content and then the individual fields within it

    vContent = Evaluate({@Explode(Request_Content;"&")}, doc)
    'If the customer has accidentally blanked out any quantities, vQunatity and vISBN will get out of
    'sync when trimmed. Thus, for each blank QUANTITY value in vContent, we'll simply blank out
    'its matching ISBN, which immediately follows the QUANTITY. This will keep us from updating the
    'quantity on this particular Order Item doc, but the quantity is already stored there and will simply
    'redisplay when the cart is refreshed.
    Forall arg In vContent
      If emptyQuantity Then
        arg = "ISBN="
        emptyQuantity = False
      End If
      If arg = "QUANTITY=" Then
        emptyQuantity = True
      End If
    End Forall

    doc.tmpContent = vContent
    vDelete=Evaluate({@Trim(@Right(tmpContent;"DELETE="))},doc)
    vQuantity=Evaluate({@Trim(@Right(tmpContent;"QUANTITY="))},doc)
    vISBN=Evaluate({@Trim(@Right(tmpContent;"ISBN="))},doc)

    'Update quantities for all Order Item documents for this customer

    For x=0 To Ubound(vISBN)
      Set oidoc = db.GetDocumentByUNID(vISBN(x))
      If Not oidoc Is Nothing Then
        If Cint(vQuantity(x))>0 Then
          oidoc.Quantity = Cint(vQuantity(x))
          Call oidoc.Save(True,True)
        End If
      End If
    Next
    'Delete an Order Item documents this customer has marked for delete

    If Not vDelete(0) ="" Then
      Forall v In vDelete
        Set oidoc = db.GetDocumentByUNID(v)
        If Not oidoc Is Nothing Then
          Call oidoc.Remove(True)
        End If
      End Forall
    End If

    'Set URL path for return - in this case a simple redisplay of the cart
    vPath=Evaluate({@ReplaceSubstring (@Subset (@DbName; -1); "\\" : " "; "/" : "+")})
    Print "[" + vPath(0) + "/cart?ReadForm&CartID=" + vCartID(0) + "]"
End Sub
    About IBM Privacy Contact