umbraco / Umbraco.Commerce.Issues

18 stars 2 forks source link

COMMERCE multistore in a multi language solution is not getting all currencies in the PRICE field. #538

Closed GitNetlab closed 1 month ago

GitNetlab commented 1 month ago

Describe the bug In localhost using trial version, I have set up two store each set to different default currencies. Norway store to "NOK" and Canada store to "CAD". Umbraco price field is added to the product document type. I am not getting the CAD in the PRICE field. Product has NO culture. NORWEGIAN is default language for the application.

Steps To Reproduce Steps to reproduce the behavior:

  1. Create a PRODUCT document type and add a commerce PRICE field.
  2. Create two stores "Norway" and "Canada" and set default currencies to "NOK" and "CAD" respectively.
  3. Open the product in backoffice.

Expected behavior A clear and concise description of what you expected to happen. Should show both currencies "NOK" and "CAD" in the umbraco PRICE field.

Screenshots umbraco commerce multistore.docx

Additional context Yes. Commerce Checkout is also used. If try to add additional currency "CAD" to the NORWAY store, the CAD appears in the PRICE field in the backoffice. and set NORWAY store to the CANADA webpages, it works. But our requirement is to setup separate STORE.

Umbraco Commerce version: v12.1.1

mattbrailsford commented 1 month ago

@GitNetlab A product node can only belong to a single store. The price property editor will look up the content tree to find a store picker which connects a section of the site to a given store. Given you are only seeing the NOK currency it would suggest your section of the site is connected to the Norway store.

GitNetlab commented 1 month ago

Thanks for the response. I added two currecies to NORWAY store. The CalculatePrice() always returns NOK value. but I want to get CAD value for "en-ca" webpages. get productNode (IpublishedContent) in content. var store = content.Value("store", fallback: Fallback.ToAncestors); var datats = UmbracoCommerceApi.Instance.GetProduct(store.Id, content.GetProductReference(), null); (Prices holds both NOK and CAD price value) but datas.CalculatePrice().WithTAX always returns NOK price. I tried to pass "Thread.CurrentThread.CurrentCulture.Name" in languageIsoCode, still it returns NOK price. How to get the correct currency Price value based on the page culture?

mattbrailsford commented 1 month ago

CalculatePrice will do one of two things to choose the currency it calculates the price in.

1) If there is a current order, it will use the currency of that 2) If there is now current order, it will use ISessionManager.GetDefaultCurrency to calculate the price.

If you want to change the price, you'll either need to change the currency of the current order, or update the current sessions default currency.

GitNetlab commented 1 month ago

The product page should show the correct currency price well before product is added to the cart and order create. var currency = _currencyService.GetCurrencies(store.Id).FirstOrDefault(c => c.Code.ToLower() == selectedLanguage.CurrencyCode); if (currency != null) { UmbracoCommerceApi.Instance.ClearDefaultCurrency(store.Id); UmbracoCommerceApi.Instance.SetDefaultCurrency(store.Id, currency.Id); }

I cleared the DefaultCurrency and set the desired CAD currency. But still I get NOK (default currency of the store) is returned to GETDEFAULTCURRENCY.

How to update the current sessions default currency?

mattbrailsford commented 1 month ago

That code should be enough. Are you sure you don’t have a current order in your session? Try clearing your cookies.

GitNetlab commented 1 month ago

The product page should show the correct currency price before adding the product to the cart. Not all users have ADDTOCART option. many users will have only view product information access. I cleared the cookies, also tried in new incognito mode, the defaultCurrency is not changed image From the screenshot, it is clear that CAD is set as default and after executing the statement on GETDEFAULTCURRENCY, it is still NOK. Is there any option to pass the currency in publishContent.CALCULATEPRICE().

mattbrailsford commented 1 month ago

As I said, it will use the current order IF THERE IS ONE, if there isn't, it will fallback to the current sessions default, hence me asking.

I've just checked the logic of the ISessionManager.SetDefaultCurrency and realized there is also a check in that method that the currency must be allowed in the default payment country so you'll also need to make sure ISessionManager.GetDefaultPaymentCountry is set to a country that the currency is allowed in.

Your only other option would be to bypass that method and use the IProductCalculator directly, which is ultimately what that CalculatePrice method does, but deduces the required arguments for the calculator from the session.

GitNetlab commented 1 month ago

After assigning the country to the CAD currency, it worked. Thanks.