uCommerce CatalogLibrary.CalculatePrice, Money culture and price formatting
Hi! I'm working with uCommerce using razor and have been making use of the handy CatalogLibrary.CalculatePrice method ie.
var product = SiteContext.Current.CatalogContext.CurrentProduct; var price = CatalogLibrary.CalculatePrice(product); <div>Price = @price.YourPrice.AmountExclTax</div>
The YourPrice.AmountExclTax object is a uCommerce Money object. When you call ToString() on it then it nicely renders out the currency symbol (based on the PriceGroup of the current ProductCatalog in the SiteContext) and the amount. So, for instance, if my PriceGroup was GBP and the product price was 159.60 before VAT it would render:
£159.60
This is great and as expected.
The problem I have is that if the PriceGroup is set to, say, Euro and the current culture is en-ES (Spanish) then it will render:
€159.60
However, as far as I understand, the way it should render in Spanish culture is:
€159,60
When I checked the uCommerce Money object that results from a price calculation I found it does have a reference to a .NET Culture object - however, this always seems to be set to the Invariant Culture and not the culture of the current thread as defined in the context. It's read-only, too, so cannot be over-ridden.
Is there any way around this or is this a (small) bug in the way prices are rendered by default? I know I could write my own method for rendering prices, but the convenience of just calling ToString() in razor on the Money object is really nice and it would be a shame not to be able to use it.
okay for everyone else I wrote this for my multi currency solution, in this example on Danish it output DKK 2.995,00
First you have to set System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("da-DK"); to the CurrencyInfo of your choise and then you call
In Germany it's both correct (according to Duden and DIN 5008), you can write the € symbol or "EUR" before or after the amount. But don't forget to insert a space.
uCommerce CatalogLibrary.CalculatePrice, Money culture and price formatting
Hi! I'm working with uCommerce using razor and have been making use of the handy CatalogLibrary.CalculatePrice method ie.
The YourPrice.AmountExclTax object is a uCommerce Money object. When you call ToString() on it then it nicely renders out the currency symbol (based on the PriceGroup of the current ProductCatalog in the SiteContext) and the amount. So, for instance, if my PriceGroup was GBP and the product price was 159.60 before VAT it would render:
This is great and as expected.
The problem I have is that if the PriceGroup is set to, say, Euro and the current culture is en-ES (Spanish) then it will render:
However, as far as I understand, the way it should render in Spanish culture is:
When I checked the uCommerce Money object that results from a price calculation I found it does have a reference to a .NET Culture object - however, this always seems to be set to the Invariant Culture and not the culture of the current thread as defined in the context. It's read-only, too, so cannot be over-ridden.
Is there any way around this or is this a (small) bug in the way prices are rendered by default? I know I could write my own method for rendering prices, but the convenience of just calling ToString() in razor on the Money object is really nice and it would be a shame not to be able to use it.
Did you ever found a solution to this?
I basically had to write my own method for this, didn't find any way around it :(
okay for everyone else I wrote this for my multi currency solution, in this example on Danish it output DKK 2.995,00
First you have to set System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("da-DK"); to the CurrencyInfo of your choise and then you call
@helper FormatPrice(UCommerce.Api.PriceCalculation price) {
NumberFormatInfo LocalFormat = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
LocalFormat.CurrencySymbol = price.YourPrice.AmountInclTax.Currency.ISOCode;
@price.YourPrice.AmountInclTax.Value.ToString("C", LocalFormat);
}
That's cool - would have posted my code, but I don't work at the place where I wrote it any more :)
Would be nice if uCommerce fixed this, though - c'mon guys! :p
It's on the todo list. :)
Any updates on this?
Also it should be 159,60€ (in germany) and not €159,60
In Germany it's both correct (according to Duden and DIN 5008), you can write the € symbol or "EUR" before or after the amount. But don't forget to insert a space.
Hi David and Christian,
This was fixed in version 4.
Kind regards,
Jesper
is working on a reply...