Skip to content

Commit 2eef27f

Browse files
committed
Price formatting: the DisplayLocale's FormatProvider was not applied when CustomFormatting was specified for Currency
1 parent b1dd466 commit 2eef27f

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
###Improvements###
66
* UI: TabStrips remember their last selected tab across page requests in an unobtrusive way (removed old selection code)
77
* TinyMCE 4: activated spell checking, added FontSelect and FontSizeSelect tools to the toolbar
8+
* Price formatting: the DisplayLocale's FormatProvider was not applied when _CustomFormatting_ was specified for Currency
9+
* Admin: Specification attributes are now sorted by DisplayOrder, THEN BY Name
810
* (Developer) MVC filter attributes are now Autofac injectable
911
* (Developer) Implemented _RunSync_ extension methods for _Func<Task>_ and _Func<Task<T>>_. A reliable way to execute async operations synchronously.
1012
* (Developer) Refactored model creation for category navigation: it now incorporates _TreeNode<MenuItem>_, which enables plugin developers to alter the main menu with the event hook _NavigationModelBuilt_.
13+
* (Developer) Added _user.less_ to Alpha theme for user defined css overrides and tweaks
1114
* #384 Web API: Inserting sluged recources like products require an URL record
1215

1316
###Bugfixes###

src/Libraries/SmartStore.Data/Setup/SeedData/InvariantSeedData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public IList<Currency> Currencies()
271271
CreateCurrency("en-AU", published: true, rate: 0.94M, order: 10),
272272
CreateCurrency("en-CA", published: true, rate: 0.98M, order: 15),
273273
CreateCurrency("de-DE", rate: 0.79M, order: 20/*, formatting: string.Format("0.00 {0}", "\u20ac")*/),
274-
CreateCurrency("de-CH", rate: 0.93M, order: 25),
274+
CreateCurrency("de-CH", rate: 0.93M, order: 25, formatting: "CHF #,##0.00"),
275275
CreateCurrency("zh-CN", rate: 6.48M, order: 30),
276276
CreateCurrency("zh-HK", rate: 7.75M, order: 35),
277277
CreateCurrency("ja-JP", rate: 80.07M, order: 40),

src/Libraries/SmartStore.Services/Catalog/PriceFormatter.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,35 @@ protected string GetCurrencyString(decimal amount)
5151
/// <param name="showCurrency">A value indicating whether to show a currency</param>
5252
/// <param name="targetCurrency">Target currency</param>
5353
/// <returns>Currency string without exchange rate</returns>
54-
protected string GetCurrencyString(decimal amount,
55-
bool showCurrency, Currency targetCurrency)
54+
protected string GetCurrencyString(decimal amount, bool showCurrency, Currency targetCurrency)
5655
{
5756
string result = string.Empty;
58-
if (!String.IsNullOrEmpty(targetCurrency.CustomFormatting))
57+
58+
IFormatProvider fmt = NumberFormatInfo.CurrentInfo;
59+
try
60+
{
61+
fmt = CultureInfo.CreateSpecificCulture(targetCurrency.DisplayLocale);
62+
}
63+
catch { }
64+
65+
66+
if (targetCurrency.CustomFormatting.HasValue())
5967
{
60-
result = amount.ToString(targetCurrency.CustomFormatting);
68+
result = amount.ToString(targetCurrency.CustomFormatting, fmt);
6169
}
6270
else
6371
{
64-
if (!String.IsNullOrEmpty(targetCurrency.DisplayLocale))
72+
if (targetCurrency.DisplayLocale.HasValue())
6573
{
66-
result = amount.ToString("C", new CultureInfo(targetCurrency.DisplayLocale));
74+
result = amount.ToString("C", fmt);
6775
}
6876
else
6977
{
70-
result = String.Format("{0} ({1})", amount.ToString("N"), targetCurrency.CurrencyCode);
78+
result = String.Format("{0} {1}", amount.ToString("N"), showCurrency ? targetCurrency.CurrencyCode : "").TrimEnd();
7179
return result;
7280
}
7381
}
7482

75-
// codehint: sm-edit (commented, refactor later)
76-
/*if (showCurrency && _currencyService.GetAllCurrencies().Count > 1)
77-
result = String.Format("{0} ({1})", result, targetCurrency.CurrencyCode);*/
7883
return result;
7984
}
8085

0 commit comments

Comments
 (0)