Add additional property to products field call Spartacus

Viewed 198

I need to add an additional url parameter (which is dynamic and not fixed) to the fields calls that happen on the PDP page. I have tried extending the the product service but that doesnt fire any of my overide functions.

I have now ended up implementing the product adapter so I just want to confirm this is 100% correct.

export class MyProductAdapter implements ProductAdapter {
2 Answers

if you want to add a (fixed) value in your fields call you can override the default call and add your missing value. Create a file 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',
        },
      },
    },
  },
},

And in your module add the config to your providers array

import { yourOccProductDetailsConfig } from './yourOccProductDetails.config'

@NgModule({
  imports: [...],
  declarations: [YourProductDetailsComponent],
  exports: [YourProductDetailsComponent],
  providers: [provideConfig(yourOccProductDetailsConfig)],
})
export class YourProductDetailsModule {}
Related