public ActionResult EvalPromos(DemoPromoViewModel viewModel) { var market = _currentMarket.GetCurrentMarket(); var inMemOrderGroup = new InMemoryOrderGroup(market, market.DefaultCurrency); foreach (var item in viewModel.CatalogItems) { if (item.Quantity > 0) { var inMemLineItem = new InMemoryLineItem { Code = item.Code, Quantity = item.Quantity }; inMemOrderGroup.GetFirstShipment().LineItems.Add(inMemLineItem); } } var promoSettings = new PromotionEngineSettings(RequestFulfillmentStatus.All, true); viewModel.Rewards = _promoEngine.Run(inMemOrderGroup, promoSettings); viewModel.CartItems = inMemOrderGroup.GetFirstShipment().LineItems; if (inMemOrderGroup.GetFirstForm().Promotions.Count > 0) { viewModel.PromoItems = inMemOrderGroup.GetFirstForm().Promotions.First().Entries; } return(View("Index", viewModel)); }
public ActionResult Index(CartPage currentPage) { CartViewModel model = new CartViewModel(); var contactId = GetContactId(); var cart = _orderRepository.LoadCart <ICart>(contactId, DefaultCartName); if (cart == null) { return(View("NoCart")); } else { var warningMessages = ValidateCart(cart); if (string.IsNullOrEmpty(warningMessages)) { warningMessages = "No Messages"; } var descriptions = _promotionEngine.Run(cart); Money totalDiscount = _orderGroupCalculator.GetOrderDiscountTotal(cart, cart.Currency); model.PromotionMessage = string.Join("<br/>", descriptions.Select(x => x.Promotion.Name)); model.OrderDiscount = totalDiscount; model.LineItems = cart.GetAllLineItems(); model.SubTotal = _orderGroupCalculator.GetSubTotal(cart); model.WarningMessage = warningMessages; _orderRepository.Save(cart); } // The below is a dummy, remove when lab D2 is done return(View(model)); }
public ActionResult Index(CartPage currentPage) { var cart = _orderRepository.LoadCart <ICart>(GetContactId(), "Default"); if (cart == null) { return(View("NoCart")); } else { string warningMessages = ValidateCart(cart); if (string.IsNullOrEmpty(warningMessages)) { warningMessages = "No messages"; } _promotionEngine.Run(cart); var model = new CartViewModel() { LineItems = cart.GetAllLineItems(), SubTotal = _orderGroupCalculator.GetSubTotal(cart), WarningMessage = warningMessages }; _orderRepository.Save(cart); return(View(model)); } }
public string GetPromotions(ICart cart) { // ...very simple, mostly for verification and/or maybe do something // depending on the descriptions we get back String str = String.Empty; var rewardDescriptions = _promotionEngine.Run(cart).ToList(); rewardDescriptions.ForEach(r => str += r.Description); #region just checking, not doing anything with this IEnumerable <RedemptionDescription> redemptions; RedemptionLimitsData red; foreach (var item in cart.GetAllLineItems()) { decimal d = item.GetEntryDiscount(); Money m = item.GetDiscountedPrice(cart.Currency); } foreach (var item in rewardDescriptions) { red = item.Promotion.RedemptionLimits; redemptions = item.Redemptions; } #endregion // example with Coupons in QS return(str); }
public virtual IHttpActionResult PostCart([FromBody] OrderGroup orderGroup) { Logger.LogPost("PostCart", Request); try { if (string.IsNullOrEmpty(orderGroup.Name)) { throw new ArgumentNullException(nameof(orderGroup.Name)); } if (orderGroup.CustomerId == Guid.Empty) { throw new ArgumentNullException(nameof(orderGroup.CustomerId)); } var cart = _orderRepository.Create <Cart>(orderGroup.CustomerId, orderGroup.Name); cart = orderGroup.ConvertToCart(cart); _promotionEngine.Run(cart); cart.AcceptChanges(); return(Ok(cart)); } catch (Exception exception) { Logger.Error(exception.Message, exception); return(InternalServerError(exception)); } }
public ActionResult Index(CartPage currentPage) { // ToDo: (exercise D2) var cart = _orderRepository.LoadCart <ICart>( GetContactId() , DefaultCartName); // NOTE: a few different ways of loading cart // var cart1 = _orderRepository.Load<ICart>(GetContactId(), DefaultCartName).FirstOrDefault(); // var cart2 = _orderRepository.LoadCart<ICart>(GetContactId(), DefaultCartName); // var cart3 = _orderRepository.Load(); // all IOrderGroups for current user... 8 overloads if (cart == null) { return(View("NoCart")); // ...do this nicer } else { string warningMessages = ValidateCart(cart); if (String.IsNullOrEmpty(warningMessages)) { warningMessages += "No messages"; } _promotionEngine.Run(cart); Money totalDiscount = _orderGroupCalculator.GetOrderDiscountTotal(cart); var model = new CartViewModel { PromotionRewards = GetPromotionRewards(cart), LineItems = cart.GetAllLineItems(), // Extension method SubTotal = _orderGroupCalculator.GetSubTotal(cart), WarningMessage = warningMessages }; _orderRepository.Save(cart); return(View("index", model)); } // The below is a dummy, remove when lab D2 is done //return null; }
public string GetPromotions(ICart cart) { String str = String.Empty; var rewardDescriptions = _promotionEngine.Run(cart).ToList(); rewardDescriptions.ForEach(r => str += r.Description); // example with Coupons in QS return(str); }
public PurchaseOrderModel QuickBuyOrder(QuickBuyModel model, Guid customerId) { var cart = _orderRepository.LoadOrCreateCart <Cart>(customerId, Constants.Order.Cartname.Quickbuy); var item = _orderGroupFactory.CreateLineItem(model.Sku, cart); item.Quantity = 1; cart.GetFirstShipment().LineItems.Add(item); cart.GetFirstShipment().ShippingAddress = CreateAddress(model, cart, "Shipping"); if (!string.IsNullOrEmpty(model.CouponCode)) { cart.GetFirstForm().CouponCodes.Add(model.CouponCode); } cart.ValidateOrRemoveLineItems(ProcessValidationIssue); cart.UpdatePlacedPriceOrRemoveLineItems(ProcessValidationIssue); cart.UpdateInventoryOrRemoveLineItems(ProcessValidationIssue); _promotionEngine.Run(cart); cart.GetFirstForm().Payments.Add(CreateQuickBuyPayment(model, cart)); cart.GetFirstForm().Payments.FirstOrDefault().BillingAddress = CreateAddress(model, cart, "Billing"); cart.ProcessPayments(); cart.OrderNumberMethod = cart1 => GetInvoiceNumber(); var orderRef = _orderRepository.SaveAsPurchaseOrder(cart); var order = _orderRepository.Load <PurchaseOrder>(orderRef.OrderGroupId); order[Constants.Metadata.PurchaseOrder.Frequency] = model.Frequency.ToString(); order[Constants.Metadata.PurchaseOrder.LatestDelivery] = DateTime.Now.AddDays(5); OrderStatusManager.CompleteOrderShipment(order.GetFirstShipment() as Shipment); _orderRepository.Save(order); return(MapToModel(order)); }
private Money GetDiscountedPrice(string code, decimal placedPrice, IMarket market) { var inMemoryOrderGroup = new InMemoryOrderGroup(market, market.DefaultCurrency); inMemoryOrderGroup.AddLineItem(new InMemoryLineItem { Quantity = decimal.One, PlacedPrice = placedPrice, Code = code }); // calculate discounts var settings = new PromotionEngineSettings() { ApplyReward = false, RequestedStatuses = RequestFulfillmentStatus.Fulfilled }; var rewardDescriptions = _promotionEngine .Run(inMemoryOrderGroup, settings); var affectedEntries = rewardDescriptions .SelectMany(rd => rd.Redemptions) .Where(r => r.AffectedEntries != null) .SelectMany(r => r.AffectedEntries.PriceEntries); var affectedEntry = affectedEntries.FirstOrDefault(ae => ae.ParentItem.Code.Equals(code, StringComparison.OrdinalIgnoreCase)); if (affectedEntry != null) { var savedAmount = affectedEntry.OriginalTotal - affectedEntry.CalculatedTotal; var discountPrice = new PriceValue(); return(new Money(affectedEntry.CalculatedTotal, market.DefaultCurrency)); } else { var priceValue = new PriceValue(); return(new Money(placedPrice, market.DefaultCurrency)); } }
public ActionResult Index(CartPage currentPage) { var cart = _orderRepository.LoadCart <ICart>(PrincipalInfo.CurrentPrincipal.GetContactId(), "Default"); if (cart == null) { return(View("NoCart")); } var viewModel = new CartViewModel { WarningMessage = ValidateCart(cart), LineItems = cart.GetAllLineItems(), SubTotal = cart.GetSubTotal() }; var promos = _promotionEngine.Run(cart); _orderRepository.Save(cart); return(View(viewModel)); }