Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.
An OrderAddress represents a ___location that items in the Basket will be shipped to. Since the items could be shipped to more than one ___location -- for example, half of the items could be shipped to the customer's home, and the other half could be shipped to the customer's office -- OrderAddresses are contained in an OrderAddressCollection. The OrderAddressCollection is contained in a Basket.
To add an OrderAddress to a Basket
In Visual Studio, create a new Commerce Server Web application.
Add the Microsoft.CommerceServer.Runtime reference to the Web application.
Add a using directive for the Microsoft.CommerceServer.Runtime.Orders namespace.
Create or retrieve a Basket.
Create a new OrderAddress and add it to the OrderAddressCollection in the Basket.
Save the updated Basket.
Example
The following code shows an example of how to add an OrderAddress to a Basket.
This example builds on the example in the topic How to Create a Basket.
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 "current".
Basket myBasket = OrderContext.Current.GetBasket(userID, "current");
// Create a new OrderAddress, and add it to the Basket.
OrderAddress myAddress = new OrderAddress();
myAddress.Line1 = "One Microsoft Way";
myAddress.City = "Redmond";
myAddress.State = "WA";
myAddress.CountryName = "USA";
myBasket.Addresses.Add(myAddress);
// Validate that we've really added the OrderAddress by
// displaying the OrderAddresses for the Basket.
foreach (OrderAddress theAddress in myBasket.Addresses)
{
Response.Write(theAddress.Line1 + "<br>");
Response.Write(theAddress.City + "<br>");
Response.Write(theAddress.State + "<br>");
Response.Write(theAddress.CountryName + "<br>");
} // end foreach
// Save the basket.
myBasket.Save();
} // end Page_Load method
} // end Default_aspx class