我正在尝试使用我在 -items.xml 中创建的新属性来扩展产品模型,但我似乎无法在 Spartacus 前面获取它。我添加了一个带有以下代码的product.model.ts文件:
import { Product as CxProduct } from '@spartacus/core';
export interface Product extends CxProduct {
myAttribute: string;
}
我将该文件导入到使用产品模型的管道中,但它显示为空,尽管该产品在后台的 myAttribute 字段中确实有数据。我可能缺少什么吗?
我在我创建的product-images.component 中使用此属性来覆盖默认属性。
这是新产品-images.component.ts
import { Component, OnInit } from '@angular/core';
import { CurrentProductService } from '@spartacus/storefront';
import { ProductImagesComponent as SpartacusProductImages } from '@spartacus/storefront'
@Component({
selector: 'cx-product-images',
templateUrl: './product-images.component.html',
styleUrls: ['./product-images.component.scss']
})
export class ProductImagesComponent extends SpartacusProductImages implements OnInit {
constructor(currentProductService: CurrentProductService) {
super(currentProductService)
}
ngOnInit() {
}
}
多谢
您需要明确要求后端返回属性。请配置product
要包含的端点?fields=
与您的自定义属性。请参阅文档:https://sap.github.io/spartacus-docs/connecting-to-other-systems/#configuring-endpoints https://sap.github.io/spartacus-docs/connecting-to-other-systems/#configuring-endpoints
请注意,您可以为产品数据指定各种范围的端点配置 - 因此您可以仅在需要时加载自定义属性(即,当某些视图(如产品轮播或产品列表)未显示 myAttribute 时,它很有用)。但由于您正在操作图像数据,我想您想在任何地方使用此属性(因此请使用名为list
).
有关更多信息,请参阅范围产品端点的文档:https://sap.github.io/spartacus-docs/loading-scopes/#using-default-product-scopes https://sap.github.io/spartacus-docs/loading-scopes/#using-default-product-scopes. 注意:撰写本文时,Spartacus 2.0 版本的文档尚未发布。在2.0中product_scopes
配置属性已重命名为product
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)