다음을 통해 공유


How to Add an OrderForm to a Basket

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

An OrderForm represents a collection of items that a user placed in a shopping cart. Depending on how far the user has progressed through the purchasing process, an OrderForm might also contain the locations to ship the products to, the discounts that apply to the OrderGroup, and the ways that the user paid or will pay for the products.

An OrderForm is part of an OrderFormCollection, which is part of a Basket. An empty OrderFormCollection is created automatically when you create a Basket. Therefore, to associate an OrderForm with a Basket, you must not only create the OrderForm, but also add the OrderForm to the OrderFormCollection in the Basket.

To create an OrderForm

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

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

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

  4. Create or retrieve a Basket.

  5. Create a new OrderForm.

  6. Add the OrderForm to the OrderFormCollection in the Basket.

  7. Save the updated Basket.

Example

The following code shows an example of how to create a new OrderForm and add the OrderForm to the Basket. This example builds on the example in the topic How to Create a Basket.

using System;
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.

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

        // Create a new OrderForm and add it to the 
        // OrderFormCollection in the Basket.

        OrderForm orderForm = new OrderForm();
        myBasket.OrderForms.Add(orderForm);

        // Validate that we've really created an OrderForm by
        // displaying its creation date.

        Response.Write("Order form created: " + orderForm.Created.ToString() + "<br>");

        // Save the Basket, which includes the new OrderForm.

        myBasket.Save();

    } // end Page_Load method
} // end Default_aspx class

See Also

Other Resources

Working with Baskets

How to Add Items to a Basket

Orders Runtime Object Model