My example may be a bit convoluted, however it does strike me as a bug so I thought I'd report it.

I have a display node for a product, and then blocks that also show on the same page provided by Views / Context.

One of these blocks holds the add to cart form for the product which the display node references.

If I try and add to cart using the form in the View, no matter what Quantity I specify, only 1 is added to the cart.

If I remove the Add To Cart form from the display node (hide it in the content type) however, then the Views form works as expected.

Files: 
CommentFileSizeAuthor
#5 duplicate_add_to_cart_form_id-1447782-5.patch1.03 KBvasike
PASSED: [[SimpleTest]]: [MySQL] 3,589 pass(es).
[ View ]
#1 views.txt4.46 KBkitkat13

Comments

Title:Add To Cart form provided by a View only adds 1 quantity if displayed on the same page as the display nodeA second Add To Cart form provided by a View only adds 1 quantity if displayed on the same page with form without imput quantity
Version:7.x-1.2» 7.x-1.x-dev
StatusFileSize
new4.46 KB

Hello,
i have the same bug.

To reproduce it , just install (and dependencies):
- Drupal v. 7.14
- commerce v. 7.x-1.x-dev
- views v. 7.x-3.3
- eva v. 7.x-1.x-dev

Now:
- add a new product (product_commerce type)
- create a product-display (name : 'product' if you want to use my view) with a field 'product_ref'
- set manage display for field 'product_ref'
** in default => Format 'add to cart'
settings:
Quantity widget: Disabled
Default quantity: 1
Combine like items: Enabled
** in teaser => teaser => Format 'add to cart'
settings:
Quantity widget: Enabled
Default quantity: 1
Combine like items: Enabled

- add a new content : product with a ref on the product create before
- import the view in views.txt
- go to admin/structure/block and set to 'View: add to cart bis' in region 'content' BUT UNDER 'Main page content'

Now, go to the display node or /test.
Try to add 10 product into your cart... only 1 is added to the cart.

@kitkat13 : i follow your instructions using the view you provided.
i can't reproduce the issue. all it works as should be. it adds the right number of products to the cart.

i used the last dev http://ftp.drupal.org/files/projects/commerce-7.x-1.x-dev.tar.gz

Status:Active» Postponed (maintainer needs more info)

i did a second test and indeed i could reproduce the issue.

first test: i test for a product display with several product references (different attributes), and all it works as it should be

second test: for a product display with a single product reference and i got this issue, only one product added to the cart, no matter of quantity.

third test: deleted the fields for attributes, and made test for both product display
result: it works only for multiple product references. for product displays with single product referenced it seems we have this issue.

Status:Postponed (maintainer needs more info)» Active

i think i found the cause of the issue : duplicate of the form_id in the case of duplicates of the products referenced.
'form_id' => commerce_cart_add_to_cart_form_id($product_ids),
this value should be somehow unique.

Status:Active» Needs review
StatusFileSize
new1.03 KB
PASSED: [[SimpleTest]]: [MySQL] 3,589 pass(es).
[ View ]

here is a patch for this, adds an incremental number to the form_id.

i also noticed there some issues, having duplicate of product displays in a page with multiple products referenced.
the change of the product (or attributes) selection goes to to change for all product displays.
but i think this is another issue. i'll take a look if is not already open.

Thanks yor this patch vasike. I'm in the situation "having duplicate of product displays in a page with multiple products referenced" and therefore your patch does not work. The form ids are unique but I still cannot add to cart.

Title:A second Add To Cart form provided by a View only adds 1 quantity if displayed on the same page with form without imput quantityUse a separate form ID pattern for Views field based Add to Cart forms
Component:Cart» Views integration
Category:bug» feature
Status:Needs review» Active

Honestly, I'm a bit hesitant to commit the patch in #5. I think that function is the wrong place to work around a limitation of Drupal's forms API. I'm not sure we should even be responsible for ensuring uniqueness of form IDs if multiple instances of the same form are placed on the page. As a concession, we could use an alternate form ID pattern for Views field based Add to Cart forms, but we would need to make it optional to preserve backwards compatibility for folks who may already be altering those forms.

Generally, though, I'd also recommend not having multiple instances of the same Add to Cart form on the page, but if you must it appears you just won't be able to have one use the quantity textfield and the other not (I don't see how this makes sense anyways) until this feature lands.

Want to add to this that in the course of debugging #1925646: Combine does not work with different line-item types and custom comparison properties I discovered another scenario where you can end up with duplicate form IDs: using two Add to Cart forms on the same page that add the product using different line item types.