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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nelslynn’s picture

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

neilnz’s picture

Status: Active » Needs review
FileSize
387 bytes

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

tunic’s picture

#2 sounds good to me... nelslynn, Bartezz, could you test attached patch and post your results?

Bartezz’s picture

@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!

stewart.adam’s picture

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

nelslynn’s picture

Sorry, this patch does not fix the problem for me.

EDIT, this seems to fix the issue when using Ubercart 2.8, just released.

stewart.adam’s picture

Status: Needs review » Fixed

Just got a chance to test this, confirmed working.

Committed, thanks.

Status: Fixed » Closed (fixed)

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