When "Add to cart" form is rendered, a wrong product will be added to the cart.
Same result as drupal 8.x.

Comments

pontus_nilsson created an issue. See original summary.

pontus_nilsson’s picture

Issue summary: View changes
pontus_nilsson’s picture

Issue summary: View changes
rszrama’s picture

I can confirm. It appears the Add to Cart form builder does not use unique form IDs in 2.x like it did in 1.x. This means Drupal is simply submitting the first matching form it finds. Duplicated on my site, will talk w/ Matt about how that worked in 1.x if he's unclear.

niko-’s picture

pontus_nilsson’s picture

mglaman’s picture

Status: Active » Closed (duplicate)

Closing this as a duplicate of #2796669: Price not updated for variations when products shown in list views, as it should be fixed in there. Basically the merge is halted by drupal_ti and Travis tests failing.

hansfn’s picture

Status: Closed (duplicate) » Active

I have grabbed the latest dev version of Commerce and this issue is not fixed.

Doing as the OP suggested still shows the problem - wrong product added. This seems to a off-by-one problem. ADDED: Or it seems the ids are running in the wrong order - opposite for the article element and the add-to-cart div/form element.

Sample HTML code generated for product 2:

<article data-quickedit-entity-id="commerce_product/2" data-quickedit-entity-instance-id="0">
    <div data-quickedit-field-id="commerce_product/2/title/default" [...]>T-shirt</div>
      
    [...]
    <div id="commerce-product-add-to-cart-form--3">
        <form class="commerce-order-item-default-add-to-cart-3-form commerce-order-item-add-to-cart-form" [...]>
        [...]
        <button [...] type="submit" id="edit-submit--3" name="op" value="Add to cart">Add to cart</button></div>
        </form>
    </div>
</article>

I guess you see the offset and using "Add to cart" adds the wrong product. I'm looking at the code, but any help is very much appreciated.

drugan’s picture

Did you try this?

The #2796669: Price not updated for variations when products shown in list views is marked as fixed but appears that it is not. The main reason for this issue is wrong id on Add to Cart forms. Things will become more complicated if you have duplicated carts(the same product) on a page. The solution above resolves this issue too. Just do not forget to disable views caches on the each next view (page or block) which has the same Add to Cart forms as the previous one.

hansfn’s picture

Thx a lot, drugan! Your patch in commit 21 in #2827721: AddToCartForm should support all purchasable entities fixed the issue for me. I consider this issue to be a duplicate of that issue - closing it again.

hansfn’s picture

Status: Active » Closed (duplicate)
Anonymous’s picture

Version: 8.x-2.x-dev » 7.x-1.x-dev
Priority: Normal » Major
Issue summary: View changes
Status: Closed (duplicate) » Active

Hello, I have problems with product selection. Drupal core 7.59, Module Cart 7.x-1.8 + Commerce add to cart confirmation. When adding to the shopping cart the confirmation window has a) the right prices and the right product photo or b) a window with quantity and price only. The real problem is with the shopping cart. There are usually other products displayed as customer has selected. Looks like the problem solved with drupal 8.x (Form ID?). Would it be possible to provide a patch for version 7.x.? Thank you.

Anonymous’s picture

Version: 7.x-1.x-dev » 8.x-2.x-dev
Status: Active » Closed (duplicate)