1

I need to get the stock quantity on the product detail page. I'm not an expert in Magento but I was being told that using the objectmanager is not a good idea, but in almost every example I find I see the use of the objectmanager.

Is there somehow another way to get the stock quantity on the product detail page?

Regards,

1 Answer 1

2

You can get stock qty on product details page using below code.

$stockItem = $product->getExtensionAttributes()->getStockItem();
print_r($stockItem->getQty()); 

Let me know if I you need further help

2
  • Yes, it's working! :)
    – n00bly
    Commented Nov 13, 2018 at 14:07
  • great @n00bly happy coding :) Commented Nov 13, 2018 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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