spartacus-storefront - 向产品字段调用 Spartacus 添加其他属性
问题描述
我需要在 PDP 页面上发生的字段调用中添加一个额外的 url 参数(它是动态的而不是固定的)。我尝试过扩展产品服务,但这并没有触发我的任何覆盖功能。
我现在最终实现了产品适配器,所以我只想确认这是 100% 正确的。
export class MyProductAdapter implements ProductAdapter {
解决方案
如果您想在字段调用中添加(固定)值,您可以覆盖默认调用并添加缺失值。创建一个文件yourOccProductDetails.config.ts
export const yourOccProductDetailsConfig: OccConfig = {
backend: {
occ: {
endpoints: {
product: {
details: 'products/${productCode}?fields=averageRating,stock(DEFAULT),description,availableForPickup,code,url,price(DEFAULT),numberOfReviews,manufacturer,categories(FULL),priceRange,multidimensional,tags,images(FULL),yourParam',
},
},
},
},
},
并在您的模块中将配置添加到您的提供程序数组
import { yourOccProductDetailsConfig } from './yourOccProductDetails.config'
@NgModule({
imports: [...],
declarations: [YourProductDetailsComponent],
exports: [YourProductDetailsComponent],
providers: [provideConfig(yourOccProductDetailsConfig)],
})
export class YourProductDetailsModule {}
推荐阅读
- javascript - Async/Await 获取 JSON 数据失败
- java - NullPointerException 从 Firebase 数据库中检索数据
- tensorflow - 缺少 resnet_v1_50.ckpt 和 DeepLabCut 无法训练网络(深度学习)
- javascript - 用于在 React Native 中杀死应用程序后存储数据的数据库
- java - Mockito(Junit)无法遍历 JSONArray 对象
- wpf - WPF DataGrid AlternatingRowBackground 覆盖背景的 Style DataTrigger
- c# - 在 xamarin 中没有 googleservices.json 文件的 Firebase 实现
- java - JUnit GUI 不显示已执行的测试方法
- angular - 使用局部变量的 Angular 和 FabricJS 事件处理程序
- mysql - 获取rangedate mysql中的星期一数