다음을 통해 공유


How to Convert a Basket to a PurchaseOrder

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

A PurchaseOrder represents a completed order, a shopping cart that has already gone through the checkout process. After you run the Checkout pipeline on a Basket, convert the Basket to a PurchaseOrder by using the SaveAsOrder method.

To convert a Basket to a PurchaseOrder

  1. In Visual Studio, create a new Commerce Server Web application.

  2. Add the Microsoft.CommerceServer.Runtime reference to the Web application.

  3. Add a using directive for the Microsoft.CommerceServer.Runtime.Orders namespace.

  4. Create or retrieve a Basket.

  5. Call the SaveAsOrder method.

  6. Save the updated PurchaseOrder.

Example

The following code shows an example of how to convert a Basket to a PurchaseOrder. In a full Commerce Server application, you would run the Checkout pipeline on the Basket before you convert the Basket to a PurchaseOrder.

using System;
using System.Collections;
using System.Web;
using Microsoft.CommerceServer.Runtime.Orders;

public partial class Default_aspx : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // For this example, create a new Guid for the user's ID.  
        // If this were part of a full CommerceServer site that
        // implemented logons, we could get the ID of the current
        // user from the CommerceContext.

        Guid userID = Guid.NewGuid();

        // Create a new Basket named "test basket".

        Basket myBasket = OrderContext.Current.GetBasket(userID, "test basket");

        // In a full Commerce Server application you would add
        // OrderForms, LineItems, Payments, and so on to the Basket, 
        // and then run the Basket, Payment, and Checkout pipeline
        // on the Basket before you converted the Basket to a
        // PurchaseOrder. In this small sample we'll just convert the 
        // Basket directly to a PurchaseOrder.

        // First, display the Basket's name, so that we can confirm
        // it's the same as the PurchaseOrder's name.

        Response.Write("Basket name: " + myBasket.Name + "<br>");

        // Convert the Basket to a PurchaseOrder, and save the.
        // PurchaseOrder.

        PurchaseOrder myPurchaseOrder = myBasket.SaveAsOrder();

        // Display the PurchaseOrder's name.

        Response.Write("PurchaseOrder name: " + myPurchaseOrder.Name + "<br>");

    } // end Page_Load method

} // end Default_aspx class

See Also

Reference

SaveAsOrder

Other Resources

Working with Baskets

How to Add Items to a Basket

Orders Runtime Object Model