Hi Matt,
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:
sessionManager.SetDefaultCurrency(currency.StoreId, currency);
var currentOrder = sessionManager.GetCurrentOrder(currency.StoreId);
if (currentOrder != null)
{
using (var uow = VendrApi.Instance.Uow.Create())
{
var order = currentOrder.AsWritable(uow).SetCurrency(currency);
VendrApi.Instance.SaveOrder(order);
uow.Complete();
}
}
You'd need to set a variable called currency based on the country picker and associated currency before running the code above.
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.
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
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.
Show specific country price
Hi Matt, 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
/Victor
Hi Victor,
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:
You'd need to set a variable called
currency
based on the country picker and associated currency before running the code above.Nik
Exactly what Nik said.
Only extra thing I could add is to say there is also a handy optional param on the
SetDefaultCurrency
calledapplyToCurrentOrder
which should allow you to set the session default currency and at the same time update the order in one go./Matt
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.
/Matt
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
/Victor
Hi Victor,
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 👍
Matt
Just to let you know, 1.2.8 is out now containing a fix for
applyToCurrentOrder
🎉is working on a reply...