Stock level of a product in hybris

In Hybris, when we deal with products , one of the most important concept to keep in mind is the Stock level of a product.

Whenever we have to make product eligible for adding to a cart, we first need to check whether we have sufficient stock for it or not.

We could see in many ecommerce sites that “Out Of Stock” will be displayed for some products and we will not be able to add that product to cart.

This is where the stock information of a product is useful.

Stock information in Hybris is represented by a term called “Stock level” and we have a separate model for it called “StockLevelModel”

Stock level of a product is the available quantity of the specific product at a certain time.

We need to understand 2 things here

Warehouse stock level : This is the actual stock levels which is typically reported by an inventory (in hybris it is called as warehouse).
Sometimes warehouse is also called as Point of service(POS)

Local stock level : The local stock level is the calculated value within hybris system that is mainly used to keep track of sold product quantities

Note :
While calculating local stock level, we do not know the exact amount that is available in the warehouse at each moment.

In most of the real time scenarios, product stock levels are not updated “instantly” but it may be updated once a day or once a week.

Because of this delay, we might see some difference between the actual stock level and the local (calculated) stock level.

Each warehouse defines a stock for a specific product

We know that store can be associated with many warehouses

The actual stock level of a product can be defined as
Total stock level for all the warehouses where the product is available
In other words, Stock level of a product “X” available in 3 warehouses is defined as

Stock level of X = stock level of Warehouse1 + stock level of Warehouse2 + stock level of Warehouse3

Stock level has many fields in which 2 important fields are
Available – This number indicates total available count for a specific product
Reserved – This number indicates the total count of a product ordered by customer

So, Stock level will always be calculated as

  1. int actualStockAmount = stockLevel.getAvailable() - stockLevel.getReserved();
int actualStockAmount = stockLevel.getAvailable() - stockLevel.getReserved();

Where, stockLevel is the instance of StockLevelModel

This logic has to be looped for all the warehouses. No need to write all this logic as Hybris has already written it and provided StockService API for the same

About the Author

Karibasappa G C (KB)
Founder of
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to

Connect with me on Facebook for more updates

Share this article on