Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I've encountered a bug where the quantity of a product in the cart page can only be altered once. The second time the AJAX call fires and a message that the cart was updated is shown but the quantity remains unchanged.
I've enabled the update cart button again and when I press it right after changing the quantity it works as expected. Is this possibly a form validation error where a form is sent twice with the same form_build_id?
Cheers
Comment | File | Size | Author |
---|---|---|---|
#2 | uc_ajax_cart-doublesubmitfix-1421256-2.patch | 387 bytes | neilnz |
Comments
Comment #1
nelslynn CreditAttribution: nelslynn commentedI've encountered something similar, only that after the first time to the cart page, and trying to change quantity, it dosn't work, althougth there is a successful update message. It takes a few times for the update cart to then work. After it works once, I can browse away from the cart page and then back to it, and the update function works as expected.
I've cleared cache, run update, and run cron.... neither of these help.
Using latest version of Dev uc_ajax-cart (jan 24) and ubercart 2.7
Comment #2
neilnz CreditAttribution: neilnz commentedThe reason for this is Ubercart 2.7 includes a hidden submit button at the top of the form that has the same ID (edit-update) as the one at the bottom. Of course this is extremely invalid, but to trigger the cart submit on change, triggerCartSubmit() in uc_ajax_cart.js uses this:
jQuery('#uc-cart-view-form #edit-update').trigger('click');
Because this actually matches two elements (!!), it clicks both update buttons. The first submit has valid form data, the second doesn't, and it triggers two refreshes of the cart contents, the first before the update has actually happened. It leads to a race condition, which is why the update works sometimes.
While Ubercart really need to sort out their CSS IDs on the form, this can be worked around by changing the click trigger to:
jQuery('#uc-cart-view-form #edit-update:first').trigger('click');
Attached a patch that does this.
Comment #3
tunic#2 sounds good to me... nelslynn, Bartezz, could you test attached patch and post your results?
Comment #4
Bartezz CreditAttribution: Bartezz commented@tunic, will try! But am currently not working for that employer anymore, will have to setup a copy of the site and test, don't hold your breath!
Comment #5
stewart.adam CreditAttribution: stewart.adam commentedHas an issue been reported against Ubercart about this? While I'll be happy to commit this in the mean time (after RTBC), this should really be fixed in Ubercart not here...
Comment #6
nelslynn CreditAttribution: nelslynn commentedSorry, this patch does not fix the problem for me.
EDIT, this seems to fix the issue when using Ubercart 2.8, just released.
Comment #7
stewart.adam CreditAttribution: stewart.adam commentedJust got a chance to test this, confirmed working.
Committed, thanks.