You are here

public function Order::getDisplayLineItems in Ubercart 8.4

Returns an order's line items ordered by weight, prepared for display.

Return value

array An array of line items, which are arrays containing the following keys:

  • type: The line item type.
  • title: The line item title.
  • amount: The line item amount.
  • weight: The line item weight.

Overrides OrderInterface::getDisplayLineItems

File

uc_order/src/Entity/Order.php, line 261

Class

Order
Defines the order entity class.

Namespace

Drupal\uc_order\Entity

Code

public function getDisplayLineItems() {
  $line_items = $this
    ->getLineItems();
  $line_item_manager = \Drupal::service('plugin.manager.uc_order.line_item');
  foreach ($line_item_manager
    ->getDefinitions() as $item) {
    if ($item['display_only']) {
      $result = $line_item_manager
        ->createInstance($item['id'])
        ->display($this);
      if (is_array($result)) {
        foreach ($result as $line) {
          $line_items[] = [
            'line_item_id' => $line['id'],
            'type' => $item['id'],
            'title' => $line['title'],
            'amount' => $line['amount'],
            'weight' => isset($line['weight']) ? $line['weight'] : $item['weight'],
            'data' => isset($line['data']) ? $line['data'] : [],
          ];
        }
      }
    }
  }
  foreach ($line_items as &$item) {
    $item['formatted_amount'] = uc_currency_format($item['amount']);
  }
  usort($line_items, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
  return $line_items;
}