D
D
Dmitry2019-06-04 15:49:00
Database
Dmitry, 2019-06-04 15:49:00

How to store product prices in a database?

Hello, there is an online store. For example, two currencies - the dollar and the euro. One of the currencies is current, that is, the one in which all prices on the site. For example, the database contains all prices in dollars and you need to change the current currency to euro. It is unlikely that the prices in the database should be recalculated every time the current currency changes? How is the price of goods usually stored? I assume that the prices are in the default currency, and when changing the currency to another, the price displayed in the view is converted to another currency according to the current exchange rate?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aleks-th, 2019-06-04
@ddimonn8080

For good, to avoid unnecessary mistakes, store one base price.
And a table with the current exchange rate.
And at request to recalculate.
--
Otherwise, let's say you have 5 currencies. And a lot of goods.
You change the price tag, at the time of the price change something goes wrong and kirdyk, you get an unrelated base where prices do not randomly correspond to each other.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question