0
votes

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.

1
please try this: { provide: StoreFinderAdapter, useClass: CustomOccStoreFinderAdapter }Weizheng Gao
It does not work this way alsoPiotr Dziwoki

1 Answers

0
votes

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
}