Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Problem/Motivation
#3088597: Add a constraint to purchased_entity which checks the availability manager added support for integrating with the availability manager in the AddToCartForm thanks to entity validation. We now need the commerce_order_item_edit_quantity
views field plugin to do the same.
Proposed resolution
The validate should adjust the order item quantity and then validate the entity to see if purchased_entity still is valid with the new quantity changes.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#7 | interdiff_5-7.txt | 1.63 KB | jsacksick |
#7 | 3109312-7.patch | 7.6 KB | jsacksick |
|
Comments
Comment #2
mglamanBlind patch to at least scaffold out what the code should kind of look like.
Comment #3
mglamanComment #4
jsacksick CreditAttribution: jsacksick at Centarro commentedI've been working on this today, we should definitely fix this ASAP, cause right now, if an order availability checker indicates that an order item is unavailable, the quantity update goes through, and then the item is removed on the next refresh (with a successful message saying "Your shopping cart has been updated").
I tried finding an issue for that this morning but couldn't, and then finally found yours :p.
We need tests coverage for this, and we also need to set the initial quantity back, so the logic in
viewsFormSubmit()
works properly.For some reason, when looping over the violations using the
getEntityViolations()
, no violations are present. so I'm looping on the violations directly and it seems to work.Attaching patch for review.
Comment #5
jsacksick CreditAttribution: jsacksick at Centarro commentedComment #6
mglaman😂 had to find this, man.. Views.
Above we check
$quantity < 0
and here we check if it is also equal to0
. The could still mean the quantity changed. Should we changeto
and update the inline comments? This handles invalid values or purposely set to 0 quantities?
I don't think we need to filter by field access if we are then filtering by the two specified fields
Is this required? This isn't a content entity form, so I don't think this affects anything.
And, upon further digging.. it looks like this flag is mostly used when importing entities via Migrate, not even the content entity form.
Actually, we could remove this and just update
viewsFormSubmit
to trust the set quantity value. We've validated it already, so the form submit no longer needs to.Comment #7
jsacksick CreditAttribution: jsacksick at Centarro commentedWell, we can't remove the checks in
viewsFormSubmit()
becauseviewsFormValidate
ignore "invalid" quantities and doesn't throw an error.And we still need
to keep ignoring quantities that haven't changed. Remember, we're checking quantities of all "rows", not just a single one.
Comment #8
mglamanAh okay. Thanks @jsacksick for clarifying Views form handling 🙂.
Moving to RTBC as my sign off, if you'd like the honors of commit.
Comment #10
jsacksick CreditAttribution: jsacksick at Centarro commentedCommitted!