Closed (duplicate)
Project:
Commerce Core
Version:
8.x-2.x-dev
Component:
Product
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
30 Nov 2016 at 19:23 UTC
Updated:
2 Dec 2016 at 11:47 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
steveoliver commentedSee https://github.com/drupalcommerce/commerce/pull/578 - currently submits add to cart forms to purchasable entities' pages. Not ideal as it directs you to another page and cannot continue adding products to cart from the view. :(
Comment #3
steveoliver commentedComment #4
steveoliver commentedWeird -- with the currently committed code (not this patch - which doesn't actually help anything), what happens is if you have a list of 10 products, and you click to add the second one to your cart, the second from last is added to the cart. If you click the third from the top, the third from the bottom is actually added. WTF?
This is not an issue specific to views, so removing tag and views from title.
Comment #5
mglamanDoes this have to do with the static counter added in #2827721: AddToCartForm should support all purchasable entities instead of when it was based on the product ID? Not quite sure, but would be worth checking out.
Comment #6
drugan commented@steveoliver
Try applying #575 and see if that will work for you.
Comment #7
mglamandrugan the issue is the form ID. Using a static counter was not working because it didn't increment properly.
This ensures a unique add to cart form ID.
Comment #8
drugan commented@mglaman
It didn't increment properly because it should be changed like this:
But anyway, if we'll get right incrementing the bug indicating by steveoliver #4 is still there. As I think the issue not only on the add to cart form ID, but also with not properly detected $selected_variation.
See ProductVariationAttributesWidget.php
For me #575 has resolved the steveoliver's issue. Still the ajax wrapper is not working properly because when you choose an attribute option, let's say on the seventh add to cart form in the view then you thrown up to the first add to cart form in the view instead of staying at the seventh form.
Comment #9
steveoliver commentedI'm marking this issue as a child of the static counter issue as a follow-up fix to that -- with this issue, we just use the purchasable entity id as a unique identifier for the form id. The Forms API/HTML::getId will increment the form id if the same product add to cart form ends up more than once on a page, and will keep the same functionality/approach, but with support for all purchasable entity types, not just products.
The https://github.com/drupalcommerce/commerce/pull/578 PR (diff also attached) fixes this issue.
@drugan, You may be experiencing a different issue which I noticed while testing this issue -- that is: if you have the same purchasable entity add to cart form twice on a page, the current ajax attribute selection/changing does not work correctly -- I will open a separate issue for the #ajax class targeting / field re-rendering issue.
Comment #10
steveoliver commented@drugan, I created the issue I noticed #2832268: AddToCartForm should support multiple of the same purchasable entity add to cart form -- maybe it is affected by your PR?
Comment #11
bojanz commentedLet's go back to #2827721: AddToCartForm should support all purchasable entities since that's where the regression originated.