结合销售平面订单和销售平面订单项目的信息 sql Magento
Combine information from sales flat order and sales flat order item sql Magento
要在 table 中获取以下信息,SQL 查询是什么?
订单状态
订单号(增量 ID)
产品名称
产品类别
制造商
价格
杂项发票信息
看起来这个信息在三个 table、sales_flat_order、sales_flat_order_item 和 sales_flat_invoice 中。有什么建议吗?
这样的 SQL 查询是可能的,但那太复杂了。 Magento 的 OOP 允许您使用方法检索这些属性,因此您只需调用适当对象上的 getOrderID() 等即可。
同意@cleong 的观点,您应该使用 Magento 的 ORM 在应用程序中加载此数据,但类似此查询的内容可能对为报告提取数据等有用:
SELECT
sfo.entity_id,
sfo.increment_id,
sfoi.name,
sfoi.product_type,
sfoi.price,
sfoi.original_price,
sfo.status,
sfi.state
FROM
sales_flat_order sfo
INNER JOIN
sales_flat_order_item sfoi ON sfoi.order_id = sfo.entity_id
LEFT JOIN
sales_flat_invoice sfi ON sfi.order_id = sfo.entity_id
ORDER BY
sfo.entity_id DESC
LIMIT
500
您必须调整列以准确获得您想要的内容,值得注意的是,这仅包括可以从订单信息中提取的数据。如果您想返回只能在目录中找到的数据——这可能会有风险,因为旧产品可能不再存在并且通常需要进入 EAV 模型——将需要更多的连接。
要在 table 中获取以下信息,SQL 查询是什么? 订单状态 订单号(增量 ID) 产品名称 产品类别 制造商 价格 杂项发票信息
看起来这个信息在三个 table、sales_flat_order、sales_flat_order_item 和 sales_flat_invoice 中。有什么建议吗?
这样的 SQL 查询是可能的,但那太复杂了。 Magento 的 OOP 允许您使用方法检索这些属性,因此您只需调用适当对象上的 getOrderID() 等即可。
同意@cleong 的观点,您应该使用 Magento 的 ORM 在应用程序中加载此数据,但类似此查询的内容可能对为报告提取数据等有用:
SELECT
sfo.entity_id,
sfo.increment_id,
sfoi.name,
sfoi.product_type,
sfoi.price,
sfoi.original_price,
sfo.status,
sfi.state
FROM
sales_flat_order sfo
INNER JOIN
sales_flat_order_item sfoi ON sfoi.order_id = sfo.entity_id
LEFT JOIN
sales_flat_invoice sfi ON sfi.order_id = sfo.entity_id
ORDER BY
sfo.entity_id DESC
LIMIT
500
您必须调整列以准确获得您想要的内容,值得注意的是,这仅包括可以从订单信息中提取的数据。如果您想返回只能在目录中找到的数据——这可能会有风险,因为旧产品可能不再存在并且通常需要进入 EAV 模型——将需要更多的连接。