Get / Update Stock Items in Magento 2

Magento 2 Get Stock Items will introduce the simple way to collect the list of all your items in the inventory when you work with code from Magento 2 backend.

In topic How to get stock items list Magento 2 today, I will introduce the simple way to collect the list of all your items in the inventory when you work with code from Magento 2 backend. Let’s pass via three steps to complete that.

Overview of getting stock items list in Magento 2

Step 1: Collection stock item from Resource Model

The below code snippet is the required command you need to run:

	$resource = $objectManager->create('Magento\CatalogInventory\Model\ResourceModel\Stock\Item');
	$select = $resource->getConnection()->select()->from($resource->getMainTable());
	$stockItems = $resource->getConnection()->fetchAll($select);
	foreach($stockItems as $_item){
		var_dump($_item->getData());
	}

Step 2: Take Resource Model of StockItem

By that command, you will take Resource Model of StockItem by using $objectManager

Step 3: Set the select query

Set the select query via connection object. Then you will retrieve the data from the database by the command $select query.

Three steps are the crucial instructions to get the stock item list in Magento 2. I hope you will manipulate them conveniently on your store.

Enjoyed the tutorial? Spread it to your friends!

magento-2-tutorial
how-to
get
stock
items
list
featured

Sam Thomas
Sam Thomas

CEO and Founder of Mageplaza. Pursueing a simple and healthy lifestyle. A friend, a husband and a dad of two children, a trainer and a wanna-be influencer. He is a big fan of sports and travel, also.

People also searched for

  • magento 2 how to get stock items list
  • magento 2 get out of stock items
  • magento 2 get in stock items
  • magento 2 get stock items
  • how to get out of stock items in magento 2
  • magento 2 get product quantity
  • magento 2 get product stock status
  • magento 2 get product stock quantity
  • magento 2 get product qty
  • magento 2 update product stock programmatically
  • magento 2 get product stock item
  • magento 2 get stock qty
  • magento 2 update stock programmaticall
  • 2.2.x, 2.3.x