---
title: "How to Add Available Quantity Per Product in The Catalog On Magento 2.3?"
url: "https://magecomp.com/blog/add-available-quantity-per-product-in-the-catalog-on-magento-2-3/"
date: "2020-05-04T20:08:03+00:00"
modified: "2025-02-20T08:55:34+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 360
reading_time: "2 min read"
summary: "Magento Folks?,"
description: "Follow the given below steps for implementing how can you add the available quantity per product in the catalog on Magento 2.3 with the help of appropriate c..."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Add Tree Mass action Dynamically In Sales Order Grid in Magento 2"
    url: "https://magecomp.com/blog/add-tree-mass-action-dynamically-in-sales-order-grid-in-magento-2/"
  - title: "How to Hide Admin Menu Based on System Config in Magento 2"
    url: "https://magecomp.com/blog/hide-admin-menu-based-on-system-config-magento-2/"
  - title: "How to Fix &#8220;Uncaught Error: Class &#8216;Magento\Setup\Mvc\Bootstrap\InitParamListener&#8217; not found&#8221; Error After Upgrading to Magento 2.4.x?"
    url: "https://magecomp.com/blog/fix-class-magento-setup-mvc-bootstrap-initparamlistener-not-found-error/"
---

# How to Add Available Quantity Per Product in The Catalog On Magento 2.3?

_Published: May 4, 2020_  
_Author: Dhiren Vasoya_  

![](https://magecomp.com/blog/wp-content/uploads/2020/05/How-can-I-add-the-available-quantity-per-product-on-catalog-on-Magento-23-1024x512.webp)

**Magento Folks?,**

What’s going on? Welcome back to the [**How-To serie**s](https://magecomp.com/blog/category/how-to-magento/) where today the illustration will be on How can I add the available quantity per product in the catalog on Magento 2.3? Lastly, I have illustrated to you **[Magento 2: How To Import Products with Custom Product Types](https://magecomp.com/blog/magento-2-import-products-with-custom-product-type/)** with appropriate codes.
Let’s Begin??
[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

## Introduction:
Follow the given below steps for implementing how you can add the available quantity per product in the catalog on Magento 2.3?
## Step 1: Create a block file in the custom extension
```
app/code/[VENDOR]/[EXTENSION]/Block/Product.php
<?php

namespace [VENDOR][EXTENSION]Block;

class Product extends MagentoFrameworkViewElementTemplate
{
    protected $_scopeConfig;
    protected $_stockInterface;
    protected $_productRepository;

    public function __construct(
        MagentoFrameworkViewElementTemplateContext $context,
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        MagentoCatalogInventoryApiStockStateInterface $stockInterface,
        MagentoCatalogModelProductRepository $productRepository
    ){
        $this->_scopeConfig = $scopeConfig;
        $this->_stockInterface = $stockInterface;
        $this->_productRepository = $productRepository;
        parent::__construct($context);
    }

    public function getStockMessage($productId){
        $_product = $this->getProductById($productId);
        $_stock = $this->getStock($_product);
        if($_stock <= $this->getThresoldQty()){
            return __('Only %1 left', $_stock);
        }
        return '';
    }

    public function getProductById($id)
    {
        return $this->_productRepository->getById($id);
    }

    public function getStock($_product)
    {
        return $this->_stockInterface->getStockQty($_product->getId(), $_product->getStore()->getWebsiteId());
    }

    public function getThresoldQty(){
        return $this->_scopeConfig->getValue('cataloginventory/options/stock_threshold_qty', MagentoStoreModelScopeInterface::SCOPE_STORE);
    }
}
```

## [![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-6.webp)](https://magecomp.com/magento-malware-removal.html)

## Step 2: Now add below code in list.phtml
```
$blockObj = $block->getLayout()->createBlock('[VENDOR][EXTENSION]BlockProduct');

Step 3: Now, you can call in the block inside your foreach loop.

<?php echo $blockObj->getStockMessage($_product->getId()); ?>
```

By applying the above-given steps you will be successfully able to add the available quantity per product on the catalog on Magento 2.3
## Final Words:
I hope the above-given solution for adding the available quantity per product in the catalog in Magento 2.3 is helpful for you and if you find any difficulties then you can contact [**MageComp Support** ](https://magecomp.com/support/)for more guidance. And if you like the article then let us know in the comment section below. Don’t forget to share it with your Magento friends and make them more knowledgeable.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-3.webp)](https://magecomp.com/magento-performance-optimization.html)

**Happy Coding?**


---

_View the original post at: [https://magecomp.com/blog/add-available-quantity-per-product-in-the-catalog-on-magento-2-3/](https://magecomp.com/blog/add-available-quantity-per-product-in-the-catalog-on-magento-2-3/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-09 06:44:32 UTC_  
