Skip to main content
10 votes

How to get product stock status on the listing page in Magento 2?

You can try the following code public function __construct( \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry ) { $this->stockRegistry = $stockRegistry; } // you can pass $...
Mohit Rane's user avatar
  • 1,965
10 votes
Accepted

Downloadable product on Magento 2.3.1 out of stock issue

In our case the issue was related to a migration from Magento 1 to Magento 2 via migration data tool. The problem is that default value for the attribute 'links_exist' is 0 in Magento 1. However in ...
mbernt - mediarox's user avatar
9 votes

How to get product stock status on the listing page in Magento 2?

If you are using the only simple products in your system then using the Stock Status field check then Product status is Ok. But when you have a configurable or bundle or group product then it is not ...
Amit Bera's user avatar
  • 77.6k
7 votes
Accepted

How to add Stock Status(default attribute) column in admin product grid Magento 2?

Try following way: For M 2.2 SR/Stackexchange/view/adminhtml/ui_component/product_listing.xml <?xml version="1.0" encoding="UTF-8"?> <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
Sohel Rana's user avatar
  • 35.9k
6 votes
Accepted

Magento 2: Get Product Stock status details in Rest API

You can get product stock status from here : /V1/stockItems/:productSku API Response : { "item_id": 1, "product_id": 1, "stock_id": 1, "qty": 100, "is_in_stock": true, "...
Rohan Hapani's user avatar
  • 17.4k
6 votes
Accepted

Magento 2: Rest API add "stock_item" in to the list of the products

Magento2 does not suggest to add stock info to listing Api a MSI add to 2.3 version. But if you want don't use MSI to your system then you can below solution 1.Create di.xml at your app/code/...
Amit Bera's user avatar
  • 77.6k
5 votes
Accepted

Magento 2: Product stock status is not automatically updated from Out of Stock to In Stock

I have fixed the issue of product stock status update from Out of Stock to In Stock. Fixed the issue to override module-catalog-inventory/Model/Stock/StockItemRepository.php file. Follow below steps ...
Kirti Nariya's user avatar
  • 3,051
5 votes

How to display stock information on product page?

you can check product is in stock via below code $stockItem = $product->getStockItem(); if ($stockItem->getIsInStock()) { //in stock! } else { //not in stock! }
Murtuza Zabuawala's user avatar
4 votes

magento 2 how to update stock using import csv

In order to update stock in Magento 2 using csv, for most scenarios, you will only need to include 'sku' and 'qty' columns. However, I am assuming for the products in question you already have stock ...
JohnHughes1984's user avatar
4 votes
Accepted

How to display stock information on product page?

To display the "out of stock" and "in stock" label on product view page, write the below code in the file app/design/frontend/rwd/default/template/catalog/product/view.phtml <?php $stock = ...
Manashvi Birla's user avatar
4 votes
Accepted

Magento2 set "in stock" when programmatically update qty

Try following code: $product->setQuantityAndStockStatus(['qty' => $qty, 'is_in_stock' => (bool)$qty]); OR $stockItem->setQty($qty); $stockItem->setIsInStock((bool)$qty);
Pratik Oza's user avatar
  • 3,992
4 votes
Accepted

Can't getStockItem magento 2.3.1

Try using this \Magento\CatalogInventory\Api\StockRegistryInterface Update your code with the following code namespace Vendor\Extension\Block\Product; use Magento\Framework\View\Element\Template; ...
Mohit Rane's user avatar
  • 1,965
4 votes

How to get product stock status on the listing page in Magento 2?

Inject \Magento\CatalogInventory\Model\Stock\StockItemRepository $stockItemRepository, in constructor e.g: protected $_stockItemRepository; public function __construct( \Magento\...
Sameer Bhayani's user avatar
3 votes

How to get all products with Qty in magento2

Instead of using Object Manager, use dependency structure for good practise. /** * @var \Magento\Framework\View\Result\PageFactory */ protected $productFactory; public function __construct( .......
Rohan Hapani's user avatar
  • 17.4k
3 votes
Accepted

How can I add different stock labels

You should create a custom module to solve your problem. And then you can create a plugin to add more stock option by do following steps: app/code/YourVendor/YourModule/etc/di.xml <type ...
bachlee89's user avatar
  • 1,287
3 votes

How to get product stock status on the listing page in Magento 2?

Note:- Object Manager is not recommended way. You can inject class in your constructor this way <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $...
Limbani Himanshu's user avatar
3 votes
Accepted

How to update product qty and Stock Status update programmatically by product id : Magento 2

You can use below sample code $product->setStockData(['qty' => $yourQty, 'is_in_stock' => 1]); $product->setQuantityAndStockStatus(['qty' => $yourQty, 'is_in_stock' => 1]); $product-...
Narayan Jat's user avatar
2 votes
Accepted

Magento 1.9 Update stock product status with sql query

try this query, in will prevent product appears on the website searching result and although product page can be accessed on the frontend by url, it cannot be added to cart : $query = "UPDATE ...
mrfizh's user avatar
  • 1,363
2 votes

How to display available quantity of each product in Magento 2

to Show quantity on listing page and quick show pop you there are 2 methods either create your custom module and call its block on both places or add code directly using $ObjectManager. This method ...
Naveed Asim's user avatar
  • 3,657
2 votes
Accepted

How to get disable products in product collection in magento2.2

In magento 2.2, I have also faced this problem and it looks like bug to me but still we can use a workaround of using 'getPart' & 'setPart' functions to alter the load query of collection. Note: ...
Sarvagya's user avatar
  • 1,217
2 votes

How to display stock information on product page?

Get the stock details in magento using below lines. $stockItem = Mage::getModel('cataloginventory/stock_item') ->loadByProduct($productId); print_r($stockItem);
Divya Sekar's user avatar
  • 1,485
2 votes
Accepted

Magento 2: Get Product Stock status details in Category List Product details Rest API

I have added stock_item in Category List Product details Rest API. Update ExtensionPool data of Magento\Catalog\Api\Data\ProductInterface and add stock_item data provider. File path: magento\app\...
Kirti Nariya's user avatar
  • 3,051
2 votes

How to load stock item using product_id in Magento 2?

You need to inject \Magento\CatalogInventory\Api\StockRegistryInterface in your file : protected $stockRepository; public function __construct( \Magento\CatalogInventory\Api\...
Rohan Hapani's user avatar
  • 17.4k
2 votes

How to load stock item using product_id in Magento 2?

Below script helpful to get stock data using object manager $productId = 1; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productStockObj = $objectManager->get('Magento\...
Pradip Garchar's user avatar
2 votes
Accepted

How to automatically change the status to In Stock if products are added to the product

I assume you know the necessary files for creating a module, one all basic files generated, create below files: Vendor/Module/etc/events.xml <?xml version="1.0" ?> <config xmlns:...
Natha Odedara's user avatar
2 votes
Accepted

Magento 2.4.3 - Green and red light for in stock and out of stock

It can be done by CSS .stock.available::after { width: 15px; height: 15px; border-radius: 50%; background-color: green; display: inline-block; content: open-quote; } Same can ...
Pawan's user avatar
  • 5,906
1 vote
Accepted

Magento 1.9 - how to get single product stock data by id?

if you load the product like $product = Mage::getModel('catalog/product')->load($id);, to get the qty available for the product, you can do $qty = $product->getStockItem()->getQty(); and to ...
Herve Tribouilloy's user avatar
1 vote
Accepted

How to get all products with Qty in magento2

you can get all products with qty using below code <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productCollection = $objectManager->create('Magento\...
Rakesh Donga's user avatar
  • 5,364
1 vote

How to display stock information to logged in customer only in Magento 2?

Something like: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->get('Magento\Customer\Model\Session'); if($customerSession->...
BartZalas's user avatar
  • 1,757
1 vote

Magento 2 Possible to make Stock Status working for storeviews?

Magento 2.3 comes up with new MSI feature, so now you can maintain stock status based on store views. Check the release notes and upgrade your magento 2.x to 2.3
Quasar M's user avatar
  • 409

Only top scored, non community-wiki answers of a minimum length are eligible