Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change BaseStore from SAP Spartacus storefront

As Spartacus is for B2C process there is no any option to change BaseStore from storefront. I have a drop down for different countries and now want to change BaseSite from it.

like image 985
user8462556 Avatar asked Aug 31 '25 18:08

user8462556


1 Answers

So finally I made it working. I am storing baseSite to session if its changed from dropdown and if user is coming back reading it first from session. here what you have to do to make it working:

  1. Override BaseSite service and change initialize method similar to the initialize method of LanguageService. (which check if baseStore is stored in session )

  2. Listen to SET_ACTIVE_BASE_SITE action and set payload to session. (again similar like activeLanguage effect in LanguagesEffects)

  3. Now in B2cStorefrontModule config add your other sites as

 B2cStorefrontModule.withConfig({
     context: {
       baseSite: ['electronics','mystore2','mystore-uk', 'mystore-canada'],
       language: ['en'],
       currency: ['USD']
     }

So the main solution is, you listen to basestore change action and store the value to session and on page load you read basestore from session

like image 139
user8462556 Avatar answered Sep 10 '25 04:09

user8462556