Page 1 of 1
currency
Posted: Sun Dec 16, 2012 12:04 pm
by pluto
Hey,
I think this is a real basic question but can someone tell me how to set the currency to Euro?
When I do this:
Code: Select all
System.out.println("Locale: " + locale.getDisplayName());
Currency currency = Currency.getInstance(locale);
System.out.println("Currency Code: " + currency.getCurrencyCode());
System.out.println("Symbol: " + currency.getSymbol());
System.out.println("Default Fraction Digits: " + currency.getDefaultFractionDigits());
the output is
Locale: Nederlands (België)
Currency Code: EUR
Symbol: €
Default Fraction Digits: 2
Still he will always put a $ before the price. So how can I force to put him on €
*****UPDATE****
Code: Select all
Money mon=new Money();
System.out.println(mon.getCurrency());
Will also print out EUR.
Thanks,
Pluto
Re: currency
Posted: Fri Dec 21, 2012 5:29 pm
by phillipuniverse
This is completely supported in the 2.2 version of Broadleaf (currently in snapshot). Docs on enabling this:
http://docs.broadleafcommerce.org/2.2/C ... ution.htmlIf you can't use 2.2 for some reason, you could look at the PriceTextDisplayProcessor and override this to return whatever sign you would like.
Re: currency
Posted: Sat Dec 22, 2012 6:30 am
by pluto
Thanks phillipuniverse!
Now it's working! I override the PriceTextDisplayProcessor.
Re: currency
Posted: Thu Jan 10, 2013 7:16 pm
by fibernut
How do I go about modifying the PriceTextDisplayProcessor to show the a difference currency sign?
Re: currency
Posted: Fri Jan 11, 2013 11:02 am
by phillipuniverse
The processor is pretty straightforward. The meat of it is near the end:
Code: Select all
BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
if (brc.getJavaLocale() != null) {
NumberFormat format = NumberFormat.getCurrencyInstance(brc.getJavaLocale());
format.setCurrency(price.getCurrency());
return format.format(price.getAmount());
} else {
return "$ " + price.getAmount().toString();
}
If you do not want to mess with the BLC request context, you can override this and provide your own implementation by adding this in an application context:
Code: Select all
<bean id="blPriceTextDisplayProcessor" class="com.mycompany.CustomPriceTextDisplayProcessor" />
And return the price formatted however you like.
Re: currency
Posted: Fri Jan 11, 2013 11:42 am
by fibernut
Thanks Philip,
What file is the processor in, and where would I find this file?
Re: currency
Posted: Fri Jan 11, 2013 12:32 pm
by phillipuniverse
The price text processor? PriceTextDisplayProcessor.java? This is a BLC class it's not something you will find in the demo site directly. You can get to it by doing CTRL + SHIFT + T (open type) in Eclipse.
Re: currency
Posted: Tue Jan 15, 2013 6:59 pm
by fibernut
I have tried to open the class but eclipse cannot find the jar. Ho can I get the jar or where do I tell eclipse to find it.
Thbanks.
Re: currency
Posted: Wed Jan 16, 2013 11:26 am
by pluto
Hey fibernut,
It's at org.broadleafcommerce.core.web.processor.PriceTextDisplayProcessor.
But I think you better do what
philipuniverse suggest:
override your own implementation:
Code: Select all
<bean id="blPriceTextDisplayProcessor" class="com.mycompany.CustomPriceTextDisplayProcessor" />
Re: currency
Posted: Wed Jan 16, 2013 4:47 pm
by fibernut
So all I do is add that line to the appliaction context in the site project and create a new java class in the java folder with
Code: Select all
BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
if (brc.getJavaLocale() != null) {
NumberFormat format = NumberFormat.getCurrencyInstance(brc.getJavaLocale());
format.setCurrency(price.getCurrency());
return format.format(price.getAmount());
} else {
// Setup your BLC_CURRENCY and BLC_LOCALE to display a diff default.
return "$ " + price.getAmount().toString();
}