Closed alvteren closed 3 years ago
Often I need extend any service or component for changing logic in one method. But I can't do this without "hack".
Last few cases:
Firstcase, our backend developer add few fields to cart items. Spartacus model is
export interface Item { product?: any; quantity?: any; basePrice?: any; totalPrice?: any; updateable?: boolean; }
my model:
export interface CustomItem extends Item { weight: number; volume: number; }
but property _items is private
Second case, I want to extend ProductListComponentService and I want to add in method getQueryFromRouteParams my custom condition
if this method was protected, I would do
protected getQueryFromRouteParams({ brandCode, categoryCode, promoCode, query, }: ProductListRouteParams) { if (query) { return query; } if (categoryCode) { return this.RELEVANCE_ALLCATEGORIES + categoryCode; } if (brandCode) { return this.RELEVANCE_ALLCATEGORIES + brandCode; } if (promoCode) { return this.RELEVANCE_ALLCAMPAINGS + promoCode; } }
But I have to replace whole class
This is mostly by design, @dunqan to provide more info.
The extensibility of the ProductListComponentService has been improved in v2.1. See PR https://github.com/SAP/spartacus/pull/7987
ProductListComponentService
Often I need extend any service or component for changing logic in one method. But I can't do this without "hack".
Last few cases:
Firstcase, our backend developer add few fields to cart items. Spartacus model is
my model:
but property _items is private
Second case, I want to extend ProductListComponentService and I want to add in method getQueryFromRouteParams my custom condition
if this method was protected, I would do
But I have to replace whole class