Override an existing service to extend its functionality #2603
Unanswered
AndyPelaez
asked this question in
Q&A
Replies: 1 comment
-
Hi, You are correct that providing a custom version of that service would need to be done in the core module in which it is currently declared, so not possible from a plugin. So are you looking for some way that allows you to use arbitrary custom logic to calculate the stockOnHand for a variant? If so then yes, we don't currently have a strategy for that case. Can you give me an example (can be pseudo code) that illustrates the kind of thing you'd like to be able to do? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am attempting to extend the functionality of the ProductVariantService but haven't been successful. I've created a new plugin that includes a CustomVariantProductService extending the original one, which contains a log in the getSelectableStockService.
@Injectable()
export class CustomProductVariantService extends ProductVariantService {
override async getSaleableStockLevel(ctx: RequestContext, variant: ProductVariant): Promise<number> {
Logger.info('getSaleableStockLevel!', loggerCtx);
return super.getSaleableStockLevel(ctx, variant);
}}
I have also included the service in the providers(I know it should be placed in the original module but It is not possible without modifying the original module):
providers: [ { provide: ProductVariantService, useClass: CustomProductVariantService, } ],
I need to do this because I must modify how the stock of a product is obtained(In my case for products that will contain ingredients that set the stock of the product), and I haven't found any strategy that allows me to customize that.
Thanks in advance for any hints!
Best Regards
Beta Was this translation helpful? Give feedback.
All reactions