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.

Comments

Garrett Albright’s picture

I'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…

Garrett Albright’s picture

Scratch 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.

Garrett Albright’s picture

Status: Active » Needs review
StatusFileSize
new445 bytes

Oh. 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…?

Garrett Albright’s picture

StatusFileSize
new3.3 KB

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… 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()?

On 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.

agerson’s picture

Status: Needs review » Reviewed & tested by the community

It works. Thanks! This provides much better user feedback.

dww’s picture

Title: You must specify a price. » Missing FAPI validation for min/max prices when adding a varprice item to your cart
Version: 6.x-1.0-rc3 » 6.x-1.x-dev
Category: feature » bug
StatusFileSize
new3.71 KB

Ran 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:

+  if (empty($form_state['values']['varprice']) || $form_state['values']['varprice'] == 0) {

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...

hedac’s picture

is 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

hedac’s picture

I 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.

jrust’s picture

Status: Reviewed & tested by the community » Needs work

Doesn't apply cleanly against the 1.1 branch so it's not clear what needs to happen for the latest version.