Posted by carn1x on February 21, 2012 at 8:00am
6 followers
| Project: | Drupal Commerce |
| Version: | 7.x-1.x-dev |
| Component: | Views integration |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
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.
Comments
#1
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.
#2
@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
#3
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.
#4
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.
#5
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.
#6
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.
#7
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.