cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the new EventService in composable storefront

Hello experts! In our project we want to use the EventService to detect when an order has been placed in order to redirect the user to our order confirmation page.

const $orderEventSubject = new Subject<MyOrderEvent>;

this.eventService.register(MyOrderEvent, $orderEventSubject);

this.eventService.dispatch(new MyOrderEvent);

We believe this should register the eventService as the source of events and dispatch a MyOrderEvent. Then later in the code we listen for MyOrderEvent on the event service, if such an event is detected we want to use our routingService to redirect the user:

this.eventService.get(MyOrderEvent).subscribe((e) =>{

this.routingService.go('/order-confirmation');

})

For some reason it seems the code inside the subscribe block is never executed. Is this the correct way to use register, dispatch and get on Event Service? Or have we made a mistake somewhere?

The EventService is a new service in composable storefront imported from @spartacus/core.

Marissa
Advisor
Advisor
0 Kudos

Hi,

As this issue is not relevant with SAP S/4HANA public cloud, I removed tag "SAP S/4HANA Cloud front end".

Best regards,

Marissa

Accepted Solutions (0)

Answers (1)

Answers (1)

samuelyang
Product and Topic Expert
Product and Topic Expert
0 Kudos