public CartWidgetModel AddToCart(CartWidgetModel cartWidgetModel, string id, string countryCode, string locale) { return(new CartWidgetModel { Id = 111, Name = "Test Cart", Quantity = 10, Subtotal = 195.00m, VolumePoints = 100.25m }); }
public CartWidgetModel Post(CartWidgetModel cartWidgetModel) { try { var id = User.Identity.Name; var locale = CultureInfo.CurrentCulture.Name; var countrycode = new RegionInfo(CultureInfo.CurrentUICulture.Name).TwoLetterISORegionName; return(_cartWidgetSource.AddToCart(cartWidgetModel, id, countrycode, locale)); } catch (Exception ex) { LoggerHelper.Exception("Error", ex, "Failed HttpPost AddToCart for DS id" + User.Identity.Name); } return(null); }
private CartWidgetModel GetCartWidgetModelFromShoppingCart(MyHLShoppingCart myHLShoppingCart) { CartWidgetModel response = new CartWidgetModel(); if (myHLShoppingCart != null) { if (myHLShoppingCart.Totals == null) { myHLShoppingCart.Calculate(myHLShoppingCart.CartItems); } var total = myHLShoppingCart.Totals as OrderTotals_V01; if (total != null) { if (myHLShoppingCart.Locale == "ko-KR") { decimal subtotal = 0m; if (total.ItemTotalsList != null) { subtotal = total.ItemTotalsList.Sum(itemTotal => getDistributorPrice(itemTotal as ItemTotal_V01, total.DiscountPercentage, myHLShoppingCart.Locale)); } response.Subtotal = subtotal; } else if (myHLShoppingCart.Locale.Equals("es-MX")) { response.Subtotal = OrderProvider.getPriceWithAllCharges(total); } else { response.Subtotal = total.DiscountedItemsTotal; } response.VolumePoints = total.VolumePoints; response.DisplaySubtotal = getAmountString(response.Subtotal); } response.Id = myHLShoppingCart.ShoppingCartID; response.Quantity = myHLShoppingCart.CartItems.Sum(x => x.Quantity); } return(response); }
public CartWidgetModel AddToCart(CartWidgetModel cartWidget, string id, string countryCode, string locale) { if (null == cartWidget) { throw new ArgumentException("cartWidget is null", "cartWidget"); } if (string.IsNullOrEmpty(countryCode)) { throw new ArgumentException("countryCode is blank", "countryCode"); } if (string.IsNullOrEmpty(locale)) { throw new ArgumentException("Locale is blank", "locale"); } if (string.IsNullOrEmpty(id)) { throw new ArgumentException("id is blank", "id"); } var cartModel = GetCartWidget(id, countryCode, locale); if (null != cartModel) { cartWidget.Id = cartModel.Id; var proxy = ServiceClientProvider.GetShoppingCartServiceProxy(); try { var circuitBreaker = CircuitBreakerFactory.GetFactory().GetCircuitBreaker <AddItemsToCartResponse_V01>(); var response = circuitBreaker.Execute(() => proxy.AddItemsToCart(new AddItemsToCartRequest1(new AddItemsToCartRequest_V01 { ShoppingCartID = cartWidget.Id, OrderItems = new List <ServiceProvider.ShoppingCartSvc.OrderItem> { new ServiceProvider.ShoppingCartSvc.OrderItem { Quantity = cartWidget.Quantity, SKU = cartWidget.Sku } }, Platform = "MyHL", DistributorId = id, Locale = locale }))).AddItemsToCartResult as AddItemsToCartResponse_V01; if (response != null && response.Status == ServiceProvider.ShoppingCartSvc.ServiceResponseStatusType.Success) { ExpireShoppingCartCache(id, locale); ClearShoppingCartFromSession(id, locale); return(new CartWidgetModel { Id = response.ShoppingCartID, Quantity = response.TotalItems, Subtotal = response.Subtotal, DisplaySubtotal = String.Format("{0}{1}", HLConfigManager.Configurations.CheckoutConfiguration.CurrencySymbol, response.Subtotal) }); } LogErrorIfAny(response); return(null); } catch (Exception ex) { LoggerHelper.Exception("Error", ex, "Errored out in AddToCart"); if (null != proxy) { proxy.Close(); } throw; } finally { if (null != proxy) { proxy.Close(); } } } return(null); }