Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Victor Bjørholm 41 posts 121 karma points
    Aug 17, 2020 @ 10:49
    Victor Bjørholm
    0

    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

  • Nik 1335 posts 5725 karma points MVP 3x c-trib
    Aug 17, 2020 @ 11:05
    Nik
    100

    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:

    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.

    Nik

  • Matt Brailsford 2807 posts 14331 karma points MVP 7x c-trib
    Aug 17, 2020 @ 12:37
    Matt Brailsford
    0

    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);
    

    /Matt

  • Matt Brailsford 2807 posts 14331 karma points MVP 7x c-trib
    Aug 17, 2020 @ 13:57
    Matt Brailsford
    0

    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

  • Victor Bjørholm 41 posts 121 karma points
    Aug 19, 2020 @ 08:20
    Victor Bjørholm
    0

    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);
    

    /Victor

  • Matt Brailsford 2807 posts 14331 karma points MVP 7x c-trib
    Aug 19, 2020 @ 09:26
    Matt Brailsford
    0

    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

  • Matt Brailsford 2807 posts 14331 karma points MVP 7x c-trib
    Aug 21, 2020 @ 10:26
    Matt Brailsford
    0

    Just to let you know, 1.2.8 is out now containing a fix for applyToCurrentOrder 🎉

Please Sign in or register to post replies

Write your reply to:

Draft