How to Add an OrderForm to a Basket
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
In Visual Studio, create a new Commerce Server Core Systems Web application.
Add the Microsoft.CommerceServer.Runtime resource to the Web application.
Add a using directive for the Microsoft.CommerceServer.Runtime.Orders namespace.
Create or retrieve a Basket.
Create a new OrderForm.
Add the OrderForm to the OrderFormCollection in the Basket.
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