public function Order::getLineItems in Ubercart 8.4
Returns an array containing an order's line items ordered by weight.
Return value
array An array of line items, which are arrays containing the following keys:
- line_item_id: The line item id.
- type: The line item type.
- title: The line item title.
- amount: The line item amount.
- weight: The line item weight.
Overrides OrderInterface::getLineItems
1 call to Order::getLineItems()
- Order::getDisplayLineItems in uc_order/
src/ Entity/ Order.php - Returns an order's line items ordered by weight, prepared for display.
File
- uc_order/
src/ Entity/ Order.php, line 219
Class
- Order
- Defines the order entity class.
Namespace
Drupal\uc_order\EntityCode
public function getLineItems() {
$items = [];
$result = \Drupal::database()
->query("SELECT * FROM {uc_order_line_items} WHERE order_id = :id", [
':id' => $this
->id(),
]);
foreach ($result as $row) {
$items[] = [
'line_item_id' => $row->line_item_id,
'type' => $row->type,
'title' => $row->title,
'amount' => $row->amount,
'weight' => $row->weight,
'data' => unserialize($row->data),
];
}
$line_item_manager = \Drupal::service('plugin.manager.uc_order.line_item');
foreach ($line_item_manager
->getDefinitions() as $type) {
if (!$type['stored'] && !$type['display_only']) {
$result = $line_item_manager
->createInstance($type['id'])
->load($this);
if ($result !== FALSE && is_array($result)) {
foreach ($result as $line) {
$items[] = [
'line_item_id' => $line['id'],
'type' => $type['id'],
'title' => $line['title'],
'amount' => $line['amount'],
'weight' => isset($line['weight']) ? $line['weight'] : $type['weight'],
'data' => isset($line['data']) ? $line['data'] : [],
];
}
}
}
}
usort($items, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
return $items;
}