コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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());
        }