SAP Spartacus 使用 customized API
https://stackoverflow.com/questions/67810796/integrating-customised-apis-in-spartacus-storefront
场景
客户对 addEntry 这个 SAP Hybris API 做了增强,payload 里增加了一个新的 boolean 类型的字段,名为 fooBar.
our Hybris instance has some custom REST APIs, for example the addEntry. This version of the API requires an extra boolean parameter in the payload, let’s call it fooBar. Here’s an example of payload:
Payload 的例子:
{"quantity": 1, "product": {"code": "1234567"}, "fooBar": false}
为了让这个定制化后的 API 在 Spartacus 里消费,需要完成下列步骤:
- Overridden the AddToCartComponent
标准的 active-cart.service.ts 里,addEntry 方法只有两个参数:
Modified the addToCart method passing the fooBar parameter to the addEntry method of the E2ActiveCartService
Extended ActiveCartService in E2ActiveCartService
Modified the addEntry method passing the fooBar parameter to the addEntry method of the E2MultiCartService
Extended MultiCartService in E2MultiCartService
Modified the addEntry method passing the fooBar parameter to the payload of the E2CartAddEntry action
- Implemented a copy of the CartAddEntry action (called E2CartAddEntry) with its own type (i.e. ‘[E2-Cart-entry] Add Entry’)
需要拷贝 CartAddEntry 成一个新的 action:
3.Implemented a new CartEntryEffects (called E2CartEntryEffects) that listens to the E2CartAddEntry action
Created a second effect called processesIncrement$ that dispatches the CartActions.CartProcessesIncrement action (we did this because the E2CartAddEntry cannot extends the EntityProcessesIncrementAction class)
Copied the addEntry$ effect from the original CartEntryEffects adding the fooBar parameter to the add method of the E2CartEntryConnector
- Extended CartEntryConnector in E2CartEntryConnector
Modified the add method passing the fooBar parameter to the add method of the E2CartEntryAdapter
- Extended CartEntryAdapter in E2CartEntryAdapter
Modified the abstract add method adding the fooBar parameter
- Created E2OccCartEntryAdapter that extends OccCartEntryAdapter and implements E2CartEntryAdapter
Modified the add method adding fooBar to the payload of the POST call made from HttpClient
- 使用新的 providers:
[
{ provide: ActiveCartService, useClass: E2ActiveCartService },
{ provide: MultiCartService, useClass: E2MultiCartService },
E2CartEntryEffects,
{ provide: CartEntryConnector, useClass: E2CartEntryConnector },
{ provide: E2CartEntryAdapter, useClass: E2OccCartEntryAdapter },
]
更多Jerry的原创文章,尽在:“汪子熙”:
相关文章
- 166. SAP UI5 OData API 中针对 Edm.DateTime 日期时间类型的操作详解
- 165. SAP UI5 应用如何采取 JavaScript 代码调用 OData API 读取满足过滤条件的业务数据($filter 操作)
- SAP UI5 click list item to navigate to detail page
- SAP UI5关于navigation API的boolean参数
- SAP S4CRM 1811 服务订单API介绍
- 关于 SAP Spartacus SSR 请求 OCC API 遇到 403 错误的解决办法
- SAP 电商云 Spartacus UI ActiveCartService 的 isStable API 里的 EMPTY 操作符
- 如何找到 SAP Spartacus OCC cms page 发送请求时读取 API endpoint 的代码
- 如何自行找出 SAP Spartacus 查询用户信息的 API Service 类
- SAP Spartacus API 的事务处理特性
- SAP Cloud for Customer upselling的前台实现
- 在 SAP Spartacus 里如何调用 hybris 里实现的自定义 API
- 如何通过Restful API的方式读取SAP Commerce Cloud的Product Reference
- 如何在SAP Fiori应用里消费SAP HANA Query view
- 使用SAP CRM BOL API修改One Order的描述信息
- 如何将SAP API Hub 上提供的工作流导入到 SAP BTP 上
- 在 SAP Kyma 上部署一个 Go MSSQL API Endpoint
- 如何在SAP C4C里使用ABSL消费第三方Restful API
- SAP Leonardo Machine Learning处于deprecated状态的API和其替代者
- 使用Java程序消费SAP Leonardo的机器学习API
- SAP UI5 日期类型 sap.ui.model.type.Date 的显示格式问题分析
- SAP 电商云 Spartacus UI 和 SmartEdit 本地测试环境
- 使用自定义 HTTP Interceptor 记录 SAP Spartacus 发送的 OCC API 以及响应