/// <summary> /// Get checkout attribute values /// </summary> /// <param name="attributes">Attributes</param> /// <returns>Checkout attribute values</returns> public static List <CheckoutAttributeValue> ParseCheckoutAttributeValues(string attributes) { var caValues = new List <CheckoutAttributeValue>(); var caCollection = ParseCheckoutAttributes(attributes); foreach (var ca in caCollection) { if (!ca.ShouldHaveValues) { continue; } var caValuesStr = ParseValues(attributes, ca.CheckoutAttributeId); foreach (string caValueStr in caValuesStr) { if (!String.IsNullOrEmpty(caValueStr)) { int caValueId = 0; if (int.TryParse(caValueStr, out caValueId)) { var caValue = CheckoutAttributeManager.GetCheckoutAttributeValueById(caValueId); if (caValue != null) { caValues.Add(caValue); } } } } } return(caValues); }
/// <summary> /// Gets selected checkout attributes /// </summary> /// <param name="attributes">Attributes</param> /// <returns>Selected checkout attributes</returns> public static List <CheckoutAttribute> ParseCheckoutAttributes(string attributes) { var caCollection = new List <CheckoutAttribute>(); var Ids = ParseCheckoutAttributeIds(attributes); foreach (int id in Ids) { var ca = CheckoutAttributeManager.GetCheckoutAttributeById(id); if (ca != null) { caCollection.Add(ca); } } return(caCollection); }
/// <summary> /// Gets the localized name /// </summary> /// <param name="languageId">Language identifier</param> /// <returns>Localized name</returns> public string GetLocalizedName(int languageId) { if (NopContext.Current.LocalizedEntityPropertiesEnabled) { if (languageId > 0) { if (_cavLocalized == null) { _cavLocalized = CheckoutAttributeManager.GetCheckoutAttributeValueLocalizedByCheckoutAttributeValueId(this.CheckoutAttributeValueId); } var temp1 = _cavLocalized.FirstOrDefault(cavl => cavl.LanguageId == languageId); if (temp1 != null && !String.IsNullOrWhiteSpace(temp1.Name)) { return(temp1.Name); } } } return(this.Name); }
/// <summary> /// Formats attributes /// </summary> /// <param name="attributes">Attributes</param> /// <param name="customer">Customer</param> /// <param name="serapator">Serapator</param> /// <param name="htmlEncode">A value indicating whether to encode (HTML) values</param> /// <param name="renderPrices">A value indicating whether to render prices</param> /// <returns>Attributes</returns> public static string FormatAttributes(string attributes, Customer customer, string serapator, bool htmlEncode, bool renderPrices) { var result = new StringBuilder(); var caCollection = ParseCheckoutAttributes(attributes); for (int i = 0; i < caCollection.Count; i++) { var ca = caCollection[i]; var valuesStr = ParseValues(attributes, ca.CheckoutAttributeId); for (int j = 0; j < valuesStr.Count; j++) { string valueStr = valuesStr[j]; string caAttribute = string.Empty; if (!ca.ShouldHaveValues) { if (ca.AttributeControlType == AttributeControlTypeEnum.MultilineTextbox) { caAttribute = string.Format("{0}: {1}", ca.LocalizedName, HtmlHelper.FormatText(valueStr, false, true, true, false, false, false)); } else { caAttribute = string.Format("{0}: {1}", ca.LocalizedName, valueStr); } } else { var caValue = CheckoutAttributeManager.GetCheckoutAttributeValueById(Convert.ToInt32(valueStr)); if (caValue != null) { caAttribute = string.Format("{0}: {1}", ca.LocalizedName, caValue.LocalizedName); if (renderPrices) { decimal priceAdjustmentBase = TaxManager.GetCheckoutAttributePrice(caValue, customer); decimal priceAdjustment = CurrencyManager.ConvertCurrency(priceAdjustmentBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency); if (priceAdjustmentBase > 0) { string priceAdjustmentStr = PriceHelper.FormatPrice(priceAdjustment); caAttribute += string.Format(" [+{0}]", priceAdjustmentStr); } } } } if (!String.IsNullOrEmpty(caAttribute)) { if (i != 0 || j != 0) { result.Append(serapator); } //we don't encode multiline textbox input if (htmlEncode && ca.AttributeControlType != AttributeControlTypeEnum.MultilineTextbox) { result.Append(HttpUtility.HtmlEncode(caAttribute)); } else { result.Append(caAttribute); } } } } return(result.ToString()); }