public CartViewModelFactoryTests() { _cart = new FakeCart(new MarketImpl(MarketId.Default), Currency.USD); _cart.Forms.Single().Shipments.Single().LineItems.Add(new InMemoryLineItem { Quantity = 1, PlacedPrice = 105, LineItemDiscountAmount = 5 }); _startPage = new StartPage() { CheckoutPage = new ContentReference(1), WishListPage = new ContentReference(1) }; var contentLoaderMock = new Mock <IContentLoader>(); contentLoaderMock.Setup(x => x.Get <StartPage>(It.IsAny <ContentReference>())).Returns(_startPage); var languageResolverMock = new Mock <LanguageResolver>(); languageResolverMock.Setup(x => x.GetPreferredCulture()).Returns(CultureInfo.InvariantCulture); var shipmentViewModelFactoryMock = new Mock <ShipmentViewModelFactory>(null, null, null, null, null, null, languageResolverMock.Object); _cartItems = new List <CartItemViewModel> { new CartItemViewModel { DiscountedPrice = new Money(100, Currency.USD), Quantity = 1 } }; shipmentViewModelFactoryMock.Setup(x => x.CreateShipmentsViewModel(It.IsAny <ICart>())).Returns(() => new[] { new ShipmentViewModel { CartItems = _cartItems } }); _referenceConverterMock = new Mock <ReferenceConverter>(null, null); _referenceConverterMock.Setup(c => c.GetContentLink(It.IsAny <string>())).Returns(new ContentReference(1)); var currencyServiceMock = new Mock <ICurrencyService>(); currencyServiceMock.Setup(x => x.GetCurrentCurrency()).Returns(Currency.USD); _totals = new OrderGroupTotals( new Money(100, Currency.USD), new Money(100, Currency.USD), new Money(100, Currency.USD), new Money(100, Currency.USD), new Money(100, Currency.USD), new Dictionary <IOrderForm, OrderFormTotals>()); _orderDiscountTotal = new Money(5, Currency.USD); var orderGroupCalculatorMock = new Mock <IOrderGroupCalculator>(); orderGroupCalculatorMock.Setup(x => x.GetOrderDiscountTotal(It.IsAny <IOrderGroup>(), It.IsAny <Currency>())) .Returns(_orderDiscountTotal); orderGroupCalculatorMock.Setup(x => x.GetSubTotal(_cart)).Returns(new Money(_cart.GetAllLineItems().Sum(x => x.PlacedPrice * x.Quantity - ((ILineItemDiscountAmount)x).EntryAmount), _cart.Currency)); _subject = new CartViewModelFactory( contentLoaderMock.Object, currencyServiceMock.Object, orderGroupCalculatorMock.Object, shipmentViewModelFactoryMock.Object, _referenceConverterMock.Object); }
/// <summary> /// Updates the totals for the current order group. /// </summary> /// <param name="totals">The model containing calculated totals for the order group</param> protected virtual void UpdateOrderGroupTotals(OrderGroupTotals totals) { OrderGroup.SubTotal = totals.SubTotal.Amount; OrderGroup.Total = totals.Total.Amount; OrderGroup.ShippingTotal = totals.ShippingTotal.Amount; OrderGroup.TaxTotal = totals.TaxTotal.Amount; OrderGroup.HandlingTotal = totals.HandlingTotal.Amount; }
public List <OrderLine> GetOrderLines(ICart cart, OrderGroupTotals orderGroupTotals, bool sendProductAndImageUrlField) { var shipment = cart.GetFirstShipment(); var currentCountry = shipment.ShippingAddress?.CountryCode ?? cart.Market.Countries.FirstOrDefault(); var includedTaxesOnLineItems = !CountryCodeHelper.GetContinentByCountry(currentCountry).Equals("NA", StringComparison.InvariantCultureIgnoreCase); return(GetOrderLines(cart, orderGroupTotals, includedTaxesOnLineItems, sendProductAndImageUrlField)); }
private List <OrderLine> GetOrderLinesWithTax(ICart cart, OrderGroupTotals orderGroupTotals, bool sendProductAndImageUrl) { var shipment = cart.GetFirstShipment(); var orderLines = new List <OrderLine>(); var market = _marketService.GetMarket(cart.MarketId); // Line items foreach (var lineItem in cart.GetAllLineItems()) { var orderLine = lineItem.GetOrderLineWithTax(market, cart.GetFirstShipment(), cart.Currency, sendProductAndImageUrl); orderLines.Add(orderLine); } // Shipment if (shipment != null && orderGroupTotals.ShippingTotal.Amount > 0) { var shipmentOrderLine = shipment.GetOrderLine(cart, orderGroupTotals, true); orderLines.Add(shipmentOrderLine); } // Without tax var orderLevelDiscount = AmountHelper.GetAmount(cart.GetOrderDiscountTotal()); if (orderLevelDiscount > 0) { // Order level discounts with tax var totalOrderAmountWithoutDiscount = orderLines .Sum(x => x.TotalAmount); var totalOrderAmountWithDiscount = AmountHelper.GetAmount(orderGroupTotals.Total.Amount); var orderLevelDiscountIncludingTax = totalOrderAmountWithoutDiscount - totalOrderAmountWithDiscount; // Tax var totalTaxAmountWithoutDiscount = orderLines .Sum(x => x.TotalTaxAmount); var totalTaxAmountWithDiscount = AmountHelper.GetAmount(orderGroupTotals.TaxTotal); var discountTax = totalTaxAmountWithoutDiscount - totalTaxAmountWithDiscount; var taxRate = discountTax * 100 / (orderLevelDiscountIncludingTax - discountTax); orderLines.Add(new OrderLine() { Type = OrderLineType.discount, Name = "Discount", Quantity = 1, TotalAmount = orderLevelDiscountIncludingTax * -1, UnitPrice = orderLevelDiscountIncludingTax * -1, TotalTaxAmount = discountTax * -1, TaxRate = AmountHelper.GetAmount(taxRate) }); } return(orderLines); }
private List <OrderLine> GetOrderLinesWithoutTax(ICart cart, OrderGroupTotals orderGroupTotals, bool sendProductAndImageUrl) { var shipment = cart.GetFirstShipment(); var orderLines = new List <OrderLine>(); // Line items foreach (var lineItem in cart.GetAllLineItems()) { var orderLine = lineItem.GetOrderLine(sendProductAndImageUrl); orderLines.Add(orderLine); } // Shipment if (shipment != null && orderGroupTotals.ShippingTotal.Amount > 0) { var shipmentOrderLine = shipment.GetOrderLine(cart, orderGroupTotals, false); orderLines.Add(shipmentOrderLine); } // Sales tax orderLines.Add(new PatchedOrderLine() { Type = "sales_tax", Name = "Sales Tax", Quantity = 1, TotalAmount = AmountHelper.GetAmount(orderGroupTotals.TaxTotal), UnitPrice = AmountHelper.GetAmount(orderGroupTotals.TaxTotal), TotalTaxAmount = 0, TaxRate = 0 }); // Order level discounts var orderDiscount = cart.GetOrderDiscountTotal(cart.Currency); var entryLevelDiscount = cart.GetAllLineItems().Sum(x => x.GetEntryDiscount()); var totalDiscount = orderDiscount.Amount + entryLevelDiscount; if (totalDiscount > 0) { orderLines.Add(new PatchedOrderLine() { Type = "discount", Name = "Discount", Quantity = 1, TotalAmount = -AmountHelper.GetAmount(totalDiscount), UnitPrice = -AmountHelper.GetAmount(totalDiscount), TotalTaxAmount = 0, TaxRate = 0 }); } return(orderLines); }
#pragma warning restore 649 public static OrderLine GetOrderLine(this IShipment shipment, ICart cart, OrderGroupTotals totals, bool includeTaxes) { var total = AmountHelper.GetAmount(totals.ShippingTotal); var totalTaxAmount = 0; var taxRate = 0; if (includeTaxes) { var market = _marketService.Service.GetMarket(cart.MarketId); var shippingTaxTotal = _shippingCalculator.Service.GetShippingTax(shipment, market, cart.Currency); if (shippingTaxTotal.Amount > 0) { totalTaxAmount = AmountHelper.GetAmount(shippingTaxTotal.Amount); var shippingTotalExcludingTax = market.PricesIncludeTax ? totals.ShippingTotal.Amount - shippingTaxTotal.Amount : totals.ShippingTotal.Amount; taxRate = AmountHelper.GetAmount(shippingTaxTotal.Amount * 100 / shippingTotalExcludingTax); if (!market.PricesIncludeTax) { total = total + totalTaxAmount; } } } var shipmentOrderLine = new OrderLine { Name = shipment.ShippingMethodName, Quantity = 1, UnitPrice = total, TotalAmount = total, TaxRate = taxRate, TotalTaxAmount = totalTaxAmount, Type = OrderLineType.shipping_fee }; if (string.IsNullOrEmpty(shipmentOrderLine.Name)) { var shipmentMethod = Mediachase.Commerce.Orders.Managers.ShippingManager.GetShippingMethod(shipment.ShippingMethodId) .ShippingMethod.FirstOrDefault(); if (shipmentMethod != null) { shipmentOrderLine.Name = shipmentMethod.DisplayName; } } return(shipmentOrderLine); }
public CartViewModelFactoryTests() { _cart = new FakeCart(new MarketImpl(MarketId.Default), Currency.USD); _cart.Forms.Single().Shipments.Single().LineItems.Add(new InMemoryLineItem { Quantity = 1, PlacedPrice = 105, LineItemDiscountAmount = 5}); _startPage = new StartPage() { CheckoutPage = new ContentReference(1), WishListPage = new ContentReference(1) }; var contentLoaderMock = new Mock<IContentLoader>(); contentLoaderMock.Setup(x => x.Get<StartPage>(It.IsAny<ContentReference>())).Returns(_startPage); PreferredCultureAccessor accessor = () => CultureInfo.InvariantCulture; var shipmentViewModelFactoryMock = new Mock<ShipmentViewModelFactory>(null,null,null,null,null,null,accessor,null); _cartItems = new List<CartItemViewModel> {new CartItemViewModel {DiscountedPrice = new Money(100, Currency.USD), Quantity = 1} }; shipmentViewModelFactoryMock.Setup(x => x.CreateShipmentsViewModel(It.IsAny<ICart>())).Returns(() => new[] { new ShipmentViewModel {CartItems = _cartItems} }); var currencyServiceMock = new Mock<ICurrencyService>(); currencyServiceMock.Setup(x => x.GetCurrentCurrency()).Returns(Currency.USD); _totals = new OrderGroupTotals( new Money(100, Currency.USD), new Money(100, Currency.USD), new Money(100, Currency.USD), new Money(100, Currency.USD), new Money(100, Currency.USD), new Dictionary<IOrderForm, OrderFormTotals>()); var orderGroupTotalsCalculatorMock = new Mock<IOrderGroupTotalsCalculator>(); orderGroupTotalsCalculatorMock.Setup(x => x.GetTotals(It.IsAny<ICart>())).Returns(_totals); _orderDiscountTotal = new Money(5, Currency.USD); var orderGroupCalculatorMock = new Mock<IOrderGroupCalculator>(); orderGroupCalculatorMock.Setup(x => x.GetOrderDiscountTotal(It.IsAny<IOrderGroup>(), It.IsAny<Currency>())) .Returns(_orderDiscountTotal); orderGroupCalculatorMock.Setup(x => x.GetSubTotal(_cart)).Returns(new Money(_cart.GetAllLineItems().Sum(x => x.PlacedPrice * x.Quantity - ((ILineItemDiscountAmount)x).EntryAmount), _cart.Currency)); _subject = new CartViewModelFactory( contentLoaderMock.Object, currencyServiceMock.Object, orderGroupTotalsCalculatorMock.Object, orderGroupCalculatorMock.Object, shipmentViewModelFactoryMock.Object); }
public List <OrderLine> GetOrderLines(ICart cart, OrderGroupTotals orderGroupTotals, bool includeTaxOnLineItems, bool sendProductAndImageUrl) { return(includeTaxOnLineItems ? GetOrderLinesWithTax(cart, orderGroupTotals, sendProductAndImageUrl) : GetOrderLinesWithoutTax(cart, orderGroupTotals, sendProductAndImageUrl)); }
#pragma warning restore 649 public static PatchedOrderLine GetOrderLine(this IShipment shipment, ICart cart, OrderGroupTotals totals, bool includeTaxes) { var total = AmountHelper.GetAmount(totals.ShippingTotal); var totalTaxAmount = 0; var taxRate = 0; if (includeTaxes) { var shippingTaxTotal = _taxCalculator.Service.GetShippingTaxTotal(shipment, cart.Market, cart.Currency); if (shippingTaxTotal.Amount > 0) { totalTaxAmount = AmountHelper.GetAmount(shippingTaxTotal.Amount); taxRate = AmountHelper.GetAmount((shippingTaxTotal.Amount / totals.ShippingTotal.Amount) * 100); total = total + totalTaxAmount; } } var shipmentOrderLine = new PatchedOrderLine { Name = shipment.ShippingMethodName, Quantity = 1, UnitPrice = total, TotalAmount = total, TaxRate = taxRate, TotalTaxAmount = totalTaxAmount, Type = "shipping_fee" }; if (string.IsNullOrEmpty(shipmentOrderLine.Name)) { var shipmentMethod = Mediachase.Commerce.Orders.Managers.ShippingManager.GetShippingMethod(shipment.ShippingMethodId) .ShippingMethod.FirstOrDefault(); if (shipmentMethod != null) { shipmentOrderLine.Name = shipmentMethod.DisplayName; } } return(shipmentOrderLine); }
public List <OrderLine> GetOrderLines(ICart cart, OrderGroupTotals orderGroupTotals, bool sendProductAndImageUrlField) { var market = _marketService.GetMarket(cart.MarketId); return(GetOrderLines(cart, orderGroupTotals, market.PricesIncludeTax, sendProductAndImageUrlField)); }