日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SAP Spartacus 使用 customized API

發布時間:2023/12/19 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的原創文章,盡在:“汪子熙”:

    總結

    以上是生活随笔為你收集整理的SAP Spartacus 使用 customized API的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。