Stock
Overview of the main stock classes
classDiagram
direction BT
class ProductStock {
InStock
Reserved
}
class ProductVariant {
ProductVariantId
Name
Fields
}
class Product {
Id
Url
Images
Videos
Files
Breadcrumbs
Fields
}
ProductVariant --> ProductStock
Product "1" --o "1..n" ProductVariant
ProductStock
has a field InStock
that holds the last stock value
received from whatever integration provices the stock values.
The other field, Reserved
, is how many we sold in the webshop since
the last time we received the stock value.
So in order to get the available stock you have to do the following
calculation: InStock - Reserved
.
When we syncronize stock values we set the Reserved
back to 0.
This design with a reserved stock value protects the webshop from overselling products without throwing away information about the last received stock value.
Backend and frontend functionality
Stock status is displayed in a number of pages incl. PLP, PDP, Basket, Checkout. All the backend APIs supporting these pages return stock levels.
In the frontend we display a "traffic light" for these three stock levels:
- In stock - green.
- Few in stock - yellow.
- Out of stock - red.
Less than 10 in stock triggers the "few in stock". The specific number of products for each level is currently hardcoded. But this can easily be moved to a config or the product category or product in the PIM.