首页 > 解决方案 > 向产品字段调用 Spartacus 添加其他属性

问题描述

我需要在 PDP 页面上发生的字段调用中添加一个额外的 url 参数(它是动态的而不是固定的)。我尝试过扩展产品服务,但这并没有触发我的任何覆盖功能。

我现在最终实现了产品适配器,所以我只想确认这是 100% 正确的。

export class MyProductAdapter implements ProductAdapter {

标签: spartacus-storefront

解决方案


如果您想在字段调用中添加(固定)值,您可以覆盖默认调用并添加缺失值。创建一个文件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 {}

推荐阅读