前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SAP Spartacus 使用 customized API

SAP Spartacus 使用 customized API

作者头像
Jerry Wang
发布2021-06-10 15:33:28
3610
发布2021-06-10 15:33:28
举报

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 的例子:

代码语言:javascript
复制
{"quantity": 1, "product": {"code": "1234567"}, "fooBar": false}

为了让这个定制化后的 API 在 Spartacus 里消费,需要完成下列步骤:

  1. 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

  1. 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

  1. Extended CartEntryConnector in E2CartEntryConnector

Modified the add method passing the fooBar parameter to the add method of the E2CartEntryAdapter

  1. Extended CartEntryAdapter in E2CartEntryAdapter

Modified the abstract add method adding the fooBar parameter

  1. Created E2OccCartEntryAdapter that extends OccCartEntryAdapter and implements E2CartEntryAdapter

Modified the add method adding fooBar to the payload of the POST call made from HttpClient

  1. 使用新的 providers:
代码语言:javascript
复制
[
    { provide: ActiveCartService, useClass: E2ActiveCartService },
    { provide: MultiCartService, useClass: E2MultiCartService },
    E2CartEntryEffects,
    { provide: CartEntryConnector, useClass: E2CartEntryConnector },
    { provide: E2CartEntryAdapter, useClass: E2OccCartEntryAdapter },
]
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-06-03 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 场景
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档