/// <summary> /// 购物车 /// </summary> /// <returns></returns> public ActionResult Index() { ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew(); //用于计算会员价: LoginUser userInfo = UserMgr.ReadUserInfo(); shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo; if (shoppingCart != null) { ShoppingStorageManager.SaveShoppingCart(shoppingCart); } OrderPipelineProcessResult shoppingResult = ShoppingFacade.BuildShoppingCart(shoppingCart); ShoppingCart pipelineShoppingCart = (shoppingResult.ReturnData != null && shoppingResult.ReturnData["ShoppingCart"] != null) ? shoppingResult.ReturnData["ShoppingCart"] as ShoppingCart : new ShoppingCart(); shoppingCart.OrderSelectGiftSysNo = pipelineShoppingCart.OrderSelectGiftSysNo; shoppingCart.OrderDeleteGiftSysNo = pipelineShoppingCart.OrderDeleteGiftSysNo; ShoppingStorageManager.SaveShoppingCart(shoppingCart); //将迷你购物车加入Cookie ShoppingStorageManager.SaveShoppingCartMini(ShoppingFacade.BuildMiniShoppingCartFromPipeline(shoppingResult)); return(View(shoppingResult)); }
/// <summary> /// Mini购物车获取商品数量 /// </summary> /// <returns></returns> public JsonResult GetMiniShoppingCartCount() { LoginUser userInfo = UserMgr.ReadUserInfo(); int userSysNo = userInfo == null ? 0 : userInfo.UserSysNo; int totalProductCount = 0; //ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew(); ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartByCustomer(userSysNo); if (shoppingCart == null) { shoppingCart = new ShoppingCart(); } if (shoppingCart != null && shoppingCart.ShoppingItemGroupList != null) { foreach (var itemGroup in shoppingCart.ShoppingItemGroupList) { foreach (var item in itemGroup.ShoppingItemList) { totalProductCount += itemGroup.Quantity * item.UnitQuantity; } } } //ShoppingStorageManager.SaveShoppingCart(shoppingCart); //将迷你购物车加入Cookie OrderPipelineProcessResult shoppingResult = ShoppingFacade.BuildShoppingCart(shoppingCart); ShoppingStorageManager.SaveShoppingCartMini(ShoppingFacade.BuildMiniShoppingCartFromPipeline(shoppingResult)); return(new JsonResult() { Data = totalProductCount }); }
/// <summary> /// Mini购物车删除商品 /// </summary> /// <returns></returns> public PartialViewResult DelMiniShoppingCartProduct() { #region Check bool checkResult = true; int packageSysNo = 0; int productSysNo = 0; if (!int.TryParse(Request.Params["PackageSysNo"], out packageSysNo)) { checkResult = false; } else if (!int.TryParse(Request.Params["ProductSysNo"], out productSysNo)) { checkResult = false; } #endregion ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew(); if (checkResult) { if (packageSysNo.Equals(0)) { //删除单个商品 shoppingCart = DelProductCalcShoppingCart(shoppingCart, productSysNo); } else { //删除套餐中的商品 shoppingCart = DelPackageProductCalcShoppingCart(shoppingCart, packageSysNo, productSysNo); } } OrderPipelineProcessResult pipelineShoppingResult = null; ShoppingCartMiniResult shoppingResult = ShoppingFacade.BuildMiniShoppingCart(shoppingCart, out pipelineShoppingResult); ShoppingCart pipelineShoppingCart = (pipelineShoppingResult.ReturnData != null && pipelineShoppingResult.ReturnData["ShoppingCart"] != null) ? pipelineShoppingResult.ReturnData["ShoppingCart"] as ShoppingCart : new ShoppingCart(); shoppingCart.OrderSelectGiftSysNo = pipelineShoppingCart.OrderSelectGiftSysNo; shoppingCart.OrderDeleteGiftSysNo = pipelineShoppingCart.OrderDeleteGiftSysNo; //Key添加CustomerSysNo LoginUser userInfo = UserMgr.ReadUserInfo(); shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo; ShoppingStorageManager.SaveShoppingCart(shoppingCart); //将迷你购物车加入Cookie ShoppingStorageManager.SaveShoppingCartMini(ShoppingFacade.BuildMiniShoppingCartFromPipeline(pipelineShoppingResult)); return(PartialView("_ShoppingCartMini", shoppingResult)); }
/// <summary> /// 获取Mini购物车 /// </summary> /// <returns></returns> public PartialViewResult GetMiniShoppingCart() { //ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew(); //ShoppingCartMiniResult shoppingResult = ShoppingStorageManager.GetShoppingCartMiniFromCookie(); //ShoppingStorageManager.SaveShoppingCart(shoppingCart); ////将迷你购物车加入Cookie //ShoppingStorageManager.SaveShoppingCartMini(ShoppingStorageManager.GetShoppingCartMiniFromCookie()); LoginUser userInfo = UserMgr.ReadUserInfo(); int userSysNo = userInfo == null ? 0 : userInfo.UserSysNo; ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartByCustomer(userSysNo); if (shoppingCart == null) { shoppingCart = new ShoppingCart(); } ShoppingCartMiniResult shoppingResult = ShoppingFacade.BuildMiniShoppingCartFromPipeline(ShoppingFacade.BuildShoppingCart(shoppingCart)); //ShoppingStorageManager.SaveShoppingCart(shoppingCart); //将迷你购物车加入Cookie ShoppingStorageManager.SaveShoppingCartMini(shoppingResult); return(PartialView("_ShoppingCartMini", shoppingResult)); }
/// <summary> /// 加载购物车信息 /// </summary> /// <returns>购物车信息</returns> private PartialViewResult LoadShoppingCartData(ShoppingCart shoppingCart, string errorMessage = "", string PackageTypeSingleList = "", string PackageTypeGroupList = "") { foreach (var itemGroup in shoppingCart.ShoppingItemGroupList) { itemGroup.PackageChecked = false; foreach (ShoppingItem ProductItem in itemGroup.ShoppingItemList) { ProductItem.ProductChecked = false; } } //checkbox单个商品购买 if (!string.IsNullOrEmpty(PackageTypeSingleList)) { string[] array = PackageTypeSingleList.Split(','); foreach (var item in array) { int sysNo = 0; if (int.TryParse(item, out sysNo)) { foreach (var itemGroup in shoppingCart.ShoppingItemGroupList) { if (itemGroup.PackageType.Equals(0)) { if (!itemGroup.PackageChecked) { foreach (ShoppingItem ProductItem in itemGroup.ShoppingItemList) { if (ProductItem.ProductSysNo == sysNo && !ProductItem.ProductChecked) { itemGroup.PackageChecked = true; ProductItem.ProductChecked = true; } } } } } } } } //checkbox套餐商品购买 if (!string.IsNullOrEmpty(PackageTypeGroupList)) { string[] array = PackageTypeGroupList.Split(','); foreach (var item in array) { int sysNo = 0; if (int.TryParse(item, out sysNo)) { foreach (var itemGroup in shoppingCart.ShoppingItemGroupList) { if (itemGroup.PackageType.Equals(1)) { if (!itemGroup.PackageChecked) { if (itemGroup.PackageNo == sysNo) { itemGroup.PackageChecked = true; } } } } } } } //用于计算会员价: LoginUser userInfo = UserMgr.ReadUserInfo(); shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo; OrderPipelineProcessResult shoppingResult = ShoppingFacade.BuildShoppingCart(shoppingCart); ShoppingCart pipelineShoppingCart = (shoppingResult.ReturnData != null && shoppingResult.ReturnData["ShoppingCart"] != null) ? shoppingResult.ReturnData["ShoppingCart"] as ShoppingCart : new ShoppingCart(); shoppingCart.OrderSelectGiftSysNo = pipelineShoppingCart.OrderSelectGiftSysNo; shoppingCart.OrderDeleteGiftSysNo = pipelineShoppingCart.OrderDeleteGiftSysNo; ////checkbox单个商品购买 //if (!string.IsNullOrEmpty(PackageTypeSingleList)) //{ // string[] array = PackageTypeSingleList.Split(','); // foreach (var item in array) // { // int sysNo = 0; // if (int.TryParse(item, out sysNo)) // { // foreach (var itemGroup in shoppingResult.ReturnData.OrderItemGroupList) // { // if (itemGroup.PackageType.Equals(0)) // { // foreach (OrderProductItem ProductItem in itemGroup.ProductItemList) // { // if (ProductItem.ProductSysNo == sysNo && ProductItem.ProductChecked == false) // { // itemGroup.PackageChecked = true; // ProductItem.ProductChecked = true; // } // } // } // } // } // } //} ////checkbox套餐商品购买 //if (!string.IsNullOrEmpty(PackageTypeGroupList)) //{ // string[] array = PackageTypeGroupList.Split(','); // foreach (var item in array) // { // int sysNo = 0; // if (int.TryParse(item, out sysNo)) // { // foreach (var itemGroup in shoppingResult.ReturnData.OrderItemGroupList) // { // if (itemGroup.PackageType.Equals(1)) // { // if (itemGroup.PackageNo == sysNo && itemGroup.PackageChecked == false) // { // itemGroup.PackageChecked = true; // } // } // } // } // } //} ShoppingStorageManager.SaveShoppingCart(shoppingCart); //将迷你购物车加入Cookie ShoppingStorageManager.SaveShoppingCartMini(ShoppingFacade.BuildMiniShoppingCartFromPipeline(shoppingResult)); if (!string.IsNullOrWhiteSpace(errorMessage)) { //更改失败返回错误信息 if (shoppingResult.ErrorMessages != null) { shoppingResult.ErrorMessages = new List <string>() { errorMessage }; } else { shoppingResult.ErrorMessages.Add(errorMessage); } } return(PartialView("_ShoppingCartPanel", shoppingResult)); }
public JsonResult AjaxSubmitCheckout(CheckOutContext context) { if (context == null) { return(Json(BuildAjaxErrorObject("无效的请求"))); } ShoppingCart shoppingCart = ShoppingStorageManager.GetShoppingCartFromCreateNew(); ShoppingCart shoppingCartNew = ShoppingStorageManager.GetShoppingCartFromCreateNew(); //优先从购买商品参数来构建购物车对象 if (!String.IsNullOrWhiteSpace(context.ShoppingItemParam)) { String[] shoppingItemParams = context.ShoppingItemParam.Split(new char[] { '|' }); if (shoppingItemParams.Length == 2) { shoppingCartNew = ShoppingStorageManager.GetShoppingCartFromParam(shoppingItemParams[0], shoppingItemParams[1]); } } //其次从cookie中来构建购物车对象 if (ShoppingCartIsEmpty(shoppingCartNew)) { shoppingCart = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew(); ShoppingItemGroup ShoppingItem = new ShoppingItemGroup(); if (!string.IsNullOrEmpty(context.PackageTypeGroupList)) { string[] array = context.PackageTypeGroupList.Split(','); foreach (var item in array) { int sysNo = 0; if (int.TryParse(item, out sysNo)) { ShoppingItem = shoppingCart.ShoppingItemGroupList.FindAll(m => (m.PackageType.Equals(1) && m.PackageNo.Equals(sysNo)))[0]; shoppingCartNew.ShoppingItemGroupList.Add(ShoppingItem); } } } if (!string.IsNullOrEmpty(context.PackageTypeSingleList)) { string[] array = context.PackageTypeSingleList.Split(','); foreach (var item in array) { int sysNo = 0; if (int.TryParse(item, out sysNo)) { ShoppingItem = shoppingCart.ShoppingItemGroupList.FindAll(m => (m.PackageType.Equals(0) && m.ShoppingItemList[0].ProductSysNo.Equals(sysNo)))[0]; shoppingCartNew.ShoppingItemGroupList.Add(ShoppingItem); } } } } if (ShoppingCartIsEmpty(shoppingCartNew)) { return(Json(new { url = PageHelper.BuildUrl("ShoppingCartRoute") })); } shoppingCartNew.OrderDeleteGiftSysNo = shoppingCart.OrderDeleteGiftSysNo; shoppingCartNew.OrderSelectGiftSysNo = shoppingCart.OrderSelectGiftSysNo; CheckOutResult result = ShoppingFacade.SubmitCheckout(context, shoppingCartNew, CurrUser.UserSysNo, SOSource.None); if (result.HasSucceed) { //取得订单编号列表 List <int> soSysNoList = result.OrderProcessResult.ReturnData.SubOrderList.Select(subOrder => subOrder.Value.ID).ToList(); ShoppingStorageManager.SaveLatestSO(soSysNoList); //团购订单数据不是来自cookie,不能清除cookie if (!result.OrderProcessResult.ReturnData.SubOrderList.Any(x => x.Value.SOType == (int)SOType.GroupBuy || x.Value.SOType == (int)SOType.VirualGroupBuy)) { //ShoppingStorageManager.RemoveShoppingCartCookie(); //移除mini购物车 //ShoppingStorageManager.RemoveShoppingCartMiniCookie(); //删除套餐 if (!string.IsNullOrEmpty(context.PackageTypeGroupList)) { string[] array = context.PackageTypeGroupList.Split(','); foreach (var item in array) { int sysNo = 0; if (int.TryParse(item, out sysNo)) { shoppingCart.ShoppingItemGroupList = shoppingCart.ShoppingItemGroupList.FindAll(m => (m.PackageType.Equals(1) && !m.PackageNo.Equals(sysNo)) || m.PackageType.Equals(0)); } } } //删除单个商品 if (!string.IsNullOrEmpty(context.PackageTypeSingleList)) { string[] array = context.PackageTypeSingleList.Split(','); foreach (var item in array) { int sysNo = 0; if (int.TryParse(item, out sysNo)) { shoppingCart.ShoppingItemGroupList = shoppingCart.ShoppingItemGroupList.FindAll(m => (m.PackageType.Equals(0) && !m.ShoppingItemList[0].ProductSysNo.Equals(sysNo)) || m.PackageType.Equals(1)); } } } //用于计算会员价: LoginUser userInfo = UserMgr.ReadUserInfo(); shoppingCart.CustomerSysNo = userInfo == null ? 0 : userInfo.UserSysNo; OrderPipelineProcessResult shoppingResult = ShoppingFacade.BuildShoppingCart(shoppingCart); ShoppingCart pipelineShoppingCart = (shoppingResult.ReturnData != null && shoppingResult.ReturnData["ShoppingCart"] != null) ? shoppingResult.ReturnData["ShoppingCart"] as ShoppingCart : new ShoppingCart(); shoppingCart.OrderSelectGiftSysNo = pipelineShoppingCart.OrderSelectGiftSysNo; shoppingCart.OrderDeleteGiftSysNo = pipelineShoppingCart.OrderDeleteGiftSysNo; ShoppingStorageManager.SaveShoppingCart(shoppingCart); //将迷你购物车加入Cookie ShoppingStorageManager.SaveShoppingCartMini(ShoppingFacade.BuildMiniShoppingCartFromPipeline(shoppingResult)); } return(Json(new { url = PageHelper.BuildUrl("Thankyou", result.OrderProcessResult.ReturnData.ShoppingCartID) })); } return(Json(new { errors = result.ErrorMessages })); }