获取/更新Magento 2中的库存项目

在今天的主题如何获取Magento 2的库存清单中,我将介绍一种简单的方法,当您使用Magento 2后端的代码时,收集库存中所有物料的清单。让我们通过三个步骤来完成它。

Magento 2中的库存清单总览

步骤1:从中收集库存物料 Resource Model

以下代码段是您需要运行的必需命令:

	$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());
	}

步骤2: Resource Model of StockItem

通过该命令,您将Resource Model of StockItem使用$objectManager

步骤3:设定选择查询

通过设置选择查询connection object。然后,您将通过命令从数据库检索数据$select query

三个步骤是在Magento 2中获取库存清单的关键说明。希望您可以在商店中方便地进行操作。

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论