2 Replies Latest reply on Dec 31, 2008 11:40 AM by ahus1

    Multi Currency Tips

    mgvarley

      Hi all - I am working functionality to make my site multi-currency and I would be grateful of any tips from other Seam users who have implemented this before (I've been researching all morning and information on the forums is fairly sparce).


      I have converted my Product entities to use the MonetaryAmount entity and MonetaryAmountUserType for storing prices (based on Gavin King's example).  I have also created a SupportedCurrency entity to tell my app which currencies I support translation from and to (I am planning to allow vendors to add products in their own currency and customers to be able to be able to see prices in EUR, GBP, USD, AUD, CAD), an ExchangeRate class to store the rates by date and a SFSB which iterates over SupportedCurrency and populates instances of ExchangeRate by looking up the publicly available Yahoo service over HTTP (source code available for this if anyone is interested). 


      What I am puzzling over is where to put the conversion code to display the correct price to the customer.  There is a stub for convert() in the MonetaryAmount entity but if I convert here would I not need to inject my EntityManager to query ExchangeRate which would not be good design?


      Any advice on this would be very much appreciated.


      Thanks,


      Mark



        • 1. Re: Multi Currency Tips
          mgvarley

          I'm not sure if this is the best way to go but I have added a static hashmap of exchange rates to my MonetaryAmount class which is populated daily by my XRateAction class (gets latest rates from Yahoo).  The MonetaryAmount class has methods for convert(MonetaryAmount, Currency), add(MonetaryAmount), subtract(MonetaryAmount), equals(Object) and compareTo(MonetaryAmount) which make use of this hashmap to reflect the value of the amount in the user's preferred currency (stored on the User object).


          mark



          • 2. Re: Multi Currency Tips
            ahus1

            This reply is a bit late :)


            I would design it that there is MonetaryAmount on all products, and a preferred currency for the users.


            I would do the conversion separate from both, in a (JSF)-Converter.


            Alexander.