Exemple #1
0
        /// <summary>
        /// Turns a decimal value into a currency string
        /// </summary>
        /// <param name="currency">The decimal object to act on</param>
        /// <param name="currencyCode">The currency code.</param>
        /// <returns>
        /// A decimal formatted as a string
        /// </returns>
        public static string ToCurrency(this decimal currency, string currencyCode)
        {
            CurrencyInformationModel currencyInfo = StorefrontManager.GetCurrencyInformation(currencyCode);

            NumberFormatInfo info = (NumberFormatInfo)CultureInfo.GetCultureInfo(currencyInfo.CurrencyNumberFormatCulture).NumberFormat.Clone();

            info.CurrencySymbol          = currencyInfo != null ? currencyInfo.Symbol : currencyCode;
            info.CurrencyPositivePattern = currencyInfo.SymbolPosition;
            return(currency.ToString("C", info));
        }
Exemple #2
0
        /// <summary>
        /// Turns a decimal value into a currency string
        /// </summary>
        /// <param name="currency">The decimal object to act on</param>
        /// <param name="currencyCode">The currency code.</param>
        /// <returns>
        /// A decimal formatted as a string
        /// </returns>
        public static string ToCurrency(this decimal currency, string currencyCode)
        {
            NumberFormatInfo         info;
            CurrencyInformationModel currencyInfo = StorefrontManager.GetCurrencyInformation(currencyCode);

            if (currencyInfo != null)
            {
                info = (NumberFormatInfo)CultureInfo.GetCultureInfo(currencyInfo.CurrencyNumberFormatCulture).NumberFormat.Clone();
                info.CurrencySymbol          = currencyInfo != null ? currencyInfo.Symbol : currencyCode;
                info.CurrencyPositivePattern = currencyInfo.SymbolPosition;
            }
            else
            {
                info = (NumberFormatInfo)CultureInfo.GetCultureInfo(Sitecore.Context.Language.Name).NumberFormat.Clone();
            }

            return(currency.ToString("C", info));
        }
Exemple #3
0
        /// <summary>
        /// Initializes the specified rendering.
        /// </summary>
        /// <param name="rendering">The rendering.</param>
        /// <param name="result">The result.</param>
        public void Initialize(Rendering rendering, GetSupportedCurrenciesResult result)
        {
            if (!result.Success || result.Currencies == null)
            {
                return;
            }

            List <string> supportedCurrencies = StorefrontManager.CurrentStorefront.SupportedCurrencies;

            var currencies = supportedCurrencies.Intersect(result.Currencies);

            foreach (string currency in currencies)
            {
                var currencyInfoModel = StorefrontManager.GetCurrencyInformation(currency);
                if (currencyInfoModel != null)
                {
                    this._currencyList.Add(currencyInfoModel);
                }
            }
        }