SAP Spartacus的site context配置
每个CMS site都有一个自己的上下文:
- base site ID,
- allowed languages and default language,
- allowed currencies and default currency.
- configuration of persistence of above attributes in the URL
静态上下文配置
You can configure your application by defining context properties, such as base site, language, and currency. When you append the values of these properties to the storefront URL, the storefront is configured based on these values.
配置代码如下:
export const b2cFeature: FeatureEnvironment = {
imports: [
B2cStorefrontModule.withConfig({
context: {
urlParameters: ['baseSite', 'language', 'currency'],
baseSite: [
'electronics-spa',
'electronics',
'apparel-de',
'apparel-uk',
'apparel-uk-spa',
],
},
For example, when you access https://localhost:4200/electronics-spa/en/USD/, the application loads the electronics-spa base site, sets the site language to English (en), and sets the currency to US dollars (USD).
The context properties also set the default values for the language and currency drop-down lists, which you can use to change the context of the storefront dynamically.
Context属性在app.module.ts里定义:
context: {
baseSite: ['electronics-spa'],
urlParameters: ['baseSite', 'language', 'currency']
},
urlparameter的顺序可以自己调:
context: {
baseSite: [
'electronics-spa', //Selected by default because it is the first element in the list
'electronics',
],
language: [
'en'
],
currency: [
'USD'
],
urlParameters: ['baseSite', 'language', 'currency']
},
You can change the structure of the context in the URL by changing the order of the elements in the urlParameters property. For example, if you change the urlParameters property to urlParameters: ['currency', 'language', 'baseSite'], then the URL becomes https://localhost:4200/USD/en/electronics-spa/