public void CalculateTotals(OrderCalculationResponse responce) { _subTotal = responce.Subtotal; _total = responce.Total; _shipping = responce.Shipping; _tax = responce.Tax; }
public JsonNetResult UpdateItemSummary(bool?hideControls) { try { var model = new EnrollmentSummaryViewModel(); var order = new OrderCalculationResponse(); var hasShippingAddress = (PropertyBag.ShippingAddress != null && PropertyBag.ShippingAddress.IsComplete); var orderItems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order || c.Type == ShoppingCartItemType.EnrollmentPack).ToList(); if (hasShippingAddress) { model.IsCalculated = true; order = ExigoDAL.CalculateOrder(new OrderCalculationRequest { Configuration = OrderConfiguration, Items = orderItems, Address = PropertyBag.ShippingAddress, ShipMethodID = PropertyBag.ShipMethodID, ReturnShipMethods = true }); model.Total = order.Total; model.Shipping = order.Shipping; model.Tax = order.Tax; } model.OrderItems = ExigoDAL.GetItems(ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order), OrderConfiguration, CurrentLanguage.LanguageID); model.AutoOrderItems = ExigoDAL.GetItems(ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.AutoOrder), AutoOrderConfiguration, CurrentLanguage.LanguageID); model.OrderEnrollmentPacks = ExigoDAL.GetItems(ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.EnrollmentPack), OrderPacksConfiguration, CurrentLanguage.LanguageID); model.AutoOrderEnrollmentPacks = ExigoDAL.GetItems(ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.EnrollmentAutoOrderPack), AutoOrderConfiguration, CurrentLanguage.LanguageID); var autoOrderSubtotal = model.AutoOrderItems.Sum(c => c.Price * c.Quantity); var autoOrderPackSubtotal = model.AutoOrderEnrollmentPacks.Sum(c => c.Price * c.Quantity); var orderSubtotal = model.OrderItems.Sum(c => c.Price * c.Quantity); var orderPackSubtotal = model.OrderEnrollmentPacks.Sum(c => c.Price * c.Quantity); model.OrderSubtotal = (hasShippingAddress) ? order.Subtotal : (orderSubtotal + orderPackSubtotal); model.AutoOrderSubtotal = autoOrderPackSubtotal + autoOrderSubtotal; return(new JsonNetResult(new { success = true, orderitems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order), autoorderitems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.AutoOrder), html = this.RenderPartialViewToString("_EnrollmentSummary", model, new ViewDataDictionary { { "HideControls", hideControls } }) })); } catch (Exception ex) { return(new JsonNetResult(new { success = false, error = ex.Message })); } }
public ActionResult UpdateItemQuantity(Guid id, decimal quantity) { var item = ShoppingCart.Items.Where(c => c.ID == id).FirstOrDefault(); var subtotal = 0M; ShoppingCart.Items.Update(id, quantity); Exigo.PropertyBags.Update(ShoppingCart); if (quantity == 0) { item.Quantity = 0; } var totals = new OrderCalculationResponse(); if (ShoppingCart.Items.Count() > 0) { var itemCodes = ShoppingCart.Items.Select(c => c.ItemCode); var items = Exigo.GetItems(new ExigoService.GetItemsRequest { Configuration = OrderConfiguration, ItemCodes = itemCodes.ToArray() }).ToList(); foreach (var cartItem in items) { var shoppingCartItem = ShoppingCart.Items.Where(c => c.ItemCode == cartItem.ItemCode).FirstOrDefault(); cartItem.Quantity = shoppingCartItem.Quantity; } subtotal = items.Sum(c => c.Quantity * c.Price); } if (Request.IsAjaxRequest()) { return(new JsonNetResult(new { success = true, item = item, items = ShoppingCart.Items, subtotal = subtotal })); } else { return(RedirectToAction("Cart")); } }