/// <summary> /// Adds an attribute /// </summary> /// <param name="attributes">Attributes</param> /// <param name="ca">Checkout attribute</param> /// <param name="value">Value</param> /// <returns>Attributes</returns> public static string AddCheckoutAttribute(string attributes, CheckoutAttribute ca, string value) { string result = string.Empty; try { XmlDocument xmlDoc = new XmlDocument(); if (String.IsNullOrEmpty(attributes)) { XmlElement _element1 = xmlDoc.CreateElement("Attributes"); xmlDoc.AppendChild(_element1); } else { xmlDoc.LoadXml(attributes); } XmlElement rootElement = (XmlElement)xmlDoc.SelectSingleNode(@"//Attributes"); XmlElement caElement = null; //find existing XmlNodeList nodeList1 = xmlDoc.SelectNodes(@"//Attributes/CheckoutAttribute"); foreach (XmlNode node1 in nodeList1) { if (node1.Attributes != null && node1.Attributes["ID"] != null) { string str1 = node1.Attributes["ID"].InnerText.Trim(); int id = 0; if (int.TryParse(str1, out id)) { if (id == ca.CheckoutAttributeId) { caElement = (XmlElement)node1; break; } } } } //create new one if not found if (caElement == null) { caElement = xmlDoc.CreateElement("CheckoutAttribute"); caElement.SetAttribute("ID", ca.CheckoutAttributeId.ToString()); rootElement.AppendChild(caElement); } XmlElement cavElement = xmlDoc.CreateElement("CheckoutAttributeValue"); caElement.AppendChild(cavElement); XmlElement cavVElement = xmlDoc.CreateElement("Value"); cavVElement.InnerText = value; cavElement.AppendChild(cavVElement); result = xmlDoc.OuterXml; } catch (Exception exc) { Debug.Write(exc.ToString()); } return result; }
private static CheckoutAttribute DBMapping(DBCheckoutAttribute dbItem) { if (dbItem == null) { return(null); } var item = new CheckoutAttribute(); item.CheckoutAttributeId = dbItem.CheckoutAttributeId; item.Name = dbItem.Name; item.TextPrompt = dbItem.TextPrompt; item.IsRequired = dbItem.IsRequired; item.ShippableProductRequired = dbItem.ShippableProductRequired; item.IsTaxExempt = dbItem.IsTaxExempt; item.TaxCategoryId = dbItem.TaxCategoryId; item.AttributeControlTypeId = dbItem.AttributeControlTypeId; item.DisplayOrder = dbItem.DisplayOrder; return(item); }
/// <summary> /// Inserts a checkout attribute /// </summary> /// <param name="checkoutAttribute">Checkout attribute</param> public void InsertCheckoutAttribute(CheckoutAttribute checkoutAttribute) { if (checkoutAttribute == null) { throw new ArgumentNullException("checkoutAttribute"); } checkoutAttribute.Name = CommonHelper.EnsureNotNull(checkoutAttribute.Name); checkoutAttribute.Name = CommonHelper.EnsureMaximumLength(checkoutAttribute.Name, 100); checkoutAttribute.TextPrompt = CommonHelper.EnsureNotNull(checkoutAttribute.TextPrompt); checkoutAttribute.TextPrompt = CommonHelper.EnsureMaximumLength(checkoutAttribute.TextPrompt, 300); _context.CheckoutAttributes.AddObject(checkoutAttribute); _context.SaveChanges(); if (this.CacheEnabled) { _cacheManager.RemoveByPattern(CHECKOUTATTRIBUTES_PATTERN_KEY); _cacheManager.RemoveByPattern(CHECKOUTATTRIBUTEVALUES_PATTERN_KEY); } }
public CheckoutAttribute SaveInfo() { string name = txtName.Text; string textPrompt = txtTextPrompt.Text; int taxCategoryId = int.Parse(this.ddlTaxCategory.SelectedItem.Value); bool isRequired = cbAttributeRequired.Checked; bool shippableProductRequired = cbShippableProductRequired.Checked; bool isTaxExempt = cbIsTaxExempt.Checked; int attributeControlTypeId = int.Parse(this.ddlAttributeControlType.SelectedItem.Value); int displayOrder = txtDisplayOrder.Value; var checkoutAttribute = this.CheckoutAttributeService.GetCheckoutAttributeById(this.CheckoutAttributeId); if (checkoutAttribute != null) { checkoutAttribute.Name = name; checkoutAttribute.TextPrompt = textPrompt; checkoutAttribute.IsRequired = isRequired; checkoutAttribute.ShippableProductRequired = shippableProductRequired; checkoutAttribute.IsTaxExempt = isTaxExempt; checkoutAttribute.TaxCategoryId = taxCategoryId; checkoutAttribute.AttributeControlTypeId = attributeControlTypeId; checkoutAttribute.DisplayOrder = displayOrder; this.CheckoutAttributeService.UpdateCheckoutAttribute(checkoutAttribute); } else { checkoutAttribute = new CheckoutAttribute() { Name = name, TextPrompt = textPrompt, IsRequired = isRequired, ShippableProductRequired = shippableProductRequired, IsTaxExempt = isTaxExempt, TaxCategoryId = taxCategoryId, AttributeControlTypeId = attributeControlTypeId, DisplayOrder = displayOrder }; this.CheckoutAttributeService.InsertCheckoutAttribute(checkoutAttribute); } SaveLocalizableContent(checkoutAttribute); return checkoutAttribute; }
protected void SaveLocalizableContent(CheckoutAttribute checkoutAttribute) { if (checkoutAttribute == null) return; if (!this.HasLocalizableContent) return; foreach (RepeaterItem item in rptrLanguageDivs.Items) { if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) { var txtLocalizedName = (TextBox)item.FindControl("txtLocalizedName"); var txtLocalizedTextPrompt = (TextBox)item.FindControl("txtLocalizedTextPrompt"); var lblLanguageId = (Label)item.FindControl("lblLanguageId"); int languageId = int.Parse(lblLanguageId.Text); string name = txtLocalizedName.Text; string textPrompt = txtLocalizedTextPrompt.Text; bool allFieldsAreEmpty = (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(textPrompt)); var content = this.CheckoutAttributeService.GetCheckoutAttributeLocalizedByCheckoutAttributeIdAndLanguageId(checkoutAttribute.CheckoutAttributeId, languageId); if (content == null) { if (!allFieldsAreEmpty && languageId > 0) { //only insert if one of the fields are filled out (avoid too many empty records in db...) content = new CheckoutAttributeLocalized() { CheckoutAttributeId = checkoutAttribute.CheckoutAttributeId, LanguageId = languageId, Name = name, TextPrompt = textPrompt }; this.CheckoutAttributeService.InsertCheckoutAttributeLocalized(content); } } else { if (languageId > 0) { content.LanguageId= languageId; content.Name= name; content.TextPrompt= textPrompt; this.CheckoutAttributeService.UpdateCheckoutAttributeLocalized(content); } } } } }
/// <summary> /// Adds an attribute /// </summary> /// <param name="attributes">Attributes</param> /// <param name="ca">Checkout attribute</param> /// <param name="value">Value</param> /// <returns>Attributes</returns> public static string AddCheckoutAttribute(string attributes, CheckoutAttribute ca, string value) { string result = string.Empty; try { XmlDocument xmlDoc = new XmlDocument(); if (String.IsNullOrEmpty(attributes)) { XmlElement _element1 = xmlDoc.CreateElement("Attributes"); xmlDoc.AppendChild(_element1); } else { xmlDoc.LoadXml(attributes); } XmlElement rootElement = (XmlElement)xmlDoc.SelectSingleNode(@"//Attributes"); XmlElement caElement = null; //find existing XmlNodeList nodeList1 = xmlDoc.SelectNodes(@"//Attributes/CheckoutAttribute"); foreach (XmlNode node1 in nodeList1) { if (node1.Attributes != null && node1.Attributes["ID"] != null) { string str1 = node1.Attributes["ID"].InnerText.Trim(); int id = 0; if (int.TryParse(str1, out id)) { if (id == ca.CheckoutAttributeId) { caElement = (XmlElement)node1; break; } } } } //create new one if not found if (caElement == null) { caElement = xmlDoc.CreateElement("CheckoutAttribute"); caElement.SetAttribute("ID", ca.CheckoutAttributeId.ToString()); rootElement.AppendChild(caElement); } XmlElement cavElement = xmlDoc.CreateElement("CheckoutAttributeValue"); caElement.AppendChild(cavElement); XmlElement cavVElement = xmlDoc.CreateElement("Value"); cavVElement.InnerText = value; cavElement.AppendChild(cavVElement); result = xmlDoc.OuterXml; } catch (Exception exc) { Debug.Write(exc.ToString()); } return(result); }