get salable quantity use the following code :
namespace Yuvraj\Raulji\ModelName;
use Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku;
class ClassName
{
private $getSalableQuantityDataBySku;
public function __construct(
GetSalableQuantityDataBySku $getSalableQuantityDataBySku
) {
$this->getSalableQuantityDataBySku = $getSalableQuantityDataBySku;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$sku = "YUVI123";
$salable = $this->getSalableQuantityDataBySku->execute($sku);
echo json_encode($salable);
}
}
output as
[{"stock_name":"Default Stock","qty":4,"manage_stock":true}]
We can get the actual quantity of the product by $product->getQty();