You are here

function commerce_wishlist_view_user_wishlist in Commerce Wishlist 7.3

Page callback for viewing a wish list.

Parameters

object $wishlist_user: The user for which to show a wish list.

Return value

mixed Rendered page or response code.

1 string reference to 'commerce_wishlist_view_user_wishlist'
commerce_wishlist_menu in ./commerce_wishlist.module
Implements hook_menu().

File

./commerce_wishlist.module, line 131
Provides a wish list for use in Drupal Commerce.

Code

function commerce_wishlist_view_user_wishlist($wishlist_user) {
  global $user;

  // Get the default wishlist.
  $wishlist = commerce_wishlist_order_load($wishlist_user->uid);

  // Can this user view the wish list? Also, allow a user if there is no wish
  // list defined but the logged in user is the one accessing the page.
  if (!commerce_wishlist_user_access($user, 'view', $wishlist) && !empty($wishlist) && $user->uid != $wishlist_user->uid) {
    return MENU_ACCESS_DENIED;
  }

  // If not, then return an empty page.
  if ($wishlist !== FALSE) {
    $wishlist_wrapper = entity_metadata_wrapper('commerce_order', $wishlist);
    if (commerce_line_items_quantity($wishlist_wrapper->commerce_line_items, commerce_product_line_item_types()) > 0) {

      // Return the wishlist page.
      return commerce_embed_view('commerce_wishlist_page', 'default', array(
        $wishlist->order_id,
      ));
    }
  }

  // Page is empty.
  return theme('commerce_wishlist_empty_page', array(
    'account' => $wishlist_user,
  ));
}