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,

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

  • Yes, it's working! :) – n00bly Nov 13 '18 at 14:07
  • great @n00bly happy coding :) – Ramkishan Suthar Nov 13 '18 at 14:12

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.