You are here

function uc_order_load_line_items in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_order/uc_order.module \uc_order_load_line_items()
  2. 6.2 uc_order/uc_order.module \uc_order_load_line_items()

Returns an array containing an order's line items ordered by weight.

Parameters

$order: An order object whose line items are to be loaded.

$stored: Boolean flag. If TRUE, only line items stored in the database are loaded. If FALSE, only line items not stored in the database are loaded. This distinction is made because the non-stored line items may depend on the amounts of all of the stored line items.

Return value

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.
11 calls to uc_order_load_line_items()
UbercartCartCheckoutTestCase::createOrder in uc_cart/tests/uc_cart.test
Creates a new order.
UbercartCreditCardTestCase::createOrder in payment/uc_credit/tests/uc_credit.test
Helper function. Creates a new order.
UcOrderController::attachLoad in uc_order/uc_order.controller.inc
Attaches data to entities upon loading.
uc_cart_checkout_form in uc_cart/uc_cart.pages.inc
The checkout form built up from the enabled checkout panes.
uc_cart_checkout_form_validate in uc_cart/uc_cart.pages.inc
Form validation for uc_cart_checkout_form().

... See full list

File

uc_order/uc_order.module, line 1403

Code

function uc_order_load_line_items($order) {
  $items = array();
  $result = db_query("SELECT * FROM {uc_order_line_items} WHERE order_id = :id", array(
    ':id' => $order->order_id,
  ));
  foreach ($result as $row) {
    $item = array(
      'line_item_id' => $row->line_item_id,
      'type' => $row->type,
      'title' => $row->title,
      'amount' => $row->amount,
      'weight' => $row->weight,
      'data' => unserialize($row->data),
    );
    drupal_alter('uc_line_item', $item, $order);
    $items[] = $item;
  }

  // Set stored line items so hook_uc_line_item_alter() can access them.
  $order->line_items = $items;
  foreach (_uc_line_item_list() as $type) {
    if ($type['stored'] == FALSE && empty($type['display_only']) && !empty($type['callback']) && function_exists($type['callback'])) {
      $result = $type['callback']('load', $order);
      if ($result !== FALSE && is_array($result)) {
        foreach ($result as $line) {
          $item = array(
            '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'] : array(),
          );
          drupal_alter('uc_line_item', $item, $order);
          $items[] = $item;
        }
      }
    }
  }
  usort($items, 'uc_weight_sort');
  return $items;
}