You are here

function commerce_wishlist_get_wishlist_url in Commerce Wishlist 7.3

Returns a shareable URL for a given wish list.

Parameters

object $wishlist: The wish list object.

Return value

string The shareable URL for the wishlist which uses the hash.

1 call to commerce_wishlist_get_wishlist_url()
commerce_wishlist_share in ./commerce_wishlist.module
Form callback: Wishlist sharing.

File

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

Code

function commerce_wishlist_get_wishlist_url($wishlist) {
  $url_hashes =& drupal_static('commerce_wishlist_order_hashes', array());
  if (empty($url_hashes[$wishlist->order_id])) {
    $result = db_select('commerce_wishlist_share', 'cws')
      ->fields('cws', array(
      'url_hash',
    ))
      ->condition('order_id', $wishlist->order_id)
      ->execute();
    $url_hash = $result
      ->fetchField(0);
    $url_hashes[$wishlist->order_id] = $url_hash;
  }
  else {
    $url_hash = $url_hashes[$wishlist->order_id];
  }
  if ($url_hash == '') {
    return '';
  }
  $wishlist_url = str_replace('%', '%commerce_wishlist_hash', variable_get('commerce_wishlist_share_prefix', 'shared-wishlist/%'));
  return url(str_replace('%commerce_wishlist_hash', $url_hash, $wishlist_url));
}