SAP-Spartacus - 自定义事件重新加载触发问题

发布于 2025-01-09 10:29:06 字数 2212 浏览 3 评论 0原文

我创建了自定义事件:

export class DistributorSetEvent extends CxEvent {
  /**
   * Event's type
   */
   static readonly type = 'DistributorSetEvent';
      distributorName!: string;
}

事件生成器:

 export class DpSiteContextEventBuilder {
    constructor(
      protected actionsSubject: ActionsSubject,
      protected eventService: EventService
    ) {
      this.register();
    }
  
    /**
     * Registers the site context events
     */
    protected register(): void {
      this.registerSetDistributor();
    }
  
    /**
     * Register the language set action
     */
    protected registerSetDistributor(): void {
      const DistributorEvent$ = this.actionsSubject.pipe(
        ofType<CustomSiteContextActions.SetActiveDistributor>(
          CustomSiteContextActions.SET_ACTIVE_DISTRIBUTOR
        ),
        map((languageAction) =>
          createFrom(DistributorSetEvent, {
            distributorName: languageAction.payload            
          })
        )
      );
     
  
      this.eventService.register(DistributorSetEvent, DistributorEvent$);
    }
}

我将此配置保留在分发者模块文件中:

backend: {
   loadingScopes: {
      product: {
         details: {
            reloadOn: [DistributorSetEvent]
         },         
      },
   },
}

我在事件更改时保留了此调度:

this.eventService.dispatch(new CustomSiteContextActions.SetActiveDistributor(selectedValue),  
);

错误:

core.js:6498 ERROR TypeError: Cannot read properties of undefined (reading 'getEventMeta')
    at get (spartacus-core.js:4244:28)
    at Array.map (<anonymous>)
    at ProductLoadingService.getProductReloadTriggers (spartacus-core.js:21402:14)
    at ProductLoadingService.getProductForScope (spartacus-core.js:21373:62)
    at ProductLoadingService.initProductScopes (spartacus-core.js:21352:58)
    at ProductLoadingService.get (spartacus-core.js:21343:14)
    at ProductService.get (spartacus-core.js:21471:35)
    at SwitchMapSubscriber.project (spartacus-storefront.js:4086:39)
    at SwitchMapSubscriber._next (switchMap.js:28:1)
    at SwitchMapSubscriber.next (Subscriber.js:49:1)

I have created the custom event :

export class DistributorSetEvent extends CxEvent {
  /**
   * Event's type
   */
   static readonly type = 'DistributorSetEvent';
      distributorName!: string;
}

event builder:

 export class DpSiteContextEventBuilder {
    constructor(
      protected actionsSubject: ActionsSubject,
      protected eventService: EventService
    ) {
      this.register();
    }
  
    /**
     * Registers the site context events
     */
    protected register(): void {
      this.registerSetDistributor();
    }
  
    /**
     * Register the language set action
     */
    protected registerSetDistributor(): void {
      const DistributorEvent$ = this.actionsSubject.pipe(
        ofType<CustomSiteContextActions.SetActiveDistributor>(
          CustomSiteContextActions.SET_ACTIVE_DISTRIBUTOR
        ),
        map((languageAction) =>
          createFrom(DistributorSetEvent, {
            distributorName: languageAction.payload            
          })
        )
      );
     
  
      this.eventService.register(DistributorSetEvent, DistributorEvent$);
    }
}

I kept this config in the distributor module file:

backend: {
   loadingScopes: {
      product: {
         details: {
            reloadOn: [DistributorSetEvent]
         },         
      },
   },
}

I kept this dispatch in on event change:

this.eventService.dispatch(new CustomSiteContextActions.SetActiveDistributor(selectedValue),  
);

Error:

core.js:6498 ERROR TypeError: Cannot read properties of undefined (reading 'getEventMeta')
    at get (spartacus-core.js:4244:28)
    at Array.map (<anonymous>)
    at ProductLoadingService.getProductReloadTriggers (spartacus-core.js:21402:14)
    at ProductLoadingService.getProductForScope (spartacus-core.js:21373:62)
    at ProductLoadingService.initProductScopes (spartacus-core.js:21352:58)
    at ProductLoadingService.get (spartacus-core.js:21343:14)
    at ProductService.get (spartacus-core.js:21471:35)
    at SwitchMapSubscriber.project (spartacus-storefront.js:4086:39)
    at SwitchMapSubscriber._next (switchMap.js:28:1)
    at SwitchMapSubscriber.next (Subscriber.js:49:1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文