spartacus-storefront - SAP Spartacus OccStoreFinderAdapter 覆盖

标签 spartacus-storefront

有什么方法可以覆盖 SAP Spartacus v3.x+ 中的 OccStoreFinderAdapter 类吗?我已经尝试过的是像这样在 store-finder-feature.module.ts 中添加自定义提供程序

{
  provide: OccStoreFinderAdapter,
  useClass: CustomOccStoreFinderAdapter
}

但它仍然使用 OOTB。

最佳答案

解决方案

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

说明

对于 token StoreFinderAdapter,Spartacus OOTB 通过useClass(但不是通过useExisting)传递OccStoreFinderAdapter:

{ 
   provide: StoreFinderAdapter,
   useClass: OccStoreFinderAdapter
}

因此 OccStoreFinderAdapter 不是可注入(inject)的,不能自定义提供。它只是用作抽象 StoreFinderAdapter

的原始实现

注意:如果 StoreFinderAdapter 通过 useExistingOccStoreFinderAdapterOccStoreFinderAdapter 一起提供> 是作为可注入(inject)的提供的(即在根注入(inject)器中:@Injectable({providedIn: 'root'})),那么您的代码将按预期工作:

{ 
   provide: OccStoreFinderAdapter,
   useClass: ThmOccStoreFinderAdapter
}

关于spartacus-storefront - SAP Spartacus OccStoreFinderAdapter 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67904274/

相关文章:

angular - 如何在斯巴达克斯中抑制静态页面的自定义上下文?

spartacus-storefront - SPARTACUS 自定义 SearchboxComponent 服务

angular - 如何在特定版本中安装 Spartacus(和 Angular)

spartacus-storefront - 斯巴达克斯|在导出引用不可用的现有组件中添加一些详细信息的最佳实践

styling - 将 OOTB 样式应用于扩展组件

angular - Spartacus - 从自定义 CMS 组件中检索数据

sap-commerce-cloud - 如何让斯巴达克斯服务器端渲染在负载下执行?

angular - OccAdapters 和 Services 之间的使用差异是什么?

angular - 如何在 Spartacus SSR 中记录 http 请求的时间,即使在 SSR 超时后也是如此