Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Navigation [hide] [expand]

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

Adding an entry to a cart

C#

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.

C#
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.

C#
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.

C#
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).

C#
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.

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

Last updated: Oct 12, 2015