Skip to main content
The $wsStore module is a key-value store for the frontend. Through it, arbitrary data can be stored under a freely chosen key, read out again later, or deleted in a targeted way. It is the right tool wherever you need information that the shop system does not provide by default.

Module overview

Example / excerpt of $wsStore
JSON output
Note: "ƒ()" denotes a function. Methods overview

Methods

$wsStore.set()

Stores an arbitrary value under a key. The value can later be retrieved via get() . Optionally, a validity duration (ttl) can be specified in seconds, after which the entry is automatically removed. Without ttl, a default value of 365 days applies. Signature
$wsStore.set(key, value, ttl)

Return value

Parameters Example - Set a session marker so that a product view is counted only once per visitor To implement the display “X times viewed in the last 24 hours” on the product page, you must prevent the same visitor from falsifying the counter by repeatedly reloading the page. To do this, a marker is set per visitor – as long as this marker exists, the product view is not counted again for this visitor. $wsSession.id is the unique session ID of the current visitor. It is automatically provided by the shop system and does not have to be assigned manually. 14400 seconds equal 4 hours – the marker is valid for this long.
Result
From the time of setting, $wsStore.get('productViewSession-<ProductID><SessionID>') returns the value true for 4 hours. The actual counter that outputs the display “X times viewed in the last 24 hours” to the visitor is maintained via increment(). Only after the 4 hours have elapsed may the same visitor’s product view flow into the counter again.

$wsStore.get()

Returns the value that was previously stored with set() under the specified key. If no entry exists or the entry has expired, null is returned. Signature
$wsStore.get(key)
Return value
any - The stored value, or null, if no entry exists or the entry has expired.
Parameters Example - Display “X times viewed in the last 24 hours” on the product page To output to the visitor on a product detail page a display like “X times viewed in the last 24 hours”, the value previously incremented with increment() is read out. If no entry exists yet (because the product has not yet been viewed in the last 24 hours), get() returns null and the display is skipped.
Result, if $productViews contains the value 10

$wsStore.delete()

Deletes the entry for the specified key from the store. After deletion, get() returns null for this key. Signature
$wsStore.delete(key)

Return value\

Parameters

$wsStore.increment()

Increments a counter value under the specified key by the specified amount. If the key does not yet exist, it is created with the value of amount. This method should be preferred over a combination of get() and set() when a counter is to be incremented.

This is because get() and set() perform the increment in two steps - first read the current value, then store the incremented value. If two visitors open the page at the same time, both read the same value in step 1, for example 5. Both then store 6. The counter ends up at 6 even though it should be at 7.
With increment(), reading and incrementing happen in a single step, so both calls are counted correctly. Signature
$wsStore.increment(key, amount, ttl)
Parameters Example - Count product views, once per session The goal is to display “X times viewed in the last 24 hours” on the product page. So that the same visitor does not falsify the counter by repeatedly reloading, a marker is additionally set per session that prevents the same visitor from counting the product multiple times. $wsSession.id is the unique session ID of the current visitor. It is automatically provided by the shop system and does not have to be assigned manually.
Result
The counter productViews-<ProductID> is incremented at most once every 4 hours per visitor. The subsequent display with get() shows the visitor for example: “7 times viewed in the last 24 hours”. After 24 hours, the counter automatically restarts at zero.