Skip to content

Instantly share code, notes, and snippets.

@lunchin
Created October 27, 2015 11:56
Show Gist options
  • Save lunchin/005ed819c61448ab7632 to your computer and use it in GitHub Desktop.
Save lunchin/005ed819c61448ab7632 to your computer and use it in GitHub Desktop.
OrderRepository Version 9
var cart = OrderRepository.Load<Cart>(PrincipalInfo.CurrentPrincipal.GetContactId(), Cart.DefaultName).FirstOrDefault();
if (cart == null)
{
cart = OrderRepository.Create<Cart>(GetCommerceCustomerId(), Cart.DefaultName);
cart.CustomerName = PrincipalInfo.CurrentPrincipal.Identity.Name;
var orderReference = OrderRepository.Save(cart);
}
var price = PriceService.GetDefaultPrice(marketId,
DateTime.UtcNow,
new CatalogKey(new Guid(variation.ApplicationId), variation.Code),
SiteContext.Current.Currency);
var lineItem = CreateLineItem(variation, quantity, price.UnitPrice.Amount);
var orderForm = cart.OrderForms.First();
orderForm.LineItems.Add(lineItem);
var index = orderForm.LineItems.IndexOf(lineItem);
cart.OrderForms.First().Shipments.First().AddLineItemIndex(index, lineItem.Quantity);
OrderRepository.Save(CurrentIOrderGroup);
//LineItems are cached so we need to load again
cart = OrderRepository.Load<Cart>(currentCustomerCommerceId, Cart.DefaultName).FirstOrDefault();
PromotionEngine.Run(cart);
// Save the updated promotions data
OrderRepository.Save(CurrentCart);
//LineItems are cached so we need to load again
cart = OrderRepository.Load<Cart>(currentCustomerCommerceId, Cart.DefaultName).FirstOrDefault();
@evest
Copy link

evest commented Oct 27, 2015

Just checking. PrincipalInfo.CurrentPrincipal.GetContactId(), GetCommerceCustomerId() and currentCustomerCommerceId is the same value in the code above, right?

And, OrderRepository.Save(CurrentIOrderGroup); should be OrderRepository.Save(cart); or?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment