It is not possible to have multiple add to cart forms on the same page ("uc_product_add_to_cart_form"). When user submits the form, Ubercart will think that is is the first form that is submitted even if it is another form (another product).
Steps to reproduce:
- Create a view that lists products
- Add a "add to cart" field to the view
- Save view
- Make sure the view lists multiple products
- Click on the second add to cart form
- Error: product of the first form on the page is added to the cart.
The old Ubercart version solved this by assigning unique form IDs to each of the forms.
We might want to look at how simplenews handles this:
http://cgit.drupalcode.org/simplenews/tree/src/Plugin/Block/SimplenewsSu...
http://cgit.drupalcode.org/simplenews/tree/src/Form/SubscriptionsBlockFo...
(this way all of the forms do get a unique form ID)
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 2552629-11.patch | 10.08 KB | tr |
| #9 | ubercart-multiple-add-to-cart-same-page-2552629-9.patch | 746 bytes | bjaxelsen |
| #5 | 2552629-2.patch | 4.07 KB | tr |
| #3 | 2552629.patch | 3.01 KB | tr |
Comments
Comment #2
bjaxelsen commentedComment #3
tr commentedIt looks like the unique form ID code got lost in the port when hook_forms() was removed. Here's a patch to restore this capability. Can you test it?
Comment #5
tr commentedThis patch fixes product kit add-to-cart forms too.
Comment #9
bjaxelsen commentedThanks for quick action!
After changing a little bit in uc_product/src/Plugin/views/field/AddToCart.php (see patch) the problem is solved.
I am not quite sure why the testCatalogAttribute() test fails.
Comment #10
longwaveI think BuyItNowForm (and AddToCartForm?) also needs to implement \Drupal\Core\Form\BaseFormIdInterface so hook_form_BASE_FORM_ID_alter() will work.
Comment #11
tr commentedAdded BaseFormIdInterface and getBaseFormId(), fixed some comments related to base forms.
Comment #12
longwaveCommitted, thanks for the report and fix.