Favorite Lists

A favorite list is a collection of products explicitly saved by a user or a group of users – typically to save a product for later or as a public wish list. Favorite lists can be created and managed from frontend by users interacting with the Customer Center app – or from the backend using the Favorite Lists node (Figure 1.1).

Figure 1.1 The Favorite List node

To create a favorite list from the backend:

  • Navigate to either Favorites for users or Favorites for groups
  • Click Add in the toolbar
  • Enter a Name and select a user/user group this list should be active for

If the favorite list is for a single user, it may be marked as the Default favorite list – many tags relate only to the default favorite list, and setups with a single and default favorite list are somewhat easier to build & maintain.

Products may be added to a favorite list from either the backend or from. To add a product to a favorite list from the backend:

  • Navigate to either Favorites for users or Favorites for groups and open the favorite list
  • Click Add product in the toolbar and select one or more products – or Add by SKU to enter a list of ProductNumbers or ProductIDs
  • Click Save and close

In most cases, however, you want to make it possible for your registered users to add and remove products from their favorite lists by themselves. In that case, you can use a list of tags and loops to render Add to/Remove from favorites buttons – or something equivalent.

Here is an example to use inside a Products loop in a standard product list template:

RAZOR
<table style="width:100%;border: 1px solid black;"> <tr style="border: 1px solid black;"> <th>FAVORITE LISTS</th> <th></th> <th></th> </tr> <tr> <td>IsProductInFavoriteList?</td> <td>@product.GetBoolean("Ecom:Product.IsProductInFavoriteList")</td> <td></td> </tr> <tr> <td>IsProductInDefaultList?</td> <td>@product.GetBoolean("Ecom:Product.IsProductInDefaultList")</td> @if (@product.GetBoolean("Ecom:Product.IsProductInDefaultList") == true) { <td><a href='@product.GetString("Ecom:Product.RemoveFromList")'>Remove<a/></td> } else { <td><a href='@product.GetString("Ecom:Product.AddToList")'>Add<a/></td> } </tr> <tr style="border-top: 1px solid black;"> <th><b>List</b></th> <th><b>IsDefaultList</b></th> <th><b>On List</b></th> </tr> @foreach (var listtype in @product.GetLoop("CustomerCenter.ListTypes")) { foreach (var productlist in @listtype.GetLoop("CustomerCenter.ProductLists")) { <tr> <td>@productlist.GetString("Ecom:CustomerCenter.ListTypes.List.Name")</td> <td>@productlist.GetBoolean("Ecom:CustomerCenter.List.IsDefault")</td> @if (productlist.GetBoolean("Ecom:Product.List.IsProductInThisList") == false) { <td>No – <a href='@productlist.GetString("Ecom:Product.AddToThisListAction")'>Add</a></td> } else { <td>Yes – <a href='@productlist.GetString("Ecom:Product.RemoveFromThisList")'>Remove</a></td> } </tr> } } </table>

This code example checks some basic properties of each product – whether it is in a favorite list or not, whether it is in the Default list or not. In the second part of the example we loop through all favorite lists belonging to the logged in users and render an appropriate add/remove link for each.

Registered users can view and manager their favorite lists via the Customer Center app – using the sections called My Lists. In broad terms you must:

  • Add a favorites list section to the Customer Center menu layout template
  • Render favorites lists and list details using the My List and My List details templates

To show a favorite list to anonymous users you should also:

  • Create a page for showing a favorite list to someone and add the Show List app to it
  • In the Customer Center, select his page as the Public List page in the Links section

The Show List app is a very simple app – it consists of a template for rendering a favorite list to anonymous users. The context is set by adding a PublishID parameter to the query string when linking people to the page, e.g. /ecommerce/show-list-app?PublishedID=Q1wFhUp5iN – the PublishID value is autogenerated when a favorite list is created and is available from the favorite list templates in the customer center.

Of course, there’s a template tag which does all this for you - Ecom:CustomerCenter.List.PublicURL.

Both Customer Center templates also contain tags for emailing a favorite list to someone – the layout and content of this email is controlled using the My List Email Settings (Figure 3.1).

Figure 3.1 The My List email settings
database

These are the database tables associated with Favorite Lists:

EcomCustomerFavoriteLists

Links favorite lists (Id) with users (AccessUserId).

Field name Data type Length
Id int 4
AccessUserId int 4
Name nvarchar 255
IsPublished bit 1
PublishedToDate datetime 8
Type nvarchar 255
IsDefault bit 1
Description nvarchar Max
PublishedId nvarchar 255
IsShared bit 1

EcomCustomerFavoriteProducts

Links favorite lists (FavoriteListId) with products (ProductId, ProductLanguageId, ProductVariantId).

Field name Data type Length
FavoriteListId int 4
ProductId nvarchar 30
ProductLanguageId nvarchar 50
ProductVariantId nvarchar 255
Note nvarchar Max
ProductReferenceUrl nvarchar Max
CustomerFavoriteProductAutoId int 4
Quantity int 4
SortOrder int 4