You are here

function uc_wishlist_get_uid in UC Wish List 8

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

Get either an authenticated user's uid or an anonymous user's unique ID.

1 call to uc_wishlist_get_uid()
uc_wishlist_create_wishlist in ./uc_wishlist.module
Creates a new wishlist for the current authenticated or anonymous user.

File

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

Code

function uc_wishlist_get_uid() {
  $user = \Drupal::currentUser();

  // Get either an authenticated user's uid or an anonymous user's unique ID.
  if ($user
    ->getAccount()
    ->id()) {
    $uid = $user
      ->getAccount()
      ->id();
  }
  else {
    if (!isset($_SESSION['uc_wishlist_uid']) || empty($_SESSION['uc_wishlist_uid'])) {
      $_SESSION['uc_wishlist_uid'] = md5(uniqid(rand(), TRUE));
    }
    $uid = $_SESSION['uc_wishlist_uid'];
  }
  return $uid;
}