> ## Documentation Index
> Fetch the complete documentation index at: https://dokumentation.websale.de/llms.txt
> Use this file to discover all available pages before exploring further.

# $wsLastSeenProducts - Recently viewed products

> Reference for $wsLastSeenProducts: display a customer's recently viewed products in the WEBSALE frontend for a personalized shopping experience.

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`

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{= $wsLastSeenProducts | json }}
```

**JSON output**

```json theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{
  "load": "ƒ()"
}
```

**Note:** `ƒ()` denotes a function.

**Methods overview**

| **Method** | **Return type** | **Description**                             |
| ---------- | --------------- | ------------------------------------------- |
| `load()`   | array           | Loads 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.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ 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.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ 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.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ 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 }}
```

***

## Related links

* [\$wsProducts](/en/frontend/referenz/module/wsproducts)
