$wsWatchList module, you can access the user’s watchlists (wish lists) and display them in the frontend. You can check whether products are on a watchlist, add or remove products, and display the watchlist in the basket. In this section, you will learn how to load and manage watchlists.
Module overview
Example / excerpt of$wsWatchList
ƒ() denotes a function.
Variables and methods overview
Templates
Watchlist products are loaded via$wsWatchList in the template basket.htm. There they can be added to the basket or removed from the watchlist. Additionally, it is possible to display the watchlist in the header or in the off-canvas flyout.
Variables
$wsWatchList.watchLists
Returns a list of all the user’s watchlists.Methods
$wsWatchList.loadWatchList()
Loads a watchlist by its ID. Signature$wsWatchList.loadWatchList(watchlistId)
Return valuemap - WatchList map with all data.
Parameters
Example that loads the default watchlist.
By using the
$wsWatchList.loadWatchList() function, various variables are available to retrieve and output further watchlist data. Below is an overview of which variables are available.Watchlist data (return value of $wsWatchList.loadWatchList())
First, it is necessary to assign the map with the watchlist data, as shown in the example above, to a local variable. This can then be used at various places in the template. JSON output of the variable:$wsWatchList.isProductOnWatchList()
Checks whether a product is on a specific watchlist. Signature$wsWatchList.isProductOnWatchList(watchlistId, productId)
Return valuebool - true if the product is on the watchlist, otherwise false.
Parameters
Example that checks whether a product is on the watchlist.
$wsWatchList.countWatchListsWithProduct()
Returns the number of watchlists on which a specific product is. Signature$wsWatchList.countWatchListsWithProduct(productId)
Return valueint - Number of watchlists on which the product is.
Parameters
Example that outputs the number of watchlists containing a product:
$wsWatchList.loadWatchListItemId()
Returns the ID of the watchlist item for a specific product. This ID is required to remove the product from the watchlist. Signature$wsWatchList.loadWatchListItemId(watchlistId, productId)
Return valuestring - ID of the watchlist item.
Parameters
Example that loads the entry ID of a product.
