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 里消費,需要完成下列步驟:
標準的 active-cart.service.ts 里,addEntry 方法只有兩個參數(shù):
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
需要拷貝 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
Modified the add method passing the fooBar parameter to the add method of the E2CartEntryAdapter
Modified the abstract add method adding the fooBar parameter
Modified the add method adding fooBar to the payload of the POST call made from HttpClient
更多Jerry的原創(chuàng)文章,盡在:“汪子熙”:
總結(jié)
以上是生活随笔為你收集整理的SAP Spartacus 使用 customized API的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: webAR涉及的技术「建议收藏」
- 下一篇: 区块链如何赋能车联网-Higgs Cha