You are here

function uc_order_load in Ubercart 5

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

Load an order from the database.

51 calls to uc_order_load()
hook_calculate_tax in docs/hooks.php
Calculate tax line items for an order.
test_gateway_charge in payment/uc_payment/test_gateway.module
uc_2checkout_complete in payment/uc_2checkout/uc_2checkout.module
uc_2checkout_form_alter in payment/uc_2checkout/uc_2checkout.module
Implementation of hook_form_alter().
uc_authorizenet_charge in payment/uc_authorizenet/uc_authorizenet.module

... See full list

File

uc_order/uc_order.module, line 2552

Code

function uc_order_load($order_id) {
  if (is_null($order_id) || $order_id < 1) {
    return FALSE;
  }
  $result = db_query("SELECT * FROM {uc_orders} WHERE order_id = %d", $order_id);
  if (db_num_rows($result) == 0) {
    return FALSE;
  }
  $order = db_fetch_object($result);
  $order->data = unserialize($order->data);
  $result = db_query("SELECT * FROM {uc_order_products} WHERE order_id = %d ORDER BY order_product_id", $order_id);
  $order->products = array();
  while ($product = db_fetch_object($result)) {
    $product->data = unserialize($product->data);
    $order->products[] = $product;
  }

  // Invoke hook_order() in enabled modules.
  foreach (module_implements('order') as $module) {
    $func = $module . '_order';
    $null = NULL;
    $func('load', $order, $null);
  }

  // Load line items... has to be last after everything has been loaded.
  $order->line_items = uc_order_load_line_items($order->order_id, TRUE);
  usort($order->line_items, 'uc_weight_sort');

  // Merge it with the defaultish line items.
  $order->line_items = array_merge($order->line_items, uc_order_load_line_items($order, FALSE));
  usort($order->line_items, 'uc_weight_sort');

  // Make sure the total still matches up...
  if (($total = uc_order_get_total($order)) !== $order->order_total) {
    db_query("UPDATE {uc_orders} SET order_total = %f WHERE order_id = %d", $total, $order->order_id);
    $order->order_total = $total;
  }
  return $order;
}