/// <summary> /// 移除购物车指定项 /// </summary> public static void Clear(List <Model.cart_keys> ls) { if (ls != null) { List <Model.cart_keys> cartList = GetCart(); if (cartList == null) { return; } foreach (Model.cart_keys modelt in ls) { Model.cart_keys model = cartList.Find(p => p.article_id == modelt.article_id && p.goods_id == modelt.goods_id); if (model != null) { cartList.Remove(model); } } string jsonStr = JsonHelper.ObjectToJSON(cartList); AddCookies(jsonStr); } }
/// <summary> /// 移除购物车指定项 /// </summary> public static void Clear(List <Model.cart_keys> ls) { if (ls != null) { List <Model.cart_keys> cartList = GetCart(); if (cartList == null) { return; } foreach (Model.cart_keys modelt in ls) { Model.cart_keys model = cartList.Find(p => p.channel_id == modelt.channel_id && p.article_id == modelt.article_id); if (model != null) { cartList.Remove(model); } } string jsonStr = JSON.Serializer(cartList); AddCookies(jsonStr); } }
/// <summary> /// 更新购物车数量 /// </summary> public static Model.cart_keys Update(int article_id, int goods_id, int quantity) { //如果数量小于1则移除该项 if (quantity < 1) { return(null); } List <Model.cart_keys> ls = GetCart(); if (ls != null) { Model.cart_keys modelt = ls.Find(p => p.article_id == article_id && p.goods_id == goods_id); if (modelt != null) { int i = ls.FindIndex(p => p.article_id == article_id && p.goods_id == goods_id); modelt.quantity = quantity; //更新数量 ls[i] = modelt; string jsonStr = JsonHelper.ObjectToJSON(ls); //转换为JSON字符串 AddCookies(jsonStr); //重新加入Cookies return(modelt); } } return(null); }