Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAP Spartacus OccStoreFinderAdapter override

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.

like image 575
Piotr Dziwoki Avatar asked Oct 28 '25 01:10

Piotr Dziwoki


1 Answers

2023-05-15 Update

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.

2021-06-09 Original answer

Solution

{ 
   provide: StoreFinderAdapter,   // not OccStoreFinderAdapter
   useClass: ThmOccStoreFinderAdapter
}

Explanation

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
}
like image 156
Krzysztof Platis Avatar answered Oct 30 '25 14:10

Krzysztof Platis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!