//根据传参将商品加入购物车后跳转(支持按商品ID,套装ID购买) private void AddToCart(M_UserInfo mu, M_Product proMod, int pronum) { if (pronum < 1) { pronum = 1; } if (proMod == null || proMod.ID < 1) { return; } //商品不存在 DataTable dt = DBCenter.Sel(proMod.TableName, "ID=" + proMod.ItemID); int tlpID = DataConvert.CLng(dt.Rows[0]["TlpID"]); //if (tlpID < 1) { function.WriteErrMsg("商品未绑定设计模板"); } //复制一份作为用户新建的记录 B_Logo_Design desBll = new B_Logo_Design(); M_Logo_Design desMod = desBll.SelReturnModel(tlpID); if (desMod == null) { desMod = new M_Logo_Design(); } M_Cart_Addition addMod = new M_Cart_Addition(); //if (desMod == null) { function.WriteErrMsg("商品未绑定模板"); } desMod.ID = 0; desMod.ZType = 0; desMod.CDate = DateTime.Now; desMod.UserID = mu.UserID; desMod.UserName = mu.UserName; //不经设计直接加入物车,则获取商品预览图片 string imgUrl = function.GetImgUrl(proMod.Thumbnails); //if (File.Exists(function.VToP(imgUrl))) //{ // desMod.PreviewImg = "data:image/png;base64," + ImgToBase64(imgUrl); //} desMod.PreviewImg = imgUrl; desMod.ID = desBll.Insert(desMod); //-----------------检测完成加入购物车 M_Cart cartMod = new M_Cart(); cartMod.Cartid = CartCookID; cartMod.StoreID = proMod.UserShopID; cartMod.ProID = proMod.ID; cartMod.Pronum = pronum; cartMod.userid = mu.UserID; cartMod.Username = mu.UserName; cartMod.FarePrice = proMod.LinPrice.ToString(); cartMod.AllMoney = (proMod.LinPrice * cartMod.Pronum); cartMod.ProAttr = desMod.ID.ToString(); cartMod.Proname = proMod.Proname; cartMod.Additional = JsonConvert.SerializeObject(addMod); int id = cartBll.insert(cartMod); }
//public M_Product proMod = null; protected void Page_Load(object sender, EventArgs e) { item = (DataRowView)PageHelper.Aspx_GetModel(Request); //proMod = new B_Product().GetproductByid(DataConvert.CLng(item["ProID"])); addMod = JsonConvert.DeserializeObject <M_Cart_Addition>(item["Additional"].ToString()); if (addMod == null) { addMod = new M_Cart_Addition(); } //Additional {"age":"","weight":"","type":""} }
private void CreateCart(M_Logo_Design desMod) { M_UserInfo mu = SnsHelper.GetLogin(); M_Product mainProMod = proBll.GetproductByid(ProID); DataTable proInfo = DBCenter.Sel(mainProMod.TableName, "ID=" + mainProMod.ItemID); //-----购物车记录(按收前台各种传值) M_Cart cartMod = NewCart(mu, mainProMod); cartMod.ProAttr = desMod.ID.ToString();//存储设计好的信息ID M_Cart_Addition addMod = new M_Cart_Addition(); addMod.flash = DataConvert.CLng(Request.Form["Flash_DP"]); addMod.outdoor = DataConvert.CLng(Request.Form["OutdoorSign_DP"]); addMod.backing = DataConvert.CLng(Request.Form["Request"]); addMod.text = Request.QueryString["texts"]; addMod.size = proInfo.Rows[0]["size"].ToString(); cartMod.Additional = JsonConvert.SerializeObject(addMod); if (addMod.flash > 0) { M_Product proMod = proBll.GetproductByid(addMod.flash); cartMod.AllMoney += proMod.LinPrice; } if (addMod.outdoor > 0) { M_Product proMod = proBll.GetproductByid(addMod.outdoor); cartMod.AllMoney += proMod.LinPrice; } if (addMod.backing > 0) { M_Product proMod = proBll.GetproductByid(addMod.backing); cartMod.AllMoney += proMod.LinPrice; } cartMod.FarePrice = cartMod.AllMoney.ToString("F2"); cartBll.Add(cartMod); Response.Redirect("/Cart/Cart.aspx?ProClass=1"); }