While working on #3138952: Make the AvailabilityManager order aware we noticed that order items being validated and passing to the availability manager from the AddToCartForm didn't have their cart attached. This is because we do not resolve and determine that cart until the form is submitted.
We need to figure out that cart in the buildEntity method so that it always has a reference.
This way folks can use the order item matcher in availability checks to see if the proposed quantity and the current quantity in the cart exceed expectations. (the fact someone has to do this manually can be a follow-up.)
Comment | File | Size | Author |
---|---|---|---|
#2 | 3143382-2.patch | 1.55 KB | jsacksick |
|
Comments
Comment #2
jsacksick CreditAttribution: jsacksick at Centarro commentedThis should do the trick!
Comment #3
mglamanI wonder if this is needed anymore. The entity should be built before submission.
\Drupal\Core\Entity\ContentEntityForm::validateForm
builds the entity before it calls the validate method on the entity\Drupal\Core\Entity\EntityForm::afterBuild
rebuilds the entity if input is being processed\Drupal\Core\Entity\EntityForm::submitForm
also rebuilds the entityThe logic check protects us from additional calls, but maybe we can just remove that code.
Comment #4
mglamanSince the submitForm parent calls build entity anyways, we're safe to assume the order has been set. Patch to verify.
Comment #6
mglaman🤦♂️ because this creates the cart, and I cannot read properly. We should definitely keep it here, otherwise we'd be creating carts on every product page view whenever building an order item entity for the add to cart form.
Comment #8
mglamanCommitted, good fix @jsacksick 🥳