webdna / commerce-currency-prices

Add a product price for each currency
Other
3 stars 5 forks source link

How do I display cart totals in chosen currency? #22

Closed peteeveleigh closed 2 years ago

peteeveleigh commented 2 years ago

I'm working on a site where the commerce-currency-prices plugin has been used.

The site's primary currency is GBP and there are additional currencies for Euros and US Dollars.

We have a range of products that need to be displayed, and purchased in USD.

I can see how to display an item's price using the USD currency field, but how can I display cart totals in USD? Does this plugin provide that functionality?

mcjackson18 commented 2 years ago

Hi @fantasticmachine, the plugin doesn't set the currency on a cart. One way to do it is to update the paymentCurrency on the cart and then pass this to Commerce's commerceCurrency filter to display the selected currency.

Form to update the paymentCurrency:

<form method="post">
  {{ actionInput('commerce/cart/update-cart') }}
  {{ csrfInput() }}
  {{ redirectInput(craft.app.request.fullPath) }}
  <input type="hidden" name="paymentCurrency" value="USD">
  <button type="submit">
      USD
  </button>
</form>

Display the cart totals using this currency

{{ cart.total|commerceCurrency(cart.paymentCurrency) }}

peteeveleigh commented 2 years ago

Thanks for the tip.