You are here

function uc_wishlist_get_contents in UC Wish List 7

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

Get the items in a specified wish list.

2 calls to uc_wishlist_get_contents()
uc_wishlist_display in ./uc_wishlist.pages.inc
Display a wish list for viewing or altering.
uc_wishlist_user_display in ./uc_wishlist.pages.inc
Display a wishlist in user account page.

File

./uc_wishlist.module, line 592
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();
  $query = db_select('node', 'n');
  $query
    ->join('uc_wishlist_products', 'w', 'n.nid = w.nid');
  $query
    ->fields('w');
  $query
    ->addField('n', 'title');
  $query
    ->addField('n', 'vid');
  $query
    ->condition('w.wid', $wid);
  $query
    ->addTag('node_access');
  $res = $query
    ->execute();

  // Iterating through the array.
  foreach ($res as $item) {
    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;
    $items[] = $item;
  }
  return $items;
}