[back to
Anatomy of a Domino e-commerce Web site (Part 3)
]
The (OrderWebQuerySave) agent
Here is the code for the (OrderWebQuerySave) agent:
Sub Initialize
Dim s As New NotesSession, db As NotesDatabase
Dim doc As NotesDocument
Dim strOrderID As String, strCartID As String
Dim strDBPath As String, strErrorMessage As String, vCartID As Variant
Set db = s.CurrentDatabase
Set doc=s.DocumentContext
Dim vPath As Variant
'Set URL path for this database
vPath=Evaluate({@ReplaceSubstring (@Subset (@DbName; -1); "\\" : " "; "/" : "+")})
'Get the CartID and OrderID as calculated on the Order document
strCartID = doc.CartID(0)
strOrderID = doc.ID(0)
'Perform field validations. Any errors will result in this order being saved as a
'draft and then it will be redisplayed to user with error message.
Dim vFieldVal As Variant
Forall ReqField In doc.RequiredCustFields
vFieldval = doc.GetItemValue (ReqField)
If vFieldval(0) = "" Then
doc.Status = "Draft"
Call doc.Save (False, True)
Goto ReturnErrorMessage
End If
End Forall
'If we make it this far there are no field validation problems. Save the order
'and call the CreditCard agent
doc.Status = "ReadyToCharge"
Call doc.Save (False, True)
'We use a separate agent for the credit card processing so the LSX doesn't
'have to load each time the order form saves. Only when validation has
'passed do we actually want to perform the credit card procesing.
Print "[/" + vPath(0) + "/CreditCard?OpenAgent&CartID=" + strCartID + "&r=" + strOrderID + "]"
Exit Sub
ReturnErrorMessage:
'Since there were validatoin errors, redisplay the order
Print "[/" + vPath(0) + "/0/" + doc.UniversalID + "?EditDocument&CartID=" + strCartID + "&ValError]"
End Sub