You are here

function uc_cart_get_contents in Ubercart 5

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

Grab the items in a shopping cart for a user.

If $cid is not passed in, this function uses the uid of the person currently accessing this function.

15 calls to uc_cart_get_contents()
hook_update_cart_item in docs/hooks.php
Handle requests to update a cart item.
theme_cart_review_table in uc_cart/uc_cart_checkout_pane.inc
theme_uc_cart_block_content in uc_cart/uc_cart.module
Theme the shopping cart block content.
uc_cart_block in uc_cart/uc_cart.module
Implementation of hook_block().
uc_cart_checkout in uc_cart/uc_cart.module
Display the cart checkout page built of checkout panes from enabled modules.

... See full list

File

uc_cart/uc_cart.module, line 1885

Code

function uc_cart_get_contents($cid = NULL, $action = NULL) {
  static $items = array();
  $cid = $cid ? $cid : uc_cart_get_id();
  if ($action == 'rebuild') {
    $items = array();
  }
  if (!isset($items[$cid])) {
    $items[$cid] = array();
    $result = db_query("SELECT c.*, n.title, n.vid FROM {node} n INNER JOIN {uc_cart_products} c ON n.nid = c.nid WHERE c.cart_id = '%s'", $cid);
    while ($item = db_fetch_object($result)) {
      for ($i = 0; $i < count($items[$cid]); $i++) {
        if ($items[$cid][$i]->nid == $item->nid && $items[$cid][$i]->data == $item->data) {
          $items[$cid][$i]->qty += $item->qty;
          continue 2;
        }
      }
      $product = node_load($item->nid);
      $item->cost = $product->cost;
      $item->price = $product->sell_price;
      $item->weight = $product->weight;
      $item->data = unserialize($item->data);
      $item->module = $item->data['module'];
      $item->options = array();
      $item->model = $product->model;

      // Invoke hook_cart_item() with $op = 'load' in enabled modules.
      foreach (module_implements('cart_item') as $module) {
        $func = $module . '_cart_item';
        $func('load', $item);
      }
      $items[$cid][] = $item;
    }
  }
  return $items[$cid];
}