Last updated: Oct 24 2016

Area: Episerver Commerce Applies to versions: 10 and higher
Other versions:

EPiServer.Commerce.Sample guidelines [Legacy]

The following guidelines show order-related scenarios when working with the ECF API.

Adding an entry to a cart

void AddToCart(Entry entry)
    decimal quantity = 5;                        
    CartHelper cartHelper = new CartHelper(Cart.DefaultName);
    cartHelper.AddEntry(entry, quantity, false);

Getting cart items

Create a CartHelper instance with the name CartHelper.DefaultName to get items in the cart.

IEnumerable<LineItem> GetCartItems()
    CartHelper cart = new CartHelper(Cart.DefaultName);
    return cart.LineItems;

Adding an entry to a wish list

To add a product to cart, create an instance of CartHelper first. Then, call AddEntry to add a specific CatalogEntry to the cart.

void AddToWishList(Entry entry)
    decimal quantity = 5;                        
    CartHelper cart = new CartHelper(CartHelper.WishListName);
    cart.AddEntry(entry, quantity, false);

Getting wish list items

Create a new CartHelper with name CartHelper.WishListName to get all items in a wish list.

IEnumerable<LineItem> GetWishListItems()
    CartHelper wishList = new CartHelper(CartHelper.WishListName);
    return wishList.LineItems;

Getting promotions for an entry

Getting promotions for an entry is an advanced case. See the source code in the GetPromotions(this Entry entry) extension method to see how to do it.

Getting the order history

Use OrderContext.Current.GetPurchaseOrders to get all orders for a registered customer (user).

PurchaseOrder[] orders;
if (SecurityContext.Current.CurrentUser != null)
    orders = OrderContext.Current.GetPurchaseOrders(SecurityContext.Current.CurrentUserId).ToArray<PurchaseOrder>();                

Getting the order detail

Use OrderContext.Current.GetPurchaseOrderById to get detail for a specific order.

int orderGroupId = 3;
PurchaseOrder orderDetail = OrderContext.Current.GetPurchaseOrderById(orderGroupId);