Skip to main content
With the $wsLastSeenProducts module, you can dynamically display a customer’s recently viewed products in the frontend. This enables a personalized shopping experience and makes it easier for customers to navigate to items they have already viewed. In this section, you will learn how to load and display recently viewed products.

Module overview

Example / excerpt of $wsLastSeenProducts
{{= $wsLastSeenProducts | json }}
JSON output
{
  "load": "ƒ()"
}
Note: ƒ() denotes a function. Methods overview
MethodReturn typeDescription
load()arrayLoads the list of recently viewed products.

Templates

Recently viewed products can be displayed in any template, but they are usually used on the product detail page. The display can be customized individually, for example as a list, gallery, expandable element at the bottom of the browser window, or as a sidebar element.

Variables

No variables are available for $wsLastSeenProducts.

Methods

$wsLastSeenProducts.load()

Loads the list of recently viewed products. By default, the last 10 products are loaded. Signature
$wsLastSeenProducts.load()
Return value
array - List of product maps.
Example
Example that loads the recently viewed products.
{{ var $lastSeen = $wsLastSeenProducts.load() }}

Actions

No actions are available for $wsLastSeenProducts.

Examples for data access

Check whether products are in the list

In this example, the products are assigned to a variable with $wsLastSeenProducts.load(). If the variable contains data, this means that products are in the list.
{{ var $cLastSeenProducts = $wsLastSeenProducts.load() }}
  {{ if $cLastSeenProducts > 0 }}
    <h2>Recently viewed products</h2>
    ..
  {{ /if }}

Display products

In the following example, the recently viewed products from the variable are loaded in a foreach loop and their product data is displayed.
{{ var $cLastSeenProducts = $wsLastSeenProducts.load() }}
{{ if $cLastSeenProducts > 0 }}
   {{ foreach $cProduct in $cLastSeenProducts }}
      <p>Product name: {{= $cProduct.name }}</p>
      <a href="{{= $wsViews.url('Product', {productId: $cProduct.id}) }}">{{= $cProduct.name }}</a>
      <img src="{{= $cProduct.custom.image.normal }}" alt="...">
   {{ /foreach }}
{{ /if }}