Discovered a curious bug and not sure if this is UC or Drupal related. If comments are enable for the product content type and an user submits a comment and then clicks the "Preview" button on the comment form they are then taken to the preview page. Now if they click "submit", instead of the comment being submitted the product is added to the users cart.

I'm not sure if this was the case in D6?/UC2 but I did use comments on one site and didn't see this.

You can test it out here http://dev.ubercartdemo.com/node/1

login details
User: comment
Pass: comment

I tested this with Garland and Bartik. At first I thought it was my theme that was the issue but not so.

Files: 
CommentFileSizeAuthor
#8 1800626-comment-preview-submit.patch1.39 KBlongwave
PASSED: [[SimpleTest]]: [MySQL] 2,800 pass(es).
[ View ]
#2 1800626-comment-preview-submit.patch1.49 KBlongwave
PASSED: [[SimpleTest]]: [MySQL] 2,453 pass(es).
[ View ]

Comments

Title:Drupal comments form conflicts with UC add to cart formDrupal comment preview conflicts with add to cart form

Bug confirmed, only occurs when previewing a comment, seemingly due to the add to cart form effectively being embedded inside the comment save/preview form, and the former apparently overrides the latter.

Version:7.x-3.1» 7.x-3.x-dev
Status:Active» Needs review
StatusFileSize
new1.49 KB
PASSED: [[SimpleTest]]: [MySQL] 2,453 pass(es).
[ View ]

Not sure this is the correct approach, but it seems to work after very basic testing.

An alternative might be to move the add to cart form from uc_product_view() to hook_entity_prepare_view().

Tested it out and seems to work good.

Status:Needs review» Fixed

Committed #2.

Status:Fixed» Closed (fixed)

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

Status:Closed (fixed)» Active

Reopening, as this change caused various issues with Panels and Views.

Status:Active» Needs review
StatusFileSize
new1.39 KB
PASSED: [[SimpleTest]]: [MySQL] 2,800 pass(es).
[ View ]

This doesn't seem as clean, but I don't see any other way to detect the comment reply page.

Are comments the only place where this mix-up could happen?

I haven't looked into the code, but it seems like the add-to-cart button ought to work in some way that doesn't interfere with the main form on a page.

It interferes with VBO also.

Unfortunately, this and the VBO issue are due to the way Drupal builds up pieces of content by wrapping smaller pieces in bigger pieces of HTML. In cases involving multiple forms such as these, the add to cart form gets wrapped up inside the comment reply form and the VBO action form - but nested <form> tags are not allowed by the HTML spec and therefore they present broken behaviour. However, there is not enough context passed into the add to cart form to be able to tell whether it is being rendered inside a comment reply form, VBO form, etc. so it appears the only way of handling this is on a case by case basis.

Therefore, it looks like the only reliable way of detecting a comment reply form is with the URL /comment/reply. The VBO issue will have to be dealt with separately, probably in a Views hook or plugin somehow, as we cannot detect this from the URL alone.

Status:Needs review» Fixed

Committed #8.

The VBO issue cannot be handled the same way, and will be dealt with in #1835206: VBO add to cart does not work with Add To Cart/Buy Now fields

Status:Fixed» Closed (fixed)

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