1

Is it possible to change the store currency from a plugin?

I know about COMMERCE_PAYMENT_CURRENCY, but I'm not sure how to set that one early enough.

It also seems like it doesn't affect the displayed price. Do I need to use the commerceCurrency in combination with the cart.paymentCurrency everywhere I display a price?

1

In your plugin have you tried updating the currency and paymentCurrency fields in the craft_commerce_orders database table?

Depending on when you want to set the currency and how you are determining it, you could either do this by a direct database query, or modify the values in the order model before it is saved using this hook: https://craftcommerce.com/docs/events-reference#commerce_orders.onbeforesaveorder

1
  • I have tried modifying those columns manually. But as far as I know, that doesn't affect the displayed prices. Apr 26 '17 at 19:11
1

You can set the COMMERCE_PAYMENT_CURRENCY in your index.php file. This defaults the order.paymentCurrency. The price attributes on the order are still stored in the primary store currency so you will still need to convert to the current payment currency with the commerceCurrency filter: https://craftcommerce.com/docs/twig-filters#commercecurrency

1
  • This wouldn't work as I need to conditionally set it from my plugin. Feature request? Say that becomes possible. Would I use the order.paymentCurrency through the commerceCurrency in the order confirmation etc. to keep it the same everywhere? Will that mean, that if I update the exchange rates, and a customer then goes to look at their order on the site, the price will look different from what they paid? It doesn't take into the exchange rate on the day they ordered, right? May 3 '17 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.