subscribe(): Promise<TResponseStatus | undefined>¶
The subscribe
method is asynchronous and allows to add a product with a given stock id to the favourites list. To perform this action, user must be logged in. If they are not, an appropriate message will be returned.
Input parameters¶
stockId¶
string
stockId - identifier of the product variant we want to add to the favourites list
Returned value¶
A returned value has a type of Promise<TResponseStatus | undefined>
. Find out more about TResponseStatus type here.
Event Bus events¶
This API method dispatches the following events with the Event Bus:
- addedToFavourites.added - when added a product to favourites
- FlashMessengerApi.addFlashMessage - when handling messages that come from a server
- FlashMessengerApi.addFlashMessages - when handling messages that come from a server
Example¶
In this example we make a AddToFavouritesApi
call to add a product with stockId 5
to the favourites list.
useStorefront(async (storefront) => {
const favouritesApi = await storefront.getApi('AddToFavouritesApi');
await favouritesApi.subscribe(5)
});