G
G
Garde22018-07-12 12:05:32
MySQL
Garde2, 2018-07-12 12:05:32

How to convert the price of a product if the user himself decides in which currency to indicate the price of his product?

Good afternoon. I can't figure out how to convert the currency if the price for each product can be indicated in different currencies.
There is a table:
products
id|cost|currency_id
1| 11 | 1
2| 133| 2
currencies
id|symbol|course
1|RUB|1
2|USD|63
Now I have a table of currencies that depends on the ruble. What is the best way to design the database so that if the user chooses the RUB currency, then everything is in rubles, USD is all in dollars.
So far I have one idea, to create a table (currency_id, currency2_id, cost) and dance further from this. Has anyone come across this problem and know the solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2018-07-12
@Garde2

You think correctly - you need to create a table containing the exchange rates of one currency for another

A
Alex-1917, 2018-07-12
@alex-1917

if the user himself decides in what currency to indicate the price of his goods?

The title of the question is confusing .. At first I thought that this is about a product that the user himself creates and edits ...
You most likely have a more banal platitude - there are goods, there is a currency exchange rate and there is a user who can only watch the product. Then everything is banal to the point of madness:
1. The price of the product is ONE. In any ONE currency.
2. The user has selected a currency - we give him from the database the price in the original currency multiplied by the exchange rate selected by the user. Exchange rates are stored in the database. The course chosen by the user can be stored for each user in his cookies or localstorage...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question