public ShoppingCartJsonResult GetCurrentShoppingCart(IStorefrontContext storefrontContext, IVisitorContext visitorContext) { ShoppingCartJsonResult model = this.ModelProvider.GetModel <ShoppingCartJsonResult>(); try { ManagerResponse <CartResult, Sitecore.Commerce.Entities.Carts.Cart> currentCart = this.CartManager.GetCurrentCart(visitorContext, storefrontContext, true); if (!currentCart.ServiceProviderResult.Success || currentCart.Result == null) { model.Success = false; string systemMessage = storefrontContext.GetSystemMessage("Cart Not Found Error", true); currentCart.ServiceProviderResult.SystemMessages.Add(new SystemMessage() { Message = systemMessage }); model.SetErrors((ServiceProviderResult)currentCart.ServiceProviderResult); } ShoppingCartLinesManager cartManager = new ShoppingCartLinesManager(this.StorefrontContext, this.SearchManager); string shopName = storefrontContext.CurrentStorefront.ShopName; string cartId = $"Default{visitorContext.UserId}" + shopName; dynamic cartLineList = cartManager.GetCurrentCartLines(cartId); model.Initialize(currentCart.Result, cartLineList); } catch (Exception ex) { model.SetErrors(nameof(GetCurrentCart), ex); } return(model); }
public JsonResult GetCurrentCart(string cartID) { ShoppingCartLinesManager cartManager = new ShoppingCartLinesManager(StorefrontContext, _searchManager); string shopName = StorefrontContext.CurrentStorefront.ShopName; string cartId = $"Default{_visitorContext.UserId}" + shopName; dynamic cartModel = cartManager.GetCurrentCartLines(cartId); JsonResult baseJsonResult = this.Json(cartModel); return(this.Json(baseJsonResult)); }
public JsonResult GetCurrentCartLines(string cartID) { JsonResult baseJsonResult; ShoppingCartLinesManager cartManager = new ShoppingCartLinesManager(this.StorefrontContext, this.SearchManager); string shopName = this.StorefrontContext.CurrentStorefront.ShopName; string cartId = $"Default{this.VisitorContext.UserId}" + shopName; dynamic cartModel = cartManager.GetCurrentCartLines(cartId); baseJsonResult = this.Json(cartModel); return(this.Json((object)baseJsonResult)); }