Magento 2, How to get the product SKU quantity displayed on product details page。

enter image description here

  • You are searching for simple product of configurable product, right? – Dhiren Vasoya Apr 10 '17 at 11:49

There is no easy getQty() method on product object.

So you can use two ways.

The unsuggested one which uses object manager:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');
echo $StockState->getStockQty($product->getId(), $product->getStore()->getWebsiteId());

The suggested way:


Keep in mind that you'll load all the stock object which has also min_qty,max_qty, etc properties.

| improve this answer | |
  • I would not suggest to you object Manager from now @Davide – Bhupendra Jadeja Apr 10 '17 at 13:09
  • 1
    @BhupendraJadeja Edited my answer. – dbg Apr 10 '17 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.