Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Given I'm on the cart product page
And I have a product in my cart with quantity 1
When I change the value of the quantity input field to 2
And press return (enter)
Then I expect the quantity for the line item to be updated
Instead the line item is deleted.
This is caused by the fact that the return submits the line item delete form instead of the cart update form.
Comment | File | Size | Author |
---|---|---|---|
#19 | 2878155-19.patch | 1.2 KB | eiriksm |
#11 | interdiff.txt | 1.82 KB | abramm |
#11 | commerce-update_cart_quantity_on_enter-2878155-11-D8.patch | 2.19 KB | abramm |
|
Comments
Comment #2
bojanz CreditAttribution: bojanz at Centarro commentedOuch, agreed.
Comment #3
vasikehere is patch for this.
Used the D7 approach - extra JS for edit quantity Views handler - to make sure the Update cart is submitted on press enter key.
Comment #4
sorabh.v6Comment #5
sorabh.v6Hi All,
I confirm that the patch in #3 is working fine for me code is also looking fine. Setting it to RTBC.
Thanks All
Comment #6
MegaChriz CreditAttribution: MegaChriz at WebCoo commentedWould this still work when #2906345: Replace the cart page view with a Twig template lands?
I see a reference to a views class here:
Comment #7
edurenye CreditAttribution: edurenye at ENDPHASYS Technologies commentedRTBC +1
Comment #8
littlepixiez CreditAttribution: littlepixiez commented#3 works perfectly for me. It's the first thing I did when playing with the cart! Great patch.
@MegaChriz It works using 'form input[id^="edit-edit-quantity"]' but I'm guessing the ID might change depending on what generates the form?
Comment #9
spacetaxi CreditAttribution: spacetaxi commented#3 works for me with a minor change: Add a colon (:) in front of input in the selector. See https://api.jquery.com/input-selector/
to
Comment #10
abrammThe JS code is missing context handling and once().
Running Drupal.attachBehaviors() multiple time will cause the event handler to run multiple times.
Comment #11
abrammAhh the context handling is there. That's just once() missing.
Here's the patch against latest dev.
Added once() and changed input to :input as per #9.
Interdiff included.
Comment #12
abrammComment #13
BerdirDon't know too much about JS, but this was RTBC before, looks fine to me and I tested it.
Interestingly, after noticing this problem. I quickly tried to reproduce on https://commerceplus.acromedia.com/cart and it doesn't happen there, so I first thought its a problem with our theme, but I guess this patch is already applied there...
Comment #14
bojanz CreditAttribution: bojanz at Centarro commentedThanks everyone!
Let's call this cart_form. That parallels cart_block above it, and allows us to keep the file even for a Twig version of the cart form, if it ends up existing. The JS file should then be commerce_cart.form.js (not a fan of prefixing every JS/CSS file with the module name, but that's what we've done so far).
Indentation is wrong here.
Wanted to run a full ESLint, but it's ignoring Drupal's coding standard somehow, telling me to replace single quotes with double quotes, which makes no sense.
Comment #16
bojanz CreditAttribution: bojanz at Centarro commentedThanks, everyone!
Comment #17
mmjvb CreditAttribution: mmjvb as a volunteer commentedComment #19
eiriksmNot sure if we should call this an edge case, but the selector in the jQuery code will only work if you actually use the view provided by commerce core with little customization. This means one has to duplicate this code to be able to fix the same issue when the selectors are different.
In my opinion we should add a class to the actual input instead, and use this as the selector. This way, the code would work regardless of how you customize the cart form. Well except if you actively remove this class, but that seems way less likely than someone doing some customization that ends up changing wrapper selectors.
Here is a patch with that approach. If you want a followup instead, please let me know :)
Comment #20
eiriksmAdded a follow up and marked as related