likes
comments
collection
share

如何在 Spartacus 使用 UserAccountFacade 在语言设置更改后重新读取用户数

作者站长头像
站长
· 阅读数 14

问题1:如何在 Spartacus 使用 UserAccountFacade 在语言设置更改后重新读取用户数据

如何在 Spartacus 使用 UserAccountFacade 在语言设置更改后重新读取用户数如何在 Spartacus 使用 UserAccountFacade 在语言设置更改后重新读取用户数如何在 Spartacus 使用 UserAccountFacade 在语言设置更改后重新读取用户数

可以扩展上图这个 Observable.

然后使用 combineLatest 和其他的 Observable 进行组合。

如何在 Spartacus 使用 UserAccountFacade 在语言设置更改后重新读取用户数

问题2:使用 outlet 时遇到错误消息:Type before is not assignable to type OutletPosition

如何在 Spartacus 使用 UserAccountFacade 在语言设置更改后重新读取用户数如何在 Spartacus 使用 UserAccountFacade 在语言设置更改后重新读取用户数

解决方案:

add outletPosition = OutletPosition; to the component,

HTML 里添加代码:

[cxOutletPos]="outletPosition.BEFORE"

还需要检查:

did you add the outlets to the app component html?

例如添加如下代码到 Component HTML:

<outlets></outlets>

问题2:HTTP 400 和 404

对于 product 明细页面来说,随便输入一个不存在的 url,返回值为 HTTP 400:

https://cloudapp.azure.com:9002/occ/v2/electronics-spa/cms/pages?pageType=CategoryPage&code=5781122&lang=en&curr=USD如何在 Spartacus 使用 UserAccountFacade 在语言设置更改后重新读取用户数

错误消息:

{
   "errors" : [ {
      "message" : "The value provided is not allowed.",
      "reason" : "invalid",
      "subject" : "code",
      "subjectType" : "parameter",
      "type" : "ValidationError"
   } ]
}

如果是 content page 请求不存在:

https://cloudapp.azure.com:9002/occ/v2/electronics-spa/cms/pages?pageType=ContentPage&pageLabelOrId=%2Ftest&lang=en&curr=USD

返回错误消息:

   "errors" : [ {
      "message" : "No content page found matching the provided label or id: /test",
      "type" : "CMSItemNotFoundError"
   } ]
}

客户可以使用自定义的 renderKeyResolver 来动态决定哪个页面应该使用哪种渲染策略,SSR 还是 CSR.

如果特定键缺少翻译,则生产模式下的店面会显示不间断的空格字符。 为了更容易捕捉丢失的键,在开发模式下,Spartacus 会显示翻译键,前面有块的名称和冒号(例如,[common:form.confirm])。

如果缺少翻译,为了提供更好的用户体验,开发人员可以指定备用语言。 设置 fallbackLang 选项可确保对于每个缺失的翻译,使用来自备用语言的等价物。

以下是使用英语作为备用语言的示例配置:

import { translations, translationChunksConfig } from '@spartacus/assets';

// ...

providers: [
  provideConfig({
    i18n: {
      resources: translations,
      chunks: translationChunksConfig,
      fallbackLang: 'en',
    },
  }),
];

翻译由语言和命名块构成,因此开发人员可以仅为当前语言和当前页面加载翻译资源。 以下是翻译资源的结构示例:

interface TranslationResources {
  [lang: string]: {
    [chunkName: string]: {
      [key: string]: any; // value or nested object with keys
    };
  };
}

如何在 Spartacus 使用 UserAccountFacade 在语言设置更改后重新读取用户数