public ActionResult ApplyCoupon(string couponCode, bool renderItems = false) { _catalogClient.CustomerSession.CouponCode = couponCode; var helper = GetCartHelper(CartHelper.CartName); var warnings = SaveChanges(helper); // Display the confirmation message var results = new CartJsonModel { CartSubTotal = StoreHelper.FormatCurrency(helper.Cart.Subtotal, helper.Cart.BillingCurrency), CartTotal = StoreHelper.FormatCurrency(helper.Cart.Total, helper.Cart.BillingCurrency), CartCount = helper.LineItems.Count(), LineItemsView = renderItems ? RenderRazorViewToString("LineItems", helper.CreateCartModel(true)) : null, CartName = CartHelper.CartName, Source = "LineItems" }; if (warnings != null) { foreach (var warning in warnings.Values) { results.Messages.Add(new MessageModel(warning)); } } if (warnings == null || !warnings.ContainsKey(WorkflowMessageCodes.COUPON_NOT_APPLIED)) { results.Messages.Add(string.IsNullOrEmpty(couponCode) ? new MessageModel("Coupon has been cleared".Localize()) : new MessageModel("Coupon has been applied".Localize())); } return(Json(results)); }
public ActionResult Add(string name, string itemId, string parentItemId, decimal?quantity, string[] relatedItemId = null) { decimal qty = 1; if (quantity.HasValue) { qty = quantity.Value; } if (String.IsNullOrEmpty(name)) { name = CartHelper.CartName; } var helper = GetCartHelper(name); var catalogItem = _catalogClient.GetItem(itemId); var parentItem = !string.IsNullOrEmpty(parentItemId) ? _catalogClient.GetItem(parentItemId) : null; var addedLineItems = new List <LineItemModel>(); var addedLineItem = DoAddToCart(name, qty, catalogItem, parentItem); if (addedLineItem != null) { addedLineItems.Add(new LineItemModel(addedLineItem, catalogItem, parentItem, helper.Cart.BillingCurrency)); } if (relatedItemId != null && relatedItemId.Length > 0) { addedLineItems.AddRange(from relItemId in relatedItemId let relItem = _catalogClient.GetItem(relItemId) let relatedItem = DoAddToCart(name, 1, relItem, null) where relatedItem != null select new LineItemModel(relatedItem, relItem, null, helper.Cart.BillingCurrency)); } if (Request.UrlReferrer != null) { UserHelper.CustomerSession.LastShoppingPage = Request.UrlReferrer.AbsoluteUri; } //helper.ClearCache(); //helper = GetCartHelper(name); var results = new CartJsonModel { CartSubTotal = StoreHelper.FormatCurrency(helper.Cart.Subtotal, helper.Cart.BillingCurrency), CartTotal = StoreHelper.FormatCurrency(helper.Cart.Total, helper.Cart.BillingCurrency), CartCount = helper.LineItems.Count(), LineItemsView = null, CartName = name }; results.Messages.Add(new MessageModel(string.Format("{0} items added to your {1}".Localize(), addedLineItems.Sum(li => li.Quantity), name.Localize()))); return(Json(results)); }
/// <summary> /// The resolve value. /// </summary> /// <returns> /// The <see cref="object"/>. /// </returns> public override object ResolveValue() { if (Content == null) { return(StoreHelper.FormatCurrency(0)); } var product = Content as IProductContent; if (product == null) { throw new Exception("Formatted price resolver can only be used with IProductContent models"); } return(StoreHelper.FormatCurrency(product.SalePrice)); }
/// <summary> /// Maps <see cref="IBasket"/> from customer context to UpdateBasket model. /// </summary> /// <returns> /// The <see cref="object"/>. /// </returns> public override object ResolveValue() { if (Content == null) { return(new UpdateBasket()); } var basket = Context.Basket; var contentResolver = ContentResolver.Instance; return(new UpdateBasket { ContinueShoppingUrl = contentResolver.GetRootContent().Url, FormattedBasketTotal = StoreHelper.FormatCurrency(basket.TotalBasketPrice), Items = basket.Items.Select(x => x.AsBasketItem(_merchello)).ToArray() }); }
/// <summary> /// Creates the price model. /// </summary> /// <param name="list">The list.</param> /// <param name="sale">The sale.</param> /// <param name="currency">The currency.</param> /// <returns>price model</returns> public static PriceModel CreatePriceModel(decimal list, decimal?sale, string currency) { var priceModel = new PriceModel { ListPrice = list, SalePrice = sale ?? list, Currency = currency }; if (priceModel.ListPrice != null) { priceModel.ListPriceFormatted = StoreHelper.FormatCurrency(priceModel.ListPrice.Value, priceModel.Currency); } if (priceModel.SalePrice != null) { priceModel.SalePriceFormatted = StoreHelper.FormatCurrency(priceModel.SalePrice.Value, priceModel.Currency); } return(priceModel); }
/// <summary> /// Creates an order summary. /// </summary> /// <returns> /// The <see cref="object"/>. /// </returns> public override object ResolveValue() { if (Content == null) { return(null); } if (Context.SalePreparation.IsReadyToInvoice()) { var invoice = Context.SalePreparation.PrepareInvoice(); return(new OrderSummary { FormattedSubTotal = StoreHelper.FormatCurrency(invoice.TotalItemPrice()), FormattedShippingTotal = StoreHelper.FormatCurrency(invoice.TotalShipping()), FormattedTotal = StoreHelper.FormatCurrency(invoice.Total), Items = invoice.Items, TotalTitle = "Total" }); } var shippingRate = 0M; const string TotalTitle = "Sub Total"; var total = Context.Basket.TotalBasketPrice; var shipment = Context.Basket.PackageBasket(new Address() { CountryCode = "GB" }).FirstOrDefault(); if (shipment != null) { var quote = shipment.ShipmentRateQuotes().FirstOrDefault(); if (quote != null) { shippingRate = quote.Rate; } total += shippingRate; } return(new OrderSummary { FormattedSubTotal = StoreHelper.FormatCurrency(Context.Basket.TotalBasketPrice), FormattedShippingTotal = StoreHelper.FormatCurrency(shippingRate), FormattedTotal = StoreHelper.FormatCurrency(total), Items = Context.Basket.Items, TotalTitle = TotalTitle }); }
public ActionResult RemoveFrom(string lineItemId, string cartName, bool clear = false, string sourceView = "LineItems", bool renderView = true) { var helper = GetCartHelper(cartName); var name = String.Empty; if (!helper.IsEmpty) { foreach (var item in helper.LineItems.Where(item => item.LineItemId == lineItemId || clear).ToArray()) { name = item.DisplayName; helper.Remove(item); } } // If cart is empty, remove it from the database if (helper.IsEmpty) { helper.Delete(); } SaveChanges(helper); // Display the confirmation message var results = new CartRemoveModel { CartSubTotal = StoreHelper.FormatCurrency(helper.Cart.Subtotal, helper.Cart.BillingCurrency), CartTotal = StoreHelper.FormatCurrency(helper.Cart.Total, helper.Cart.BillingCurrency), CartCount = helper.LineItems.Count(), LineItemsView = renderView && !string.IsNullOrEmpty(sourceView) ? RenderRazorViewToString(sourceView, cartName == CartHelper.CompareListName ? (object)helper.CreateCompareModel() : helper.CreateCartModel(true)) : "", Source = sourceView, DeleteId = lineItemId, CartName = cartName }; results.Messages.Add(new MessageModel(string.Format("{0} have been removed from your {1}.".Localize(), clear ? "Items " : Server.HtmlEncode(name), cartName))); return(Json(results)); }
/// <summary> /// Creates the cart model. /// </summary> /// <param name="helper">The helper.</param> /// <param name="preloadItems">if set to <c>true</c> [preload items].</param> /// <returns>CartModel.</returns> public static CartModel CreateCartModel(this CartHelper helper, bool preloadItems) { var model = new CartModel(); var cart = helper.Cart; model.SubTotalPriceFormatted = StoreHelper.FormatCurrency(cart.Subtotal, cart.BillingCurrency); model.TotalPriceFormatted = StoreHelper.FormatCurrency(cart.Total, cart.BillingCurrency); model.DiscountTotalPriceFormatted = StoreHelper.FormatCurrency(-cart.DiscountTotal, cart.BillingCurrency); model.ShippingPriceFormatted = StoreHelper.FormatCurrency(cart.ShippingTotal, cart.BillingCurrency); model.TaxTotalPriceFormatted = StoreHelper.FormatCurrency(cart.TaxTotal, cart.BillingCurrency); model.CouponCode = UserHelper.CustomerSession.CouponCode; if (preloadItems) { var ids = helper.LineItems.Select(li => li.CatalogItemId).ToList(); var lineItems = new List <LineItemModel>(); if (ids.Count > 0) { var items = CartHelper.CatalogClient.GetItems(ids.ToArray()); lineItems.AddRange(from li in helper.LineItems let item = (from i in items where i.ItemId.Equals(li.CatalogItemId, StringComparison.OrdinalIgnoreCase) select i).FirstOrDefault() let parentItem = CartHelper.CatalogClient.GetItem(li.ParentCatalogItemId) where item != null select new LineItemModel(li, item, parentItem, helper.Cart.BillingCurrency)); } model.LineItems = lineItems.ToArray(); } return(model); }
/// <summary> /// The resolve value. /// </summary> /// <returns> /// The <see cref="object"/>. /// </returns> public override object ResolveValue() { return(StoreHelper.FormatCurrency(!this.Context.SalePreparation.IsReadyToInvoice() ? this.Context.Basket.TotalBasketPrice : this.Context.SalePreparation.PrepareInvoice().Total)); }