 |
ソフトウェア > Lotus > Lotus Developer Domain >
Iris Today Archives
AddtoCart エージェント
 |
 |
 |
AddtoCart エージェントのコードは次のようになります。
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument, oiDoc As NotesDocument, cDoc As NotesDocument
Set db = s.CurrentDatabase
Set doc = s.DocumentContext
Dim vCartID As Variant, vISBN As Variant, vItemID As Variant, vMedia As
Variant, vQuantity As Variant, vPosn As Variant, vPath As Variant
Dim vOrderKey(1) As String
'CartID を決めます。
vCartID = Evaluate ({ @Middle (@LowerCase(Query_String) + "&";
"&cartid="; "&") }, doc)
If vCartID(0) = "" Then
vCartID= Evaluate({@Middle(@LowerCase(HTTP_COOKIE) + ";";"cartid=";";")},
doc)
End If
'URL から ISBN を取り出します。
vISBN = Evaluate ({ @Middle (@LowerCase(Query_String) + "&";
"&isbn="; "&") }, doc)
'ISBN をキーとして使い、カタログ文書を取り出します。
Set cDoc = db.GetView ("ISBNLookup").GetDocumentByKey (vISBN(0))
'もし注文された商品の文書があれば、それを取り出します。
vOrderKey(0)=vCartID(0)
vOrderKey(1)=vISBN(0)
Set oiDoc = db.GetView ("OrderISBNLookup").GetDocumentByKey (vOrderKey)
'注文商品の文書がなければ、新規に作成します。
If oiDoc Is Nothing Then
Set oiDoc = db.CreateDocument
oiDoc.Form = "OrderItem"
oiDoc.CartID = vCartID
oiDoc.Quantity = 1
oiDoc.ISBN = vISBN
oiDoc.Title = cDoc.Title
oiDoc.Author = cDoc.Author
'MediaType をカタログから取り出します。
cDoc.tempISBN = vISBN
vPosn = Evaluate ({@Member (tempISBN; MediaISBNs)}, cDoc) ' position of
ISBN in catalog entry doc
cDoc.tempPosn = vPosn
vMedia = Evaluate ( {@If (tempPosn = 0; "Error"; @Subset (@Subset
(MediaTypes; tempPosn); -1))}, cDoc)
oiDoc.Media = vMedia
Else
oiDoc.Quantity=oiDoc.Quantity(0) + 1
End If
'注文された商品があっても、価格が変わった可能性があるので、情報をアップデートします。
cDoc.tempISBN = vISBN
vPosn = Evaluate ({@Member (tempISBN; @lowercase (MediaISBNs))}, cDoc)
' position of ISBN in catalog entry doc
cDoc.tempPosn = vPosn
vPrice = Evaluate ( {@If (tempPosn = 0; "Error"; @Subset (@Subset
(MediaPrices; tempPosn); -1))}, cDoc)
oiDoc.Price = vPrice
Call oiDoc.Save (True, True)
'返す URL のパスを設定します。
vPath=Evaluate({@ReplaceSubstring (@Subset (@DbName; -1); "\\"
: " "; "/" : "+")})
Print "[" + vPath(0) + "/cart?ReadForm&CartID="
+ vCartID(0) + "]"
End Sub
|
 |
|
|