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
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
-
-
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
-
-
-
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
-
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