0

I have searched a lot and since I am new to magento I would like your help. I want to display my stock quantity on my product details page. Can someone please give me a step by step configuration including files to modify?

2 Answers 2

0

From the

Admin panel -> Go to -> store -> configuration-> Catalog -> Inventory -> Display Products Availability in Stock on Storefront ->

Select Yes from the dropdown -> Click on save config button !

Clear the cache and check at frontend - it will not display !

Magento 2: Display/Disable Out of Stock Product – Magento 2.3

Stock Options

9
  • getting or not ?? Sep 5, 2019 at 9:58
  • If i do as you instructed i cannot display the product quantity on product page just "In stock". I need my clients to be able to see actual product quantity instead of "In stock". Meaning "In stock (qty)". Sep 5, 2019 at 10:18
  • use custom theme ? Sep 5, 2019 at 10:20
  • Yes i use custom Theme SM Autostore from Magentech. Sep 5, 2019 at 10:21
  • wait let me update answer Sep 5, 2019 at 10:24
0
for total quantity

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

and if you want to get status

$stockItem = $objectManager->get('\Magento\CatalogInventory\Model\Stock\StockItemRepository');
$productId =1; // YOUR PRODUCT ID
$productStock = $stockItem->get($productId);
$data_p = $productStock->getData();
echo $data_p['is_in_stock']; //1 in stock 0 for out of stock


2
  • Can you please instruct me in which file i must edit? Also another thing is not to display negatives. I mean that if stock status in -1 to display 0. Sep 3, 2019 at 13:25
  • vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml or depend on your cutome theme ==> app/design/frontend/Lucenttheme/Inno/Magento_Catalog/templates/product/view/addtocart.phtml or any in view folder depend on your design and your place. thanks Sep 3, 2019 at 13:40

Your Answer

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

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