Eduardo P
Eduardo P

Reputation: 1

How to automatically change currency between sites according to user profile in Spartacus

I'm developing a SAP Commerce site that should handle 2 countries with different currencies.

I started with one baseStore (supporting both currencies) and one baseSite (storefront). It works fine and users can select currencies using the drop-down list.

But the requirement is that users are associated with only one country and can only see their country prices. After logging in they should stick with the currency associated with their profile.

I created a second baseStore to have 1 baseStore for each country, each linked only to their corresponding currency. I also extended DefaultBaseStoreSelectorStrategy to select the correct baseStore. The issue is the same currency is always set from the Spartacus request parameter (on DefaultContextInformationLoader).

I also tried to create a second baseSite (so each country would have it's own baseStore and associated baseSite) but I still end up with the expected baseSite but always the original currency.

It's similar to discussion on https://spartacus-storefront.slack.com/archives/CD16V16FR/p1574329837183900

Upvotes: 0

Views: 399

Answers (1)

tobi-or-not-tobi
tobi-or-not-tobi

Reputation: 1260

The multi-site capabilities of the commerce platform and the integration of spartacus should provide you with an out of the box solution.

What you'd need here:

  • 2 baseStores, each with a specific baseSite. You can however reuse the product assortments, search indexes, cms content, etc. but you can also differentiate this per country.
  • the baseStore should be configured with a single language config (this means that spartacus would not show the language selector as there's nothing to select)
  • use the multi-site configuration in Spartacus to ensure that you drive the configure by the backend. you should avoid static site config in Spartacus.
  • if both sites run on the same domain, you quite likely want to use a encoding attributes for the site or language, so that the URLs are diferentiated (for SEO as well)

Upvotes: 0

Related Questions