You are here

function uc_wishlist_get_contents in UC Wish List 6

Same name and namespace in other branches
  1. 8 uc_wishlist.module \uc_wishlist_get_contents()
  2. 7 uc_wishlist.module \uc_wishlist_get_contents()

Get the items in a specified wish list.

1 call to uc_wishlist_get_contents()
uc_wishlist_display in ./uc_wishlist.pages.inc
Display a wish list for viewing or altering.

File

./uc_wishlist.module, line 515
Allows users to create public shopping/wish lists.

Code

function uc_wishlist_get_contents($wid = NULL) {
  $wid = $wid ? $wid : uc_wishlist_get_wid();
  if (!$wid || !is_numeric($wid)) {
    return FALSE;
  }
  $items = array();
  $res = db_query('SELECT w.*, n.title, n.vid FROM {node} n INNER JOIN {uc_wishlist_products} w ON n.nid = w.nid WHERE w.wid = %d', $wid);
  while ($item = db_fetch_object($res)) {
    for ($i = 0; $i < count($items); $i++) {
      if ($items[$i]->nid == $item->nid && $items[$i]->data == $item->data) {
        $items[$i]->qty += $item->qty;
        continue 2;
      }
    }
    $product = node_load($item->nid);
    $item->model = $product->model;
    $item->cost = $product->cost;
    $item->price = $product->sell_price;
    $item->weight = $product->weight;
    $item->weight_units = $product->weight_units;
    $item->shippable = $product->shippable;
    $item->data = unserialize($item->data);
    $item->module = $item->data['module'];
    $item->purchase = unserialize($item->purchase);
    $item->options = array();

    // add wishlist id data
    $item->data['wid'] = $item->wid;
    $item->data['wpid'] = $item->wpid;

    // Invoke hook_cart_item() with $op = 'modify' in enabled modules.
    // An especially important hook is uc_attribute_cart_item which
    // updates the item given the attributes.
    foreach (module_implements('cart_item') as $module) {
      if ($module == 'uc_wishlist') {
        continue;
      }
      $func = $module . '_cart_item';
      $func('load', $item);
    }
    $items[] = $item;
  }
  return $items;
}