Forum for discussing general topics related to Couch.
9 posts Page 1 of 1
Hi, guys!

Have anyone implemented a currency converter with Couch? To-date data is taken from some place on web and used to display currency of choice? Hints, maybe?
Thank you!
:lol: Google search for 'currency converter php' gives Philippine pesos rate.. poor php :shock:
To-date data is taken from some place on web

I think the first step is to find "some place on the web". The service will provide up-to-date data in a given format, maybe XML or JSON. Once you've found a service that provides the data you need, then you can look into getting the data from the service and using it in your application. You'll create a PHP routine to make the conversion and tuck it into a Couch tag, something like
Code: Select all
<cms:convert_currency from="USD" to="RUB" amount="123.73" />

Here's a starting point from a quick search: http://answers.google.com/answers/threa ... 93723.html
This looks like a pretty good free feed. If you are going to use it for commerce, obviously you need to make sure it is reliable.

http://www.fxexchangerate.com/currency- ... -feed.html
Maybe this http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html

If you click on downloads you will find some php examples.
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Yes. The ECB would be my first choice if they cover the currencies you need to use.
Ok, thank you, guys!
I have managed to complete it. Used published php code. Put the output into couch variable and then db_persisted it to template's database. In order to update, one has to visit this template (once a day) to fetch updated rates. Then the rates are used in couchcart to recalculate dynamically.
Feel free to ask me and I will share full template. This is not a module/tag yet, only pure code.
In order to update, one has to visit this template (once a day) to fetch updated rates.

I haven't seen the actual code, and this is not something I need to use for myself. But in the abstract, this seems like an unsustainable solution. Manually accessing the template every day will get old very quickly. I think you'll balk at the burden of this daily responsibility before long, and you'll find yourself forgetting to access the template more and more as time goes by.

One option would be to set up a cron job to make the updates automatic. (Your server settings could make this complicated.) My own preference would be to check exchange rates in real time when the buyer is visiting the site, perhaps also saving them to the database as a backup in case of network errors.

Those are just my thoughts. I'm glad you found something that works for you.
Thanks, for suggestion, @tim. I will certainly look to cron.
Everyday visits lay as a burden to someone in a middle sized company. However, in the long run I'd figure out how to update info once in a while.
However, currency rate in that country is too unstable lately. And central bank publishes rates once a day only. So, i suppose, manual inputs will occur more often than a daily visit to update.
Edit: PS. You mentioned realtime, that's doable. But myself, i don't want to visit a shop with fluctuating prices. Especially if they change once an hour :)

PPS As a followup, a couch template is perfectly executed with a cron-job set in Cpanel. Data is fetched and persisted to database every 4 hours without issues.
9 posts Page 1 of 1
cron