Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jan 22, 2013 @ 12:06
    Dan Diplo
    0

    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.

     

  • Kim Søjborg Pedersen 71 posts 275 karma points
    Jun 06, 2013 @ 11:07
    Kim Søjborg Pedersen
    0

    Did you ever found a solution to this?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 06, 2013 @ 12:43
    Dan Diplo
    0

    I basically had to write my own method for this, didn't find any way around it :(

  • Kim Søjborg Pedersen 71 posts 275 karma points
    Jun 06, 2013 @ 12:57
    Kim Søjborg Pedersen
    0

    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);

    }

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 06, 2013 @ 21:24
    Dan Diplo
    0

    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

  • Morten Skjoldager 440 posts 1499 karma points
    Jun 07, 2013 @ 16:06
    Morten Skjoldager
    0

    It's on the todo list. :) 

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Sep 02, 2013 @ 16:56
    David Brendel
    0

    Any updates on this?

    Also it should be 159,60€ (in germany) and not €159,60

  • Christian Wendler 46 posts 155 karma points
    Oct 01, 2013 @ 16:28
    Christian Wendler
    0

    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.

  • Jesper Nielsen 141 posts 498 karma points
    Oct 07, 2013 @ 10:12
    Jesper Nielsen
    0

    Hi David and Christian,

    This was fixed in version 4.

    Kind regards,

    Jesper

Please Sign in or register to post replies

Write your reply to:

Draft