Code to Search for an Order and Display Line Item Information
After an order has been saved to the database, you can search for it based on a variety of criteria. In this example, the OrderGroupID will serve as the basis for the search.
This example code requires that you have already saved the order to the database as a template as is described in Code to Save an Order to the Database. Note that in the following example, the connection strings have been formatted for better display.
Create an instance of the AuthManager object to verify that the user is authenticated. This ensures that only registered users have access to their own order information.
Dim objAuthManager Set objAuthManager = Server.CreateObject("Commerce.AuthManager") objAuthManager.Initialize(<sitename>) If objAuthManager.IsAuthenticated() Then userID = objAuthManager.GetUserID(2) ' 2 is the ticket type denoting the Auth ticket. Else ' Force authentication End If
Create and initialize the OrderGroup object.
Dim oOrderGroup Set oOrderGroup = Server.CreateObject("Commerce.OrderGroup") oOrderGroup.Initialize "Provider=SQLOLEDB.1; Integrated Security='SSPI'; Initial Catalog=""Retail_commerce""; DataSource=TESTMACH2; Network Library=dbmssocn", sUserID
Create the SimpleFindSearchInfo object and set it to search for a known OrderGroupID for a specific user.
Dim oSFSearch, sReqID, sUserID Set oSFSearch = Server.CreateObject("Commerce.SimpleFindSearchInfo") sReqID ="754C40C6-EAA9-454C-A8AB-02789FBE0FB9" oSFSearch.ordergroup_id = sReqID oSFSearch.user_id = userID
Create the SimpleFindResultInfo object and set it to return data from the OrderGroup, OrderFormHeader, and OrderFormLineItems tables. Setting the JoinLineItemInfo property to True will cause the returned result set to include data from the OrderFormLineItems table. Setting the JoinOrderFormInfo property to True will cause the returned result set to include data from the OrderFormHeader table.
Dim oSFResult Set osfResult =Server.CreateObject("Commerce.SimpleFindResultInfo") oSFResult.JoinLineItemInfo = True oSFResult.JoinOrderFormInfo = True
Create a recordset to hold the search results.
Dim oRSResults Set oRSResults=Server.CreateObject("ADODB.Recordset")
Execute the search using the OrderGroupManager.SimpleFind method. The parameters for this method are the SimpleFindSearchInfo and SimpleFindResultInfo objects. Write the success status of the search to the screen.
Set oRSResults= oOGMgr.SimpleFind(oSFSearch, oSFResult) If err.number <> 0 Then Response.Write "Search error" Else Response.Write "Successful Search" & "<br>" End If
Iterate through the recordset, writing the OrderGroupID and the quantity ordered for each line item to the screen.
While Not oRSResults.EOF vtDisplay = "OrderGroup ID = " & oRSResults("ordergroup_id") _ & "<br>" Response.Write vtDisplay vtDisplay = "Quantity = " & oRSResults("quantity") _ & "<br>" & "<br>" Response.Write vtDisplay oRSResults.MoveNext WEnd
Copyright © 2005 Microsoft Corporation.
All rights reserved.