0

我使用 ActiveCartService 的“updateEntry”方法来更新购物车的条目。然后触发来自 CartEntryEffects 类的“updateEntry$”效果,返回新的操作。

updateEntry$: Observable = this.actions$.pipe(
    ofType(CartActions.CART_UPDATE_ENTRY),
    map((action: CartActions.CartUpdateEntry) => action.payload),
    concatMap(payload =>
      this.cartEntryConnector
        .update(payload.userId, payload.cartId, payload.entry, payload.qty)
        // should be my logic with payload
        .pipe(
          map(() => {
            return new CartActions.CartUpdateEntrySuccess({
              userId: payload.userId,
              cartId: payload.cartId,
            });
          }),

获取此有效载荷的正确方法是什么?或者我可以覆盖这个效果或添加我的逻辑吗?

4

1 回答 1

0

这取决于您尝试对有效负载执行什么操作。

如果您想在详细信息更新到 Commerce 之前对其进行处理,则通常由连接器和适配器处理。请参阅https://sap.github.io/spartacus-docs/connecting-to-other-systems/

如果你想引用更新的条目并显示它,那么你可以通过 ActiveCartService 获取 Observable。参见例如 AddToCart 组件(https://sap.github.io/spartacus/components/AddToCartComponent.html#source),它声明cartEntry$: Observable<OrderEntry>然后在ngOnInit()this.cartEntry$ = this.activeCartService.getEntry(this.productCode)

于 2020-04-14T11:10:32.097 回答