如何在SAP Spartacus category 页面里拿到当前的category信息

需求

https://stackoverflow.com/questions/59950572/how-to-access-the-current-categorydata-in-a-category-page

实现原理

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

(0)

相关推荐