Is there any way to override OccStoreFinderAdapter class in SAP Spartacus v3.x+? What I have already tried is to add a custom provider in store-finder-feature.module.ts like this
{
provide: OccStoreFinderAdapter,
useClass: CustomOccStoreFinderAdapter
}
but it still uses the OOTB one.
Please mind to provide your custom StoreFinderAdapter not in the app.module (not in the root injector), but provide it in your lazy-loaded custom "wrapper" module of the storefinder feature.
For more, see docs of Customizing Lazy Loaded Modules.
It's needed, since the store finder feature became lazy loaded by default in new versions of Spartacus.
{
provide: StoreFinderAdapter, // not OccStoreFinderAdapter
useClass: ThmOccStoreFinderAdapter
}
For the token StoreFinderAdapter, Spartacus OOTB passes the OccStoreFinderAdapter via useClass (but not via useExisting):
{
provide: StoreFinderAdapter,
useClass: OccStoreFinderAdapter
}
Therefore OccStoreFinderAdapter is not an injectable and cannot be custom-provided. It was just used as a raw implementation of the abstract StoreFinderAdapter
Note: If StoreFinderAdapter was provided with OccStoreFinderAdapter via useExisting and the OccStoreFinderAdapter was provided itself as an injectable (i.e. in the root injector: @Injectable({providedIn: 'root'})), then your code would work as you expected:
{
provide: OccStoreFinderAdapter,
useClass: ThmOccStoreFinderAdapter
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With