KonaKart Community Forum

Installation / Configuration => Programming of KonaKart => Topic started by: tqumhieh on February 13, 2013, 07:25:34 am

Title: Change currency using java API
Post by: tqumhieh on February 13, 2013, 07:25:34 am
Hi Guys,

How can I programmatically change the currency view in my front store? I'm building a custom portal and wishes to have a drop down menu where users can select the currency and all prices will be changed according to this selection.
I'm using the latest  6.5 version, and what I want to know:
1) how to change currency using API.
2) once currency changed, will prices be reflected automatically or is this a manual effort I have to maintain?
Title: Re: Change currency using java API
Post by: trevor on February 13, 2013, 08:59:32 am
The KK store-front already has a drop down menu to select currency.

If you want to know how it works you should look at the code in the struts action class. The form calls SetLocale.action which runs the code in SetLocaleAction.java .

The conversion rate is defined in the value of the currency object. The default currency has a value of 1 and any other defined currency has a value which is used as a multiplier to apply the conversion.
Title: Re: Change currency using java API
Post by: tqumhieh on February 13, 2013, 04:36:23 pm
Thanks for the reply, but does this mean once I set the new currency and requery products, their prices will be reflected automatically to match the new currency? Or do I need to loop over the product and multiply with the currency factor
Title: Re: Change currency using java API
Post by: trevor on February 13, 2013, 06:21:40 pm
We do the multiplication for you.
Title: Re: Change currency using java API
Post by: tqumhieh on February 14, 2013, 08:36:39 am
I think you mean SelectCurrencyAction.java and not SetLocaleAction.java Anyhow, it seems im having issues initializing KKAppEng, im trying to do so from a JSF managed bean, and im not using struts in my application, will that cause any issue?
Title: Re: Change currency using java API
Post by: trevor on February 14, 2013, 08:54:24 am
QuoteI think you mean SelectCurrencyAction.java and not SetLocaleAction.java

Yes, sorry, slip on my part.

Quoteit seems im having issues initializing KKAppEng, im trying to do so from a JSF managed bean, and im not using struts in my application, will that cause any issue?

You don't need to use Struts. In this case it may be easier to directly call the server engine APIs and not use KKAppEng. Here's an example of a JSF application using KK : https://raceforlife.cancerresearchuk.org/rfl/forms/shop/shop.jsf . If you don't use KKAppEng you will have to perform the currency multiplication on the array of products received from the KK server engine.
Title: Re: Change currency using java API
Post by: tqumhieh on February 14, 2013, 10:20:57 am
Thanks trevor, then this lead us to the original question once again, how to change the default currency utilizing the KKEngine server APIs? as all examples simply use the KKAppEngine
Title: Re: Change currency using java API
Post by: trevor on February 14, 2013, 10:40:54 am
You save the customers selection in the session or a cookie or a customer tag (EE only) and do the multiplication yourself before displaying.