如何在SAP Spartacus category 頁面裡拿到當前的category資訊

注销發表於2021-04-06

需求

https://stackoverflow.com/que...

實現原理

AFAIK, currently we do not have anything similar to CurrentProductService for current category.

當前 SAP Spartacus 標準實現裡,缺乏類似 CurrentProductService 對產品明細頁面那樣的支援。

Looking at the implementation of CurrentProductService you can see that it is using RoutingService and it's getRouterState() method (picture 1).

研究 CurrentProductService 的實現程式碼,發現其實現原理是,首先利用 RoutingService,從 RouterState 中拿到當前頁面的產品code,然後使用另一個API,productService, 來讀取產品的明細資料。

You can create something similar for current category, because the router state consists of category informations (as seen below on picture 2).

因此我們可以採取類似的思路,從 category 頁面的State裡,提取出category明細資訊:

  • categoryCode
  • param0, param1, param2

更多Jerry的原創文章,盡在:"汪子熙":

相關文章