What is Salable Quantity in Magento (Adobe Commerce)?

Magento salable quantity (formerly known as Adobe Commerce) is the sum of all products from all your sources. It decreases when an order is placed. However, when somebody cancels an order, products are added back to the salable quantity. In other words, salable quantity reflects the number of items you can sell.

Let’s look at how to get product salable quantity programmatically.

Get Salable Quantity

<?php

namespace Vendor\Extension\Model;

use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;
use Magento\InventorySalesApi\Api\GetProductSalableQtyInterface;
use Magento\InventorySalesApi\Api\StockResolverInterface;
use Magento\Store\Model\StoreManagerInterface;

class GetSalableQtyBySku
{

  /**
    * @var StoreManagerInterface
    */
  private $storeManager;
  /**
    * @var StockResolverInterface
    */
  private $stockResolver;
  /**
    * @var GetProductSalableQtyInterface
    */
  private $getProductSalableQty;

  /**
    * @var array
    */
  private $stockIdCache=[];

  public function __construct(
      StoreManagerInterface $storeManager,
      StockResolverInterface $stockResolver,
      GetProductSalableQtyInterface $getProductSalableQty
  )
  {
      $this->storeManager = $storeManager;
      $this->stockResolver = $stockResolver;
      $this->getProductSalableQty = $getProductSalableQty;
  }

  public function execute($productSku){

      $salableQty=0;
      try {
          $store = $this->storeManager->getStore();
          $stockId = $this->getStockId($store);

          $salableQty = $this->getProductSalableQty->execute($productSku, $stockId);
      }catch (\Exception $exception){
          $salableQty=0;
      }

      return $salableQty;
  }

  private function getStockId($store){

      $websiteCode = $store->getWebsite()->getCode();

      if(!isset($this->stockIdCache[$websiteCode])) {

          $stock = $this->stockResolver->execute(SalesChannelInterface::TYPE_WEBSITE, $websiteCode);
          $stockId = (int)$stock->getStockId();

          $this->stockIdCache[$websiteCode] = $stockId;
      }

      return $this->stockIdCache[$websiteCode];
  }
}

Use the above model class to get salable qty from your Helper class or ViewModel.

Here I have used that model in the Helper class to get product salable qty.

<?php


namespace Vendor\Extension\Helper;

use Magento\Framework\App\Helper\AbstractHelper;

class Data extends AbstractHelper
{
  /**
    * @var \Vendor\Extension\Model\GetSalableQtyBySku
    */
  private $getSalableQtyBySku;

  public function __construct(
      \Vendor\Extension\Model\GetSalableQtyBySku $getSalableQtyBySku
  )
  {
      $this->getSalableQtyBySku = $getSalableQtyBySku;
  }

  public function getSalableQty($productSku){
     
      $salableQty=$this->getSalableQtyBySku->execute($productSku);
      return $salableQty;
  }

}

By calling the helper class you will get salable qty

Output:

25

Please visit the developer documentation to get know more about Magento (Adobe commerce) MSI Here.

Picture of Prabhakaran R
BLOG BY

Prabhakaran R

Prabhakaran R is a Senior Software Engineer at Klizer with seven years of experience in Magento and Adobe Commerce development for ecommerce businesses. His expertise includes B2B commerce, PHP, MySQL, GraphQL, REST APIs, and ERP integration. He holds Adobe Commerce Master and Expert certifications, which reflect deep knowledge of the platform's architecture and best practices. Prabhakaran has a strong interest in exploring new technologies and applying them to client solutions, and his writing focuses on practical Adobe Commerce development and building dependable integrations for B2B stores.

Build Commerce That Scales

Scroll to Top