Created
October 27, 2015 11:56
-
-
Save lunchin/005ed819c61448ab7632 to your computer and use it in GitHub Desktop.
OrderRepository Version 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just checking.
PrincipalInfo.CurrentPrincipal.GetContactId()
,GetCommerceCustomerId()
andcurrentCustomerCommerceId
is the same value in the code above, right?And,
OrderRepository.Save(CurrentIOrderGroup);
should beOrderRepository.Save(cart);
or?