You are here

function commerce_wishlist_user_login in Commerce Wishlist 7.3

Same name and namespace in other branches
  1. 8.3 commerce_wishlist.module \commerce_wishlist_user_login()

Implements hook_user_login().

File

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

Code

function commerce_wishlist_user_login(&$edit, $account) {

  // If someone has a product ID in their session, go ahead and add it to their
  // wish list when the log in.
  if (!empty($_SESSION['commerce_wishlist']['product_id'])) {
    $product_id = $_SESSION['commerce_wishlist']['product_id'];
    $product = commerce_product_load($product_id);
    if (!commerce_wishlist_user_has_product_in_wishlist($product_id, $account->uid)) {
      commerce_wishlist_product_add($product, NULL, $account->uid);
      drupal_set_message(t('Product <em>@product</em> has been added to <a href="@url">your wish list</a>.', array(
        '@product' => $product->title,
        '@url' => url('user/' . $account->uid . '/wishlist', array(
          'absolute' => TRUE,
        )),
      )));
    }
    else {
      drupal_set_message(t('Product <em>@product</em> was already in <a href="@url">your wish list</a>.', array(
        '@product' => $product->title,
        '@url' => url('user/' . $account->uid . '/wishlist', array(
          'absolute' => TRUE,
        )),
      )), 'error');
    }
  }
  unset($_SESSION['commerce_wishlist']);
}