If you leave the price at 0.00 and click "add to cart" it takes you to your cart and gives you the message "You must specify a price." There is no link back to the product. I think this is a little vague for most users. It would be best if you never left the product page and got a traditional Drupal form error with the price field highlighted.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 471858-6.uc_varprice_validate.patch | 3.71 KB | dww |
| #4 | uc_varprice_validate.patch | 3.3 KB | Garrett Albright |
| #3 | varprice_fail_on_zero.patch | 445 bytes | Garrett Albright |
Comments
Comment #1
Garrett Albright commentedI'm confirming this behavior happens when you have the Add to Cart Tweaks module set up and configured to send a user to the checkout page after adding a product to their cart. I think the fault lies with Variable Price module, though, because minimum prices are not being respected! That is, both before and after disabling the checkout page forwarding, I was able to submit the add to cart form with a donation of $0.00, even though I set the minimum price of $1.00.
Patch forthcoming, possibly…
Comment #2
Garrett Albright commentedScratch that - I can get Variable Price to complain about the price being too low if I set it to a non-zero price like .5 or -3, but zero itself still can get added to carts successfully. Odd.
Comment #3
Garrett Albright commentedOh. Not that difficult to unravel after all… But a good example of the problems with PHP's
empty()function, which I've never been a fan of.It doesn't solve the problem with being taken to the checkout page and not being able to re-adjust the value if it's invalid, though. Further, I notice that if there's an item in the cart (like a previous donation attempt) and the Tweaks function is configured to remove other cart items when a donation product is added, that previous item(s) is still deleted.
May I suggest that we instead add a validator function to the Add to Cart form and check for the proper value there instead of using hook_add_to_cart()? But perhaps you have a good reason for doing it that way…?
Comment #4
Garrett Albright commentedOn further inspection, I don't think there's any other way, because the Tweak module is using a submit handler on the add to cart form which is always going to fire before hook_add_to_cart() AFAIK. So this patch does away with hook_add_to_cart() and adds a validation function to the form.
Comment #5
agerson commentedIt works. Thanks! This provides much better user feedback.
Comment #6
dwwRan into this bug myself. More accurate title. Rerolled the patch to:
A) Apply cleanly to the end of the DRUPAL-6--1 branch
B) Simplified the code a bit. The 2nd half of this is pointless:
Yes, empty() can lead to bugs, but in this case, it's actually all you need. ;)
C) Used proper PHPDoc style for function comments.
Fixes an important UI bug with this module, simple code. Leaving this RTBC...
Comment #8
hedac commentedis this included in the latest 1.1 version? I'm still having the problem of "You must specify a price." if I set the price to 0.00
not using Add to Cart Tweaks but uc_checkout_tweaks
Comment #9
hedac commentedI have managed to do it by removing this condition in the validation function
if (empty($form_state['values']['varprice']) || $form_state['values']['varprice'] == 0)And setting a minimum price of 0.00 in the feature
so now users can enter 0.00 price for a free purchase if they wish.
Comment #10
jrust commentedDoesn't apply cleanly against the 1.1 branch so it's not clear what needs to happen for the latest version.