I have uc_wishlist installed in Drupal 6.x and UC 2.x. It's allowing me to create the wish list but when I login as a user, search for a wish list and then add one of that wish list's products to my cart I get the following errors:

* You have selected to purchase more items than requested.
* You have selected to purchase more items than requested.

Any suggestions? It's not adding to the cart and I do have a quantity set on the wishlist side. So I've added a quantity of 1 or more to the # of product I would like. But then logged in as a diff user and then trying to add that product it doesn't work per above.

-backdrifting

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cybertoast’s picture

i'm having the same issue.

cybertoast’s picture

The source of the problem is the WantQty field being disabled for non-owner users. This thread (http://drupal.org/node/227966) has a discussion on the topic.

There appears to have been a change in form processing behavior between Drupal 5 and Drupal 6. In D5 the '#disabled' option to a form element would cause the value of the element to still be available when the element was disabled. In D6 this no longer seems to be the case. As far as I can tell this is a bug in drupal core.

So, what's the solution? This post (http://drupaleasy.com/quicktips/module-development-disabled-vs-readonly-...) has some thoughts on disabled vs. read-only. The readonly solution does not work. The solution is to add the '#value' option to the form element.

Following is the quick fix to the existing code:
In the uc_wishlist.pages.inc file, change the uc_wishlist_view_form() function:

    $element['wantqty'] = array(
      '#type' => 'textfield',
      '#value' => $item->wantqty, // <<< add this line
      '#default_value' => $item->wantqty,
      '#size' => 5,
      '#maxlength' => 6,
      '#disabled' => $own ? FALSE : TRUE
    );
    $element['haveqty'] = array(
      '#type' => 'textfield',
      '#value' => $item->haveqty, // <<< add this line
      '#default_value' => $item->haveqty,
      '#size' => 5,
      '#maxlength' => 6,
      '#disabled' => TRUE
    );

In looking at the code I found a few other inconsistencies that made things more intuitive for the end-user. Instead of allowing the user to order more items than are requested (wantqty), why not just limit the form's input using a select box? This way there's no confusing error to the end-user, and the actual selection process is simpler.

I made the following change to accommodate this (also in the uc_wishlist.pages.inc file, uc_wishlist_view_form() function):

    $element['qty'] = array(
      '#type' => 'textfield',
      '#default_value' => 0,
      // '#default_value' => $item->qty - $item->haveqty > 0 ? $item->qty - $item->haveqty : 1,
      '#size' => 5,
      '#maxlength' => 6,
    );

Changed to use a select-list instead:

    $element['qty'] = array(
      '#type' => 'select',
      '#options' => range(0,$item->qty),
      '#default_value' => $item->qty - $item->haveqty > 0 ? $item->qty - $item->haveqty : 1,
    );

Now the '#default_value' above has some sketchyness associated with it. If the #default_value uses the $item->qty-$item->haveqty logic, you'll have to change uc_wishlist_view_form_submit() to ensure that clicking one 'Add To Cart' button does not automagically add all items to the cart. The #default_value => 0 in the first block is based on a fix in a different post addressing this issue.

I've attached a patch here which has a set of changes I made to allow both singular and batch addition of wishlist items to the cart. I found it to be useful since I can test out how people respond to different options then. The patch includes a bunch of different things, so if you're not interested in all the features, please diff and only take what you need. But it incorporates all of the above discussion.

(BTW if you don't want to patch, and just want the whole bundle, it's attached as uc_wishlist_sr.tgz. Apologies to the module maintainers if this is not cool - please let me know if the proper code of conduct is to only provide patches).

cybertoast’s picture

Title: Quantity issue when adding wish list product to cart » Quantity issue when adding wish list product to cart [
FileSize
19.95 KB
7.59 KB

I screwed up my patch!!!

Please ignore the previous patch and attachment and use the one in this post instead. The problem is that I had a reference to $item->wantqty in uc_wishlist.pages.inc which does not exist (it should be $item->qty, in the form element default and value options).

Many apologies!

ambientdrup’s picture

Awesome! Thanks cybertoast. I'll try this out. Thanks for working on the patch.

-backdrifting

jasonabc’s picture

am also experiencing this issue. Any chance cybertoast's patch can make it into a core release of UC Wishlist? The wishlist is rendered pretty much useless if people can't buy stuff from it...

jasonabc’s picture

@ cybertoast - many thanks for the module bud - works a treat!!!!!

koblongata’s picture

// Why not just limit the user to the range of possible options?
$element['qty'] = array(
'#type' => 'select',
'#options' => range(0,$item->qty),
'#default_value' => $item->qty - $item->haveqty > 0 ? $item->qty - $item->haveqty : 1,
);

this part, i think it's more correct as this

'#default_value' => $item->qty - $item->haveqty > 0 ? $item->qty - $item->haveqty : 0,

manoz_79’s picture

+ Subscribing

gdblackx’s picture

This works now for when someone adds to cart but when you try to change the quantity wanted when you are logged in it doesn't work.
Please help.

gdblackx’s picture

Problem solved. If you have this same experience this is how I fixed it.

Add the below code to the uc_wishlist_pages.inc page:

if($own){
$element['wantqty'] = array(
'#type' => 'textfield',
'#default_value' => $item->qty,
'#size' => 5,
'#maxlength' => 6,
);
}else{
$element['wantqty'] = array(
'#type' => 'textfield',
'#default_value' => $item->qty,
'#value' => $item->qty, // Necessary with Disabled
'#size' => 5,
'#maxlength' => 6,
'#disabled' => TRUE
);
}

gooddesignusa’s picture

gdblackx what line #/ where ??

longwave’s picture

Status: Active » Needs review
FileSize
553 bytes

Patch attached that fixes this issue.

longwave’s picture

Status: Needs review » Fixed

Fixed in uc_wishlist-6.x-1.1.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.