如何在 PDP 上使用额外的 ProductWsDTO 属性?

How to use additional ProductWsDTO attributes on PDP?

SAP Spartacus 允许我们覆盖 PDP 中使用的各种组件。示例:ProductSummaryComponent (cx-product-summary).

使用 ConfigModule 覆盖它们非常简单,因为它们是 CMS 组件。

我的问题是关于我们如何使用我们的控制器可能 return 的附加属性。

示例 - 让我们考虑向 ProductModel 添加属性“manufacturedYear”,然后我们还通过 bean xml 将其包含在 ProductData 中。现在它在数据对象中,假设我们将它添加到 ProductWsDTO 中并将其添加到 DTO 映射中,现在将在 /product/{code} API 调用中 returned。

在UI中,我们有如下产品:

产品$:可观察=this.currentProductService.getProduct();

所以“Product”是@spartacus/core中“product.model.ts”中可用的模型。我们如何扩展它,以便我们可以通过使用进行实际 API 调用的基础服务来使用我们的新“制造年”?

目的只是扩展模型,但使用底层服务进行 API 调用以获取我们的附加属性。

感谢您的帮助

这里有一个扩展产品模型的例子,建议使用加载范围从后端获取额外的属性:Extending product model in Spartacus

基于它,你可以做:

import { Product as CxProduct } from '@spartacus/core';

export interface Product extends CxProduct {
  manufacturedYear: number;
}