How do we get a list of order items and their data (name, sku, quantity, price, weight, and dimensions)? Without using Magento's own framework components.
The problem is if the order contains 5 products I would get maybe 7 items from querying the table. This is caused by the different product types (simple, group, voucher, configurable, etc.) and different product ids so cannot be combined.
$items = array();
$sql = (
"SELECT oi.name, oi.sku, oi.qty_ordered, oi.price, oi.weight
FROM {$db->prefix}sales_flat_order_item oi
WHERE oi.order_id = ". (int)$order_entity_id .";"
);
if ($result = $mysqli->query($sql)) {
while ($row = $result->fetch_assoc()) {
$items[] = [
'name' => $row['name'],
'sku' => $row['sku'],
'quantity' => (float)$row['qty_ordered'],
'unit_price' => (float)$row['price'],
'unit_weight' => (float)$row['weight'],
//'unit_length' => (float)$row['length'], // Not present?
//'unit_width' => (float)$row['width'], // Not present?
//'unit_height' => (float)$row['height'], // Not present?
];
}
$result->close();
}
If I pass a filter AND product_type = 'simple'
to get only the simple products, they do not contain price.