Black Friday & Cyber Monday - Up to 100% Off Explore

Get / Update Stock Items in Magento 2

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
  • Step 2: Take Resource Model of StockItem
  • Step 3: Set the select query

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

Comments for Get / Update Stock Items in Magento 2

Please leave comments if you have any questions, feedbacks.

Module Development

You also may like these Magento 2 Extensions

One Step Checkout

$199
10 reviews

Layered Navigation

$99
12 reviews

SEO

FREE
no review

Shop By Brand

$99
3 reviews

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