Magento 2 is the best platform for enterprise-level businesses that are looking to enter in to the eCommerce realm. Take a look at our Magento Services we have in store for you.
‘Only few items left in stock‘ is a very powerful statement as it instills in the buyer an urgency to complete the purchase immediately. So, displaying this phrase beside the product is important as it nudges the buyer to make the next move in the buyer’s journey.
Magento provides a default option to display the ‘stocks left’ in the front end. This option is available as ‘Only X left threshold‘ (System -> Configuration -> Catalog -> Inventory). This option is used to alert the user that there are only limited products available for purchase.
By default, we can use the above option for simple products since we maintain the inventory for simple products.
On the other hand, most of the eCommerce companies do not maintain inventory stock for configurable products. But it will be a great value addition to sales , if we can display “Only X Left Threshold” option for configurable products in Magento.
How To Display “Only X Left Threshold” Option For Configurable Products in Magento?
To begin, if we want to use the threshold left option for configurable products, then the System -> Configuration -> Catalog -> Inventory -> Stock Options -> Only X Left Threshold -> Should be filled with required number.
And then the following steps are required to display the threshold quantity left option (Stocks left) for configurable products in order to show the simple products left out count.
1. First, extend the stock quantity type configurable block to rewrite the function isMsgVisible which is important to check the stock qty and availability left out.
2. Override the stock quantity item model to include the getStockQtyForCompositeProducts function which will return the least stock quantity of the product among the simple products of the configurable product
3. Module config file will contain the following content
4. And then update the catalog.xml layout file in the current theme to display the availability of the product.
5. The template should have the below content to display the simple products quantity left out option.
We are done. Happy Coding. Thank you.