$wsInventory module, you can access stock levels and product availability. Typical use cases are traffic-light displays (green/yellow/red), availability checks on product pages, or reservation times in the basket. In this section, you will learn how to load and display stock data.
Module overview
Example / excerpt of$wsInventory
"ƒ()" denotes a function.
Methods overview
| Method | Return type | Description |
|---|---|---|
load() | map | Loads the stock data of a product. |
loadReservation() | map | Loads the reservation data of a basket item. |
Templates
Typically, information on stock levels and availability is loaded together with the products – for example on the home page, the category list, the search results, or in the basket.Variables
No direct variables are available for$wsInventory. The data is loaded via methods.
Methods
$wsInventory.load()
Loads the stock data of a product. Signature$wsInventory.load(productId)
Return valuemap - Map with stock data.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
productId | string | yes | ID of the product |
By using the
$wsInventory.load() function, various variables are available to retrieve and output stock data. Below is an overview of which variables are available.Stock data (return value of $wsInventory.load() )First, it is necessary to assign the map with the stock data, as shown in the example above, to a local variable. This can then be used at various places in the template.Stock data overview| Variable | Type | Description |
|---|---|---|
active | bool | true if stock management is active for this product. |
amount | int | Available quantity. |
deliveryText | string | Delivery status text (e.g. “Only a few items in stock”). |
messageLimit | int | Quantity from which the notice text (deliveryText) is displayed. |
soldOut | bool | true if the product is sold out. |
splitDelivery | bool | true if the product can also be ordered with partial deliveries (e.g. when the quantity is not fully available). |
state | string | Traffic light status of availability: green (sufficient stock), yellow (few items), red (sold out or very scarce). |
storage | string | Optional parameter Used in connection with the store finder and/or Click & Collect to specifically include the stock of a specific store in the availability check. StorageID (stock ID) to consider store stocks in the store finder or for Click & Collect. If the parameter is specified, the quantities of the specified store are taken into account in addition to the regular stock in the availability/stock check (e.g. “available in store”). If the parameter is not specified, only the stock of the current subshop is loaded – as before (same behavior as before, no template adjustments required). |
$wsInventory.loadReservation()
Loads the reservation data of a basket item. Signature$wsInventory.loadReservation(basketItemId)
Return valuemap - Reservation data with the following attributes:
| Attribute | Type | Description |
|---|---|---|
duration | int | Remaining reservation time in seconds. |
| Name | Type | Required | Description |
|---|---|---|---|
basketItemId | string | yes | ID of the basket item. |
Actions
No actions are available for$wsInventory.
