在 SAP Spartacus 里如何调用 hybris 里实现的自定义 API

需求:We have a custom API created in hybris and I need to use the data returned by that custom API in some Spartacus pages. I want to do this post login and want to call that api whenever the page refreshes. Also I want to maintain the data in a state so that I can use it across the pages. I know how to do it in Angular but I am confused how to do it in Spartacus. Can someone please help me


登录之后调用 api.


页面刷新时调用 api.


答案

You should treat spartacus as external lib. If you know how implement it in Angular, just do it. Most of our actions like login are exported in public API:


import { ActivatedRouterStateSnapshot, AuthActions } from '@spartacus/core';
import { RouterNavigatedAction, ROUTER_NAVIGATED } from '@ngrx/router-store';

@Injectable()
export class YourEffects {

  @Effect()
  yourActionOnLogin$: Observable<YourActions.XXX> = this.actions$.pipe(
    ofType(AuthActions.LOGIN),
    map(() => new CheckoutActions.XXX())
  );

  @Effect()
  yourActionOnNavigation$: Observable<YourActions.YYY> = this.actions$.pipe(
    ofType<RouterNavigatedAction<ActivatedRouterStateSnapshot>>(
      ROUTER_NAVIGATED
    ),
    map(() => new YourActions.YYY())
  );

}

You can create and provide own modules for part of ngrx store and occ adapters (API) as well.

上一篇:项目管理实践【四】Bug跟踪管理【Bug Trace and Management】


下一篇:屌炸天,Oracle 发布了一个全栈虚拟机 GraalVM,支持 Python!