I am working on development of information system which must handle multi currencies ( USD, EUR, JPY ). Let's say, user can add products to system. User adds product #1 on 13 Feb 2017, price 2000, currency JPY. User adds product #2 on 14 Feb 2017, price 25, currency USD.
Later (15 Feb 2017) user can view and filter his products, let's say user wants to view products in USD and there is a price range filter.
Goal:
- user sets some price range and i have to find these products in database properly
My current approach is:
- i have decided, that EUR is my unified currency
- when user adds product - convert each product price to EUR using today exchange rate
- in database, original price and currency is stored (from user input), converted price(EUR) is stored
- price range in filter is initialized by today rate, so 2000 JPY is converted to USD as lower limit (17.5 USD), 20 USD as upper limit
Problems:
- user sets limit from 17.5 USD do 20 USD
- I convert 17.5 USD to a EUR_value_1, 20 USD to a EUR_value_2
- select to database where price_unified between EUR_value_1 and EUR_value_2
- values does not match products in database, because used rate can be higher / lower (every day) so values are different
My questions are:
- what is the right way to store these products, prices, currencies in database ? Should i store all currency values ?
- how to handle frontend behavior as price range filter in some currency but still be able to find products in database properly ?
- should i create a cron to re-convert all prices by today rate ?