magento2 - 如何从 magento 2 中的表 sales_order_item 获取集合数据?
问题描述
我想从表 sales_order_item 获取数据收集并加入其他表。怎么做?我写了这段代码。
$sale_order = $this->_resource->getTableName('sales_order');
$sale_order_item_table = $this->_resource->getTableName('sales_order_item');
$catalog_category_product_table = $this->_resource->getTableName('catalog_category_product');
$catalog_category_entity_text_table = $this->_resource->getTableName('catalog_category_entity_text');
我想创建集合,但我不知道如何创建正确的 _salesOrderItemCollectionFactory $saleOrderItemCollection = $this->_salesOrderItemCollectionFactory->create();
请帮我?
非常感谢,BienHV
解决方案
我认为您需要使用 getSelect 来创建这样的连接查询,然后使用此查询加载集合。
public function execute()
{
/* @var \Magento\Sales\Model\ResourceModel\Order\Item\Collection $collection*/
$collection = $this->orderItemsCollectionFactory->create();
$joinQuery = $collection->getSelect()
->join(['so' =>'sales_order'],'main_table.order_id = so.entity_id','state');
$result = $collection->load($joinQuery);
return $result->getData();
}
推荐阅读
- java - 如何使用 jgrapht 创建子图
- javascript - 如何从 javascript 文件 insize 脚本标签访问变量?
- javascript - GraphQL - “[用户]”类型的字段“x”必须有一个子字段选择。你的意思是“x{ ... }
- sql - SQLPlus 透视日期列
- xml - XSD 将字符串长度限制为两个值之一?
- c# - 获取当前类的变量名
- git - 我无法从存储库历史记录中删除 Git 大文件
- javascript - 在 React 中上传图像时出现内部服务器错误
- c++ - 在 C++ 中处理复合文字的跨平台方法是什么?
- php - PHP试图从数组中计算变量总数