public async Task UpdateCheckoutAsync(Checkout checkout) { var shoppingCartModel = checkout.ToApiModel(); await _apiClient.CartClient.UpdateCurrentCartAsync(shoppingCartModel).ConfigureAwait(false); }
public static Checkout ToViewModel(this DataContracts.Cart.ShoppingCart shoppingCart, IEnumerable<PaymentMethod> paymentMethods, IEnumerable<ShippingMethod> shippingMethods) { var checkoutModel = new Checkout(); if (shoppingCart.Addresses != null) { var address = shoppingCart.Addresses.FirstOrDefault(); if (address != null) { checkoutModel.BillingAddress = address.ToViewModel(); checkoutModel.ShippingAddress = address.ToViewModel(); } } checkoutModel.Culture = shoppingCart.LanguageCode; checkoutModel.CustomerId = shoppingCart.CustomerId; checkoutModel.Currency = shoppingCart.Currency; checkoutModel.Id = shoppingCart.Id; foreach (var lineItem in shoppingCart.Items) { checkoutModel.LineItems.Add(lineItem.ToViewModel()); } if (shoppingCart.Payments != null) { var firstPayment = shoppingCart.Payments.FirstOrDefault(); if (firstPayment != null) { checkoutModel.PaymentMethodId = firstPayment.PaymentGatewayCode; } } foreach (var paymentMethod in paymentMethods) { checkoutModel.PaymentMethods.Add(paymentMethod); } if (shoppingCart.Shipments != null) { var firstShipment = shoppingCart.Shipments.FirstOrDefault(); if (firstShipment != null) { checkoutModel.ShippingMethodId = firstShipment.ShipmentMethodCode; } } foreach (var shippingMethod in shippingMethods) { checkoutModel.ShippingMethods.Add(shippingMethod); } checkoutModel.StoreId = shoppingCart.StoreId; return checkoutModel; }