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 里消费,需要完成下列步骤:

  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:
[{ provide: ActiveCartService, useClass: E2ActiveCartService },{ provide: MultiCartService, useClass: E2MultiCartService },E2CartEntryEffects,{ provide: CartEntryConnector, useClass: E2CartEntryConnector },{ provide: E2CartEntryAdapter, useClass: E2OccCartEntryAdapter },
]

更多Jerry的原创文章,尽在:“汪子熙”:

SAP Spartacus 使用 customized API相关推荐

  1. 如何打印出 SAP Spartacus 调用 OCC API 消费的所有 endpoint

    本文写作的 SAP Spartacus 版本:3.3.0. 直接修改这个文件: node_modules@spartacus\core_ivy_ngcc_\fesm2015\spartacus-cor ...

  2. SAP Spartacus 如何使用 API 从浏览器 local Storage 读取数据

    如下图所示,SAP 电商云 UI,用户的购物车 ID,持久化在浏览器的 local storage 里: 运行时,通过封装好的函数 getStorage 读取: 为什么会触发 State module ...

  3. 如何自行找出 SAP Spartacus 查询用户信息的 API Service 类

    成功登录 SAP Spartacus 之后,在 Chrome 开发者工具 Network tab 里能看到一条读取用户信息的网络请求: https://20.83.184.244:9002/occ/v ...

  4. SAP Commerce Cloud WCMS 里的 home 页面和 SAP Spartacus Page API 返回的数据比较

    You can only create new components in the WCMS Page View perspective. In the Live Edit perspective, ...

  5. SAP Spartacus public API的概念 - index.ts

    看一个具体的例子: https://github.com/SAP/spartacus/issues/11730 backport of #11744 to maintanance branch As ...

  6. 关于SAP Spartacus在服务器端渲染模式和SAP Commerce Cloud API白名单的问题

    We are configuring our Spartacus application with SSR in SAP Commerce Cloud. Also we used the IP Fil ...

  7. SAP Spartacus 懒加载 Customized CMS Component 的问题

    Lazy-loaded overriden or custom CMS Components SAP Spartacus 有两种 lazy load 方式: CMS-driven lazy loadi ...

  8. 自定义SAP Spartacus的产品搜索API参数 - Product Search

    SAP Spartacus默认采用的产品搜索url配置在这个文件里: C:\Code\SPA\spartacus\projects\core\src\occ\adapters\product\defa ...

  9. SAP Spartacus的产品搜索API

    SAP Spartacus里点击Shop app digital cameras: url:http://localhost:4200/electronics-spa/en/USD/Open-Cata ...

最新文章

  1. Cisco交换机路由器的部分命令解析(3)
  2. 429 too many requests错误出现在wordpress后台更新及官网的5种解决方法
  3. 深度学习框架TensorFlow(2.创建图,启动图)
  4. 51nod 1632 B君的连通
  5. leetcode 174. Dungeon Game | 174. 地下城游戏(暴力递归->傻缓存->dp)
  6. 爱数应用容灾部署方案三
  7. CF1067E Random Forest Rank(树形dp,概率与期望,线性代数)
  8. php atlas,apache atlas是什么
  9. 在ASP.NET 3.5中使用新的ListView控件(3)
  10. Python中RowIOBase详解
  11. 苹果发布iOS 12.3.1正式版:更有效的屏蔽垃圾短信
  12. linux下网络包分析工具下载,Wireshark下载-网络封包分析工具 v3.2.6 官方版 - 下载吧...
  13. Unity 3D开发-C#脚本语言的一些基础用法
  14. java构造器_Java入门第十三课:“如何使用构造器初始化对象?”
  15. 群晖NAS详细教程 DSM6.1.7版本(亲测有效)传统BIOS
  16. 财务自由,整层楼沸腾!万亿蚂蚁IPO来了,诞生几千个亿万富翁?杭州、上海房价又要涨了…...
  17. 解决电脑关机状态下按键盘会开机的问题
  18. python操作excel编号自增加1
  19. 黄牛落泪!全球显卡价格纷纷跳水,高价囤货滞销
  20. linux中524端口,liunx下攻击分析及如何通过交换机封端口

热门文章

  1. 【云计算的1024种玩法】云端打造家庭文件备份中心
  2. 用vue实现模态框组件
  3. swift_通知的使用
  4. Python中的条件选择和循环语句
  5. Spark入门实战系列--2.Spark编译与部署(下)--Spark编译安装
  6. CSS 选择器优先级与效率优化
  7. Eclipse高亮显示选中的变量
  8. PowerDesigner 16安装注意事项
  9. Linux系统下Configure命令参数解释说明
  10. 设计模式--责任链模式(COR)