Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hjortur17's avatar

Currency exchanger

Hi, I need a little help structuring my currency exchanger. I have a dropdown inside my navbar where customer can change between currencies. What I need help with is to figure out the best way to update all my prices through the side.

What I have tried now is to have inside HandleInertiaRequests a GET request which gets relevant currency exchange data. Then which currency the customer has picked (default ISK) in a session cookie. All the prices for each product are stored inside the database and in ISK, what I'm trying to achieve is that customer can change the site to USD (for example) and all prices will convert from ISK to USD using Inertia prop data.

Any ideas?

0 likes
3 replies
SteamDiesel's avatar
Level 6

You could save the user selection in local storage OR customer account info OR session.

I would not let the system make calculations or handle transactions in anything other than your default currency, instead use the exchange rate to display the currency in the user's selection.

So maybe may a vue component that displays a price based on the underlying actual price?

then you could just use the price component anywhere a price is rendered

<Price 
		:currency="$attrs.user.currency_exchange_rate" 
		:price="price" 
		class="whatever you want"
/>

and the component would look something like this

<template>
		<div>{{ price * currency_exchange_rate }}</div>
</template>
<script>
		export default {
				props:{
						currency: Number,
						price: Number
				}
		}
</script>

I dunno, I haven't worked with exchange rates before, but this is how I'd hit the problem. All I know is that currency is always stored and manipulated in the lowest denomination. Never store dollars, instead store whole cents.

1 like

Please or to participate in this conversation.