You are here

function commerce_wishlist_add_wishlist_url in Commerce Wishlist 7.3

Create and store a shareable URL for a given wish list.

This function will create and store a wish list for a given wish list. It technically guarantees to create a unique URL for a given wish list with roughly 2 trillion possibilities.

Parameters

object $wishlist: The wish list object.

1 call to commerce_wishlist_add_wishlist_url()
commerce_wishlist_share_submit in ./commerce_wishlist.module
Submit handler: sharing options.

File

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

Code

function commerce_wishlist_add_wishlist_url($wishlist) {

  // Remove if there already is one.
  commerce_wishlist_remove_wishlist_url($wishlist);

  // Avoid collisions.
  do {
    $hash_to_use = commerce_wishlist_generate_url_hash($wishlist);
  } while (commerce_wishlist_hash_load($hash_to_use) !== FALSE);
  db_insert('commerce_wishlist_share')
    ->fields(array(
    'order_id' => $wishlist->order_id,
    'url_hash' => $hash_to_use,
  ))
    ->execute();
  $url_hashes =& drupal_static('commerce_wishlist_order_hashes', array());
  $url_hashes[$wishlist->order_id] = $hash_to_use;
}