Closed (fixed)
Project:
Commerce Core
Version:
8.x-2.x-dev
Component:
Product
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
7 Sep 2016 at 18:19 UTC
Updated:
28 Sep 2016 at 21:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mglamanIt sounds like some cache tags are not properly being invalidated when the variation is changed. The bug might be that it's not clearing the Views cache? Either way some cache tag isn't being invalidated somewhere.
Comment #3
krabbe commentedThank you. How can I find out, where the cache problem is located?
Comment #4
mglamanSo, unfortunately it can be difficult. I'm not even sure how I'd debug it right now without going all out with xdebug.
The first thing is to check the ProducrVariation entity class. We should be adding the Product it belongs to cache tags to its invalidate cache tags call. Maybe even experiment with adding more stuff there, no idea.
It's either Views render cache, which should invalidate with entity save. Or the variation isn't actually invalidating the Products view cache.
So if you're new to D8s render cache and cache tag/context system, this is one hell of an intro/dive in issue.
I say don't be afraid and try it out :) you'll want to have it in your back pocket.
Next steps though is writing a test to verify this bug.
Comment #5
krabbe commentedMmmmh... I'm not a full time drupalist, and while exploring D8 I have to learn so many new things. So I will put this one beside.
And yes, learning the drupal test system is one of the things.
But maybe, this issue will just "fly away" with one of next updates... ;)
Thanks a lot.
Comment #6
krabbe commentedIt seems to be a bigger problem. On the page with the block of products listed with views not only the price for the variations don't update, but also only the first product is added to the cart, no matter which add to cart button I click.
There are three products in that block with two different product types, one with variations, the other one without.
The view is a product view, format unordered list and product as rendered entity.
Comment #7
mglamanOkay, I guess it's time to create a test view and really get a test going for this. I assume that dynamic page cache and page cache are enabled. Is this for authenticated and anonymous users?
Comment #8
krabbe commentedCache modules are enabled, yes. And there is no difference in behavior between authenticated and anonymous users.
Comment #9
agoradesign commentedThe add to cart problem sounds familiar. I had a similar problem when I implemented and add to cart button directly for a variation view instead of the default one for product entities. When I used that to show 4 variations in a list,I had the same problem and I solved it
Unfortunately I don't have access to that repo atm before Sunday... I'm not sure but AFAIK it had to do with the form ID or similar
Comment #10
mglamankrabbe, is that view generic enough you could paste the config YML here? Or possible send if in a PM? We need to make a test using a sample View, but need to make sure I built one properly.
Comment #11
drugan commentedI confirm the issue. Only the first product in a block-view works as expected. The others don't change their values (Title, SKU, Price) being chosen. Well, actually they change them but only on the the very first product, not on itself.
See the exported YML of the view.
Comment #12
mglamandrugan, thanks!
Comment #13
krabbe commentedThis is the block-view-YML-file I use...
Comment #14
agoradesign commentedCommerceAddToCartForm must provide an unique form ID. That's why always the same product is added to cart.
My quick and not too sexy workaround was to use a static counter variable and add this to the form ID
Comment #15
mglamanIn 1.x we made it based on the product's ID (well, variations actually.) I'll write a test which imports this view and does all those things. Sitting down with it now.
Comment #16
mglamanThis looks surprisingly simple.
Based on
We just need a unique operation.
Can you try the patch? We still need tests
Comment #17
mglamanComment #18
mglamanHere we go! Fix with test. PR here: https://github.com/drupalcommerce/commerce/pull/487
Test is not a FunctionalJavascript test for attribute changing. Merely that with 5 add to cart forms, clicking submit on third adds proper product. We can extend to test FunctionalJavascript if needed.
Comment #19
krabbe commentedThank you!
The last patch fixed my problem. Price and title of product with variations are updating now and the correct product is added to cart.
Comment #20
drugan commentedFor me also #18 works. Thank you!
Comment #21
niko- commentedThanks,
works for me.
also #18 fix https://www.drupal.org/node/2786245
Comment #22
agoradesign commentedShouldn't we include the operation in getBaseFormId() as well?
If you want to target all add to cart forms in a hook_form_BASE_FORM_ID_alter(), this would be much more convenient...
Comment #23
mglamanUpdated base form ID:
commerce_line_item_add_to_cart_form. Then a form ID would be likecommerce_line_item_product_variation_add_to_cart_PRODUCTID_form.Tests still stupid on Travis.
Comment #24
mglamanAttributing this work to ThinkBean.
Comment #25
mglamanUpdated PR to change view name and route to match "test multiple carts". Should be merged if tests still pass with change.
Comment #27
mglamanThanks everyone for confirming! Merged.