I added a hook_add_to_cart function to my module Ubercart Product Minimum & Maximum and, in testing, I am finding that the form state (attributes and other custom elements) are not preserved when the result is false and the product form is re-loaded. In my store we have only 6 form elements that customer can set (5 attributes, 1 custom upload) and having to re-select those elements is annoying at best. Should someone have a large number of attributes, having to re-select them all could drive away customers!

Comments

longwave’s picture

Status: Active » Closed (won't fix)

This isn't possible from hook_add_to_cart() itself as that is only called at submit time. The best fix would seem to be to add a custom validate callback to the add to cart form and do your validation in there, which would preserve form state.