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.

configuration-system-inventory-admin

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.

PlaidCottonShirt

We are done. Happy Coding. Thank you.

Be the first to Know

Subscribe to our blog to get the latest articles directly to your inbox.

READY TO DRIVE SALES?

Request a Quote Today

Request a Quote

Leave a Reply

4 Comments on "How To Display “Only X Left Threshold” Option For Configurable Products in Magento?"


Guest
Prabhu
1 year 3 months ago

Hello ma’am,
It would be helpful if you specify the path or location to place the files you have explained above. Since I’m new to magento it’s difficult for me to understand. Another thing, will this code work on any theme? I’m using VES themes.

Lavanya
Guest
Lavanya
1 year 3 months ago

Hi Prabhu,

Thanks for getting back to us. Here is my reply.

Find the path of the file location:

1. Block File : app/code/local/Dckap/CatalogInventory/Block/Stockqty/Type/Configurable.php
2. Model File : app/code/local/Dckap/CatalogInventory/Model/Stock/Item.php
3. Config File : app/code/local/Dckap/CatalogInventory/etc/config.xml

Enable the module by creating app/etc/dckap_cataloginventory.xml

4. Layout File :

Find the catalog layout file in your active theme and add the CODE… block.
Ex: app/design/frontend/dckap_theme/default/layout/catalog.xml

5. Template File:

Create a file in your active theme template folder and update the template content posted on the blog.
Ex: app/design/frontend/dckap_theme/default/template/cataloginventory/stockqty/composite.phtml

It will work in any theme. According to the theme, you can design this template file. If you want to change the position of the stock qty threshold message then you should change it in catalog product view layout to display accordingly.

Please let us know if you have any further queries.

Kindly subscribe to our blogs. Thanks.

Guest
Prabhu
1 year 2 months ago

Hello ma’am,
I’m glad that you replied. I followed each and every step carefully that you mentioned in the reply. But no effect. Nothing is showing up. Even cleared cache both on back end as well as under var folder in cpanel. No changes. The Module is active under system > configuration > advanced > advanced. The “Only X Left Threshold” is set to 100. Tried echoing some text phrases in the composite.phtml. Didn’t reflect.
I’ve placed the catalog.xml code inside the already existing code block.
I’m doubting that whether the module files are being called. Can you please help me to find the issues.

Lavanya
Author
1 year 2 months ago

Hi Prabhu,

Please make sure the following things are there

1. Module is enabled
2. Catalog.xml code block should be updated in the current theme catalog.xml layout file
For Ex: rwd theme
app\design\frontend\rwd\default\layout\catalog.xml -> updated the layout block here
3. Layout Block file should called in template file.
— composite.phtml is referenced in product.info.configurable.extra. This block should be called in templated file.

Please check the layout file where the product.info.configurable.extra block is rendered and find out the parent block and template (phtml) file.

In rwd theme, product.info.configurable.extra block is a child block and it’s alias name is “product_type_data_extra” and it’s parent block name=”product.info.configurable” as=”product_type_data” and template catalog\product\view\type\default.phtml

For Ex: rwd theme
app\design\frontend\rwd\default\template\catalog\product\view\type\default.phtml and it is having the contents
— echo $this->getChildHtml(‘product_type_data_extra’);
The above will display the composite.phtml contents in product view page.

Thank You