public virtual LargeCartViewModel CreateSimpleLargeCartViewModel(ICart cart) { if (cart == null) { var zeroAmount = new Money(0, _currencyService.GetCurrentCurrency()); return(new LargeCartViewModel() { TotalDiscount = zeroAmount, Total = zeroAmount, TaxTotal = zeroAmount, ShippingTotal = zeroAmount, Subtotal = zeroAmount, }); } var totals = _orderGroupCalculator.GetOrderGroupTotals(cart); var orderDiscountTotal = _orderGroupCalculator.GetOrderDiscountTotal(cart); var shippingDiscountTotal = cart.GetShippingDiscountTotal(); var discountTotal = shippingDiscountTotal + orderDiscountTotal; var model = new LargeCartViewModel() { TotalDiscount = discountTotal, Total = totals.Total, ShippingTotal = totals.ShippingTotal, Subtotal = totals.SubTotal, TaxTotal = totals.TaxTotal, ReferrerUrl = GetReferrerUrl(), }; return(model); }
public virtual LargeCartViewModel CreateLargeCartViewModel(ICart cart, CartPage cartPage) { var startPage = _contentLoader.Get <PageData>(ContentReference.StartPage) as CommerceHomePage; _ = _contentLoader.Get <CheckoutPage>(startPage.CheckoutPage); var contact = PrincipalInfo.CurrentPrincipal.GetCustomerContact(); AddressModel addressModel = null; if (cart == null) { var zeroAmount = new Money(0, _currencyService.GetCurrentCurrency()); addressModel = new AddressModel(); _addressBookService.LoadCountriesAndRegionsForAddress(addressModel); return(new LargeCartViewModel(cartPage) { Shipments = Enumerable.Empty <ShipmentViewModel>(), TotalDiscount = zeroAmount, Total = zeroAmount, TaxTotal = zeroAmount, ShippingTotal = zeroAmount, Subtotal = zeroAmount, ReferrerUrl = GetReferrerUrl(), CheckoutPage = startPage.CheckoutPage, //MultiShipmentPage = checkoutPage.MultiShipmentPage, AppliedCouponCodes = Enumerable.Empty <string>(), AddressModel = addressModel, ShowRecommendations = true }); } var totals = _orderGroupCalculator.GetOrderGroupTotals(cart); var orderDiscountTotal = _orderGroupCalculator.GetOrderDiscountTotal(cart); var shippingDiscountTotal = cart.GetShippingDiscountTotal(); var discountTotal = shippingDiscountTotal + orderDiscountTotal; var model = new LargeCartViewModel(cartPage) { Shipments = _shipmentViewModelFactory.CreateShipmentsViewModel(cart), TotalDiscount = discountTotal, Total = totals.Total, ShippingTotal = totals.ShippingTotal, Subtotal = totals.SubTotal, TaxTotal = totals.TaxTotal, ReferrerUrl = GetReferrerUrl(), CheckoutPage = startPage.CheckoutPage, //MultiShipmentPage = checkoutPage.MultiShipmentPage, AppliedCouponCodes = cart.GetFirstForm().CouponCodes.Distinct(), HasOrganization = contact?.OwnerId != null, ShowRecommendations = cartPage != null ? cartPage.ShowRecommendations : true }; var shipment = model.Shipments.FirstOrDefault(); addressModel = shipment?.Address ?? new AddressModel(); _addressBookService.LoadCountriesAndRegionsForAddress(addressModel); model.AddressModel = addressModel; return(model); }
public ActionResult LargeCart() { var items = _cartService.GetCartItems().ToList(); var viewModel = new LargeCartViewModel { CartItems = items, Total = _cartService.ConvertToMoney(items.Sum(x => x.ExtendedPrice.Amount)), TotalDiscount = _cartService.GetTotalDiscount() }; return(PartialView("LargeCart", viewModel)); }
public void CreateLargeCartViewModel_WhenCartIsNull_ShouldCreateViewModel() { var viewModel = _subject.CreateLargeCartViewModel(null); var expectedViewModel = new LargeCartViewModel { Shipments = Enumerable.Empty <ShipmentViewModel>(), Total = new Money(0, Currency.USD), TotalDiscount = new Money(0, Currency.USD) }; viewModel.ShouldBeEquivalentTo(expectedViewModel); }
public void CreateLargeCartViewModel_WhenCartIsNull_ShouldCreateViewModel() { var viewModel = _subject.CreateLargeCartViewModel(null); var expectedViewModel = new LargeCartViewModel { Shipments = Enumerable.Empty<ShipmentViewModel>(), Total = new Money(0, Currency.USD), TotalDiscount = new Money(0, Currency.USD) }; viewModel.ShouldBeEquivalentTo(expectedViewModel); }
public void CreateLargeCartViewModel_ShouldCreateViewModel() { var viewModel = _subject.CreateLargeCartViewModel(_cart); var expectedViewModel = new LargeCartViewModel { Shipments = new[] { new ShipmentViewModel { CartItems = _cartItems } }, Total = new Money(100, Currency.USD), TotalDiscount = _orderDiscountTotal, }; viewModel.ShouldBeEquivalentTo(expectedViewModel); }
public void CreateLargeCartViewModel_ShouldCreateViewModel() { var viewModel = _subject.CreateLargeCartViewModel(_cart); var expectedViewModel = new LargeCartViewModel { Shipments = new[] { new ShipmentViewModel { CartItems = _cartItems } }, Total = new Money(100, Currency.USD), TotalDiscount = _orderDiscountTotal, }; viewModel.Should().BeEquivalentTo(expectedViewModel); }
public override object MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context) { var cart = _cartService.LoadOrCreateCart(_cartService.DefaultCartName); AddToCartResult result = _cartService.AddToCart(cart, inputs.Get <string>("code"), inputs.Get <decimal>("quantity", 1m)); if (!result.EntriesAddedToCart) { context.Errors.AddRange(result.ValidationMessages.Select(m => new ExecutionError(m))); return(null); } _orderRepository.Save(cart); _recommendationService.TrackCartAsync(_httpContextBase.Invoke()).Wait(); LargeCartViewModel largeCartViewModel = _cartViewModelFactory.CreateLargeCartViewModel(cart); return(new { Cart = largeCartViewModel }); }
public ActionResult EstimateShipping(CartPage currentPage, LargeCartViewModel largeCartViewModel) { var orderAddress = CartWithValidationIssues.Cart.GetFirstShipment().ShippingAddress; if (orderAddress == null) { orderAddress = CartWithValidationIssues.Cart.CreateOrderAddress(Guid.NewGuid().ToString()); CartWithValidationIssues.Cart.GetFirstShipment().ShippingAddress = orderAddress; } orderAddress.CountryName = largeCartViewModel.AddressModel.CountryName; orderAddress.CountryCode = largeCartViewModel.AddressModel.CountryCode; orderAddress.RegionName = largeCartViewModel.AddressModel.CountryRegion.Region; orderAddress.PostalCode = largeCartViewModel.AddressModel.PostalCode; _orderRepository.Save(CartWithValidationIssues.Cart); var viewModel = _cartViewModelFactory.CreateLargeCartViewModel(CartWithValidationIssues.Cart, currentPage); return(View("LargeCart", viewModel)); }
public override object MutateAndGetPayload(MutationInputs inputs, ResolveFieldContext <object> context) { ICart cart = _cartService.LoadCart(_cartService.DefaultCartName); _cartService.ChangeCartItem( cart, inputs.Get <int>("shipmentId"), inputs.Get <string>("code"), inputs.Get <decimal>("quantity"), inputs.Get <string>("size"), inputs.Get <string>("newSize"), inputs.Get <string>("displayName")); _orderRepository.Save(cart); _recommendationService.TrackCartAsync(_httpContextBase.Invoke()).Wait(); LargeCartViewModel largeCartViewModel = _cartViewModelFactory.CreateLargeCartViewModel(cart); return(new { Cart = largeCartViewModel }); }
public void LargeCart_WhenCreatingViewModel_ShouldCreateModel() { var expectedResult = new LargeCartViewModel { CartItems = new List <CartItem> { new CartItem { Code = "code", DiscountPrice = new Money(45, Currency.USD), DisplayName = "red", ExtendedPrice = new Money(270, Currency.USD), PlacedPrice = new Money(50, Currency.USD), Url = "url", Quantity = 6 } }, Total = new Money(270, Currency.USD), TotalDiscount = new Money(30, Currency.USD) }; var result = ((PartialViewResult)_subject.LargeCart()).Model as LargeCartViewModel; result.ShouldBeEquivalentTo(expectedResult); }