public AddCartItemStatus AddLineItem(string skuId, int quantity, int storeId) { AddCartItemStatus result; if (this.IsExistSkuId(skuId)) { XmlDocument shoppingCartData = this.GetShoppingCartData(); XmlNode xmlNode = shoppingCartData.SelectSingleNode("//sc/lis"); XmlNode xmlNode2 = xmlNode.SelectSingleNode("l[@s='" + skuId + "']"); if (xmlNode2 == null) { xmlNode2 = CookieShoppingDao.CreateLineItemNode(shoppingCartData, skuId, quantity, storeId); xmlNode.InsertBefore(xmlNode2, xmlNode.FirstChild); } else { if (storeId != 0) { xmlNode2.Attributes["q"].Value = (int.Parse(xmlNode2.Attributes["q"].Value) + quantity).ToString(CultureInfo.InvariantCulture); xmlNode2.Attributes["sto"].Value = storeId.ToString(CultureInfo.InvariantCulture); //门店Id使用最新的覆盖 } else { xmlNode2.Attributes["q"].Value = (int.Parse(xmlNode2.Attributes["q"].Value) + quantity).ToString(CultureInfo.InvariantCulture); } } this.SaveShoppingCartData(shoppingCartData); result = AddCartItemStatus.Successed; } else { result = AddCartItemStatus.ProductNotExists; } return(result); }
public bool AddGiftItem(int giftId, int quantity) { XmlDocument shoppingCartData = this.GetShoppingCartData(); XmlNode xmlNode = shoppingCartData.SelectSingleNode("//sc/gf"); XmlNode xmlNode2 = xmlNode.SelectSingleNode("l[@g=" + giftId + "]"); if (xmlNode2 == null) { xmlNode2 = CookieShoppingDao.CreateGiftLineItemNode(shoppingCartData, giftId, quantity); xmlNode.InsertBefore(xmlNode2, xmlNode.FirstChild); } else { xmlNode2.Attributes["q"].Value = (int.Parse(xmlNode2.Attributes["q"].Value) + quantity).ToString(CultureInfo.InvariantCulture); } this.SaveShoppingCartData(shoppingCartData); return(true); }
private XmlDocument GetShoppingCartData() { XmlDocument xmlDocument = new XmlDocument(); HttpCookie httpCookie = HiContext.Current.Context.Request.Cookies["Hid_Ecshop_ShoppingCart_Data_New"]; if (httpCookie == null || string.IsNullOrEmpty(httpCookie.Value)) { xmlDocument = CookieShoppingDao.CreateEmptySchema(); } else { try { xmlDocument.LoadXml(Globals.UrlDecode(httpCookie.Value)); } catch { this.ClearShoppingCart(); xmlDocument = CookieShoppingDao.CreateEmptySchema(); } } return(xmlDocument); }