I have a picky client that is unhappy with the current handling of the wishlist. His argument is that the current handling of logging in and registering could cause confusion on the part of the end user. That is, he thinks that if you add an item to your wishlist when you are not registered, if you follow the registration/login process after then the item should exist in your wishlist. Does this make sense?

I'm going to do a little initial hacking in the module today to see what I can find in order to make this happen, but any thoughts the module maintainer might have on this would be appreciated.

Comments

NicholasR’s picture

Okay, it was pretty easy. Added some session variables when validating form

function commerce_wishlist_add_form_validate($form, &$form_state) {
  global $user;
  if ($form_state['values']['op'] == t('Add to wish list')) {
    // Verify if is a registed user_access
    if (!$user->uid) {
      // store for adding one value post login/register
      if (!isset($_SESSION['wishlist'])) {
    		$_SESSION['wishlist'] = array();
  		}
  	  $wishlist = &$_SESSION['wishlist'];
  	  $wishlist['product_id'] = $form_state['values']['product_id'];
    	if (isset($form_state['build_info']['args'][2]['entity'])) {
      		$wishlist['nid'] = $form_state['build_info']['args'][2]['entity']->nid;
    	}
      form_set_error('add_to_wishlist',
        t('<a href="@login">Log in</a> or <a href="@register">register</a> to add this product to your wishlist.',
          array('@login' => url('user/login', array('query' => drupal_get_destination())), '@register' => url('user/register'))
        )
      );
    }....

Then put a hook into user_login

function commerce_wishlist_user_login(&$edit, $account) {
	if (isset($_SESSION['wishlist'])) {
		$addtowish = $_SESSION['wishlist']['product_id'];
		$nid = $_SESSION['wishlist']['nid'];
		$fields = array('uid' => $account->uid, 'product_id' => $addtowish, 'quantity' => '1', 'nid' => $nid);
		db_insert('commerce_wishlist')
      		->fields($fields)
      		->execute();
  	}
}

Works great, functions for new user creation as well as existing user login. Its not very feature filled, just holds the last value to be added to the wishlist...

Argus’s picture

Seems a logical and user friendly request. It would indeed be even better if you could create a full wish list without registering, although most users understand it takes registering to save something.

Could you create a patch so we can test?

youlikeit’s picture

#1 Part 1 works for me but in which file doI have to put the hook for user_login?

erichomanchuk’s picture

Has anyone written a patch that could be applied for this so it could be added to the module. I am currently in need of a feature that keeps track of anonymous users wishlists much like how commerce's cart functionality allows for anonymous users.

I have a project where I wish to allow a anonymous user to create a wishlist and they can save it if they do login in but if they don't login I was going to allow them to email this wishlist to whomever.

Exploratus’s picture

I like the functionality suggested by #4

nvahalik’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)
Related issues: +#2677086: Wishlist functionality for anonymous users

Closing in favor of tracking the functionality in #2677086: Wishlist functionality for anonymous users.