0

SAP Spartacus allows us to override the various components that are used within the PDP. Example : ProductSummaryComponent (cx-product-summary).

Overriding them is pretty straightforward using the ConfigModule as they are CMS Components.

My question is around how we can use the additional attributes that our controllers may return.

Example - lets consider we add an attribute "manufacturedYear" to the ProductModel, then we also include it in the ProductData via beans xml. Now that it is in the Data objects, say we added it in the ProductWsDTO and add it in the DTO mapping, this will now be returned in the /product/{code} API call.

In the UI, we have the product as below:

product$: Observable = this.currentProductService.getProduct();

So the "Product" is a model available in "product.model.ts" in the @spartacus/core. How can we extend this such that we can use our new "manufacturedYear" by using the underlying services which make the actual API call?

The intention is to just extend the model but use underlying services to make API calls to get our additional attributes.

Thanks for your help

1 Answers1

2

Here is an example of extending the product model and suggested using loading scopes to fetch the extra attributes from the backend: Extending product model in Spartacus

Based on it, you could do:

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

export interface Product extends CxProduct {
  manufacturedYear: number;
}
Caine Rotherham
  • 306
  • 1
  • 5
  • Thanks a lot Caine for your help. Another slack team member helped me with this link which explains a bit more what you have answered above: https://sap.github.io/spartacus-docs/type-augmentation/ – Balaji Mohan Oct 27 '21 at 10:36