美文网首页SAP
SAP Spartacus的site context配置

SAP Spartacus的site context配置

作者: _扫地僧_ | 来源:发表于2021-03-21 11:51 被阅读0次

    https://github.com/SAP/spartacus-docs/blob/901d0521dcf4668e2ddc5982947268becd0e66dd/_pages/dev/context-configuration.md

    每个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/

    相关文章

      网友评论

        本文标题:SAP Spartacus的site context配置

        本文链接:https://www.haomeiwen.com/subject/ykongktx.html