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 virtual MiniCartViewModel CreateMiniCartViewModel(ICart cart) { if (cart == null) { return(new MiniCartViewModel { ItemCount = 0, CheckoutPage = _contentLoader.Get <StartPage>(ContentReference.StartPage).CheckoutPage, Shipments = Enumerable.Empty <ShipmentViewModel>(), Total = new Money(0, _currencyService.GetCurrentCurrency()) }); } return(new MiniCartViewModel { ItemCount = GetLineItemsTotalQuantity(cart), CheckoutPage = _contentLoader.Get <StartPage>(ContentReference.StartPage).CheckoutPage, Shipments = _shipmentViewModelFactory.CreateShipmentsViewModel(cart), Total = _orderGroupCalculator.GetSubTotal(cart) + _orderGroupCalculator.GetOrderDiscountTotal(cart, cart.Currency) }); }
public virtual MiniCartViewModel CreateMiniCartViewModel(ICart cart) { if (cart == null) { return(new MiniCartViewModel { ItemCount = 0, CheckoutPage = _contentLoader.Get <StartPage>(ContentReference.StartPage).CheckoutPage, Shipments = Enumerable.Empty <ShipmentViewModel>(), Total = _pricingService.GetMoney(0) }); } return(new MiniCartViewModel { ItemCount = GetCartLineItems(cart).Sum(x => x.Quantity), CheckoutPage = _contentLoader.Get <StartPage>(ContentReference.StartPage).CheckoutPage, Shipments = _shipmentViewModelFactory.CreateShipmentsViewModel(cart), Total = _orderGroupCalculator.GetSubTotal(cart) }); }
public virtual MiniCartViewModel CreateMiniCartViewModel(ICart cart, bool isSharedCart = false) { var labelSettings = _settingsService.GetSiteSettings <LabelSettings>(); var pageSettings = _settingsService.GetSiteSettings <ReferencePageSettings>(); if (cart == null) { return(new MiniCartViewModel { ItemCount = 0, CheckoutPage = pageSettings?.CheckoutPage, CartPage = isSharedCart ? pageSettings?.SharedCartPage : pageSettings?.CartPage, Label = isSharedCart ? labelSettings?.SharedCartLabel : labelSettings?.CartLabel, Shipments = Enumerable.Empty <ShipmentViewModel>(), Total = new Money(0, _currencyService.GetCurrentCurrency()), IsSharedCart = isSharedCart }); } return(new MiniCartViewModel { ItemCount = GetLineItemsTotalQuantity(cart), CheckoutPage = pageSettings?.CheckoutPage, CartPage = isSharedCart ? pageSettings?.SharedCartPage : pageSettings?.CartPage, Label = isSharedCart ? labelSettings?.SharedCartLabel : labelSettings?.CartLabel, Shipments = _shipmentViewModelFactory.CreateShipmentsViewModel(cart), Total = _orderGroupCalculator.GetSubTotal(cart), IsSharedCart = isSharedCart }); }
public virtual MiniCartViewModel CreateMiniCartViewModel(ICart cart, bool isSharedCart = false) { var startPage = _contentLoader.Get <PageData>(ContentReference.StartPage) as CommerceHomePage; if (cart == null) { return(new MiniCartViewModel { ItemCount = 0, CheckoutPage = startPage.CheckoutPage, CartPage = isSharedCart ? startPage.SharedCartPage : startPage.CartPage, Label = isSharedCart ? startPage.SharedCartLabel : startPage.CartLabel, Shipments = Enumerable.Empty <ShipmentViewModel>(), Total = new Money(0, _currencyService.GetCurrentCurrency()), IsSharedCart = isSharedCart }); } return(new MiniCartViewModel { ItemCount = GetLineItemsTotalQuantity(cart), CheckoutPage = startPage.CheckoutPage, CartPage = isSharedCart ? startPage.SharedCartPage : startPage.CartPage, Label = isSharedCart ? startPage.SharedCartLabel : startPage.CartLabel, Shipments = _shipmentViewModelFactory.CreateShipmentsViewModel(cart), Total = _orderGroupCalculator.GetSubTotal(cart), IsSharedCart = isSharedCart }); }
public virtual MiniCartViewModel CreateMiniCartViewModel(ICart cart) { if (cart == null) { return(new MiniCartViewModel { ItemCount = 0, CheckoutPage = _contentLoader.Get <StartPage>(ContentReference.StartPage).CheckoutPage, Shipments = Enumerable.Empty <ShipmentViewModel>(), Total = new Money(0, _currencyService.GetCurrentCurrency()), CurrentCustomer = _customerService.GetCurrentContact(), IsQuotedCart = false }); } // If order comes from a quoted order. var quotedCart = false; if (cart.Properties[Constants.Quote.ParentOrderGroupId] != null) { int orderLink = int.Parse(cart.Properties[Constants.Quote.ParentOrderGroupId].ToString()); if (orderLink != 0) { quotedCart = true; } } return(new MiniCartViewModel { ItemCount = GetLineItemsTotalQuantity(cart), CheckoutPage = _contentLoader.Get <StartPage>(ContentReference.StartPage).CheckoutPage, Shipments = _shipmentViewModelFactory.CreateShipmentsViewModel(cart), Total = _orderGroupCalculator.GetSubTotal(cart), IsQuotedCart = quotedCart, CurrentCustomer = _customerService.GetCurrentContact() }); }
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; }
private IHttpActionResult Finalize(ICart cart) { cart.ApplyDiscounts(); var total = _orderGroupCalculator.GetSubTotal(cart); var vippsPaymentMethodDto = PaymentHelper.GetVippsPaymentMethodDto().PaymentMethod.FirstOrDefault(); if (vippsPaymentMethodDto == null) { _logger.Warning("No payment method is setup for vipps"); return(GetUnsuccessfulResult("No payment method is setup for vipps")); } cart.GetFirstForm().Payments.Clear(); var payment = PaymentHelper.CreateVippsPayment(cart, total, vippsPaymentMethodDto.PaymentMethodId); cart.AddPayment(payment); _orderRepository.Save(cart); try { var paymentProcessingResults = cart.ProcessPayments().ToArray(); var successfulResult = paymentProcessingResults.FirstOrDefault(x => x.IsSuccessful && !string.IsNullOrEmpty(x.RedirectUrl)); if (successfulResult != null) { return(GetSuccessfulResult(paymentProcessingResults.FirstOrDefault(x => x.IsSuccessful) ?? paymentProcessingResults.FirstOrDefault())); } return(GetUnsuccessfulResult(paymentProcessingResults.FirstOrDefault(x => !string.IsNullOrEmpty(x.Message))?.Message)); } catch (Exception ex) { _logger.Error($"{ex.Message} {ex.StackTrace}"); return(GetUnsuccessfulResult(ex.Message)); } }