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)

Comments

bjaxelsen created an issue. See original summary.

bjaxelsen’s picture

Issue summary: View changes
tr’s picture

Status: Active » Needs review
StatusFileSize
new3.01 KB

It 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?

Status: Needs review » Needs work

The last submitted patch, 3: 2552629.patch, failed testing.

tr’s picture

Status: Needs work » Needs review
StatusFileSize
new4.07 KB

This patch fixes product kit add-to-cart forms too.

Status: Needs review » Needs work

The last submitted patch, 5: 2552629-2.patch, failed testing.

Status: Needs work » Needs review

TR queued 5: 2552629-2.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 5: 2552629-2.patch, failed testing.

bjaxelsen’s picture

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

longwave’s picture

I think BuyItNowForm (and AddToCartForm?) also needs to implement \Drupal\Core\Form\BaseFormIdInterface so hook_form_BASE_FORM_ID_alter() will work.

tr’s picture

Status: Needs work » Needs review
StatusFileSize
new10.08 KB

Added BaseFormIdInterface and getBaseFormId(), fixed some comments related to base forms.

longwave’s picture

Status: Needs review » Fixed

Committed, thanks for the report and fix.

  • longwave committed ccd1016 on 8.x-4.x authored by TR
    Issue #2552629 by TR, bjaxelsen: Multiple uc_product_add_to_cart_form on...

Status: Fixed » Closed (fixed)

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