Answer the question
In order to leave comments, you need to log in
Currency switcher in Yii2?
Good day!
We are developing an online store on Yii2. The task is to implement something like a currency switch (from ruble to dollar and vice versa). Please tell me how best to implement such a task and how to do it in general.
It is planned to parse the dollar exchange rate from the Central Bank of the Russian Federation
By default, prices are stored in the database in dollars
When you click on the link (ruble), prices are displayed in rubles
Answer the question
In order to leave comments, you need to log in
Just like everywhere else. There is a base currency and there is a coefficient by which it is multiplied. The coefficient in the database, kroner visits the Central Bank once a day or more often and receives the rate by api, saves it to the database.
But how to store the user's choice, there are already options. I would shove it into the session, but you can generally shove it into localStorage, shove the rate there or into (sessionStorage), php always renders with the base currency, and js replaces it with the one you need. That is, to give part of the mathematics to the browser. Which can sometimes give a performance boost.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question