Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have now made a country selector, where users can select their country.
This selector is automatically populated with the countries I have made in Vendr.
However, I would of course want the price of the product to reflect the price for the chosen country, and also the currency. For now it only shows the british prices and GBP. I have looked in the Vendr documentation to see if there to change the Store standard country for that specific session.
So far the only solution seems to be a custom price calculator.
Any advice would greatly appreciated :D
You can do this by setting the session manager default currency to that associated with your picked country. You then need to update the existing order with said currency as well.
e.g. something like this:
var currentOrder = sessionManager.GetCurrentOrder(currency.StoreId);
if (currentOrder != null)
using (var uow = VendrApi.Instance.Uow.Create())
var order = currentOrder.AsWritable(uow).SetCurrency(currency);
You'd need to set a variable called currency based on the country picker and associated currency before running the code above.
Exactly what Nik said.
Only extra thing I could add is to say there is also a handy optional param on the SetDefaultCurrency called applyToCurrentOrder which should allow you to set the session default currency and at the same time update the order in one go.
sessionManager.SetDefaultCurrency(currency.StoreId, currency, applyToCurrentOrder: true);
Nik just rightly pointed out to me there is an outstanding bug in the code I presented (hence why Nik gave the code example he did) https://github.com/vendrhub/vendr/issues/160
I've reviewed and fixed that bug now, which will be in the upcoming 1.2.8 release, but in the mean time, Niks answer is the workaround.
Thanks Nik and Matt,
I forgot to write back yesterday, but I got it working as soon as I saw Nik's answer!!!
I also experienced that I could not set applyToCurrentOrder to true, although it worked with
sessionManager.SetDefaulCountry(country.StoreId, country, applyToCurrentOrder: true);
Great Nik's solution worked out for you.
Yea, the issue with applyToCurrentOrder not working should only affect the Currency and TaxClass based methods. These will be fixed in the next patch release though.
Thanks for confirming 👍
Just to let you know, 1.2.8 is out now containing a fix for applyToCurrentOrder 🎉
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted