Cache subTotalDiscounted on the cart (#2229) - #2646
Open
wakqasahmed wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2229.
Cart::$cachablePropertieslists the dynamic totals that get cached in Blink for the rest of the request, butsubTotalDiscountedwas never added to it even thoughCalculatesets it every time the cart is calculated. So a fresh fetch of the cart within the same request (e.g. viarefresh()/retrieved) restoressubTotal,total, etc. from the cache but leavessubTotalDiscounteduncalculated, forcing a full recalculation just to get that one property.Added
subTotalDiscountednext tosubTotalin the list and wrote a test that applies a coupon, calculates the cart, then disables the coupon and fetches a fresh instance of the same cart - it still sees the originally calculated discounted subtotal rather than an uncalculated one.I also looked at
shippingBreakdown, which has the same gap, but caching it exposes a pre-existing bug inApplyShipping's guard against re-setting the shipping address totals (can get same draft order when cart does not changestarts failing). That felt out of scope for this fix, so I left it out and kept this PR to the one property the issue pointed at.Ran
vendor/bin/pest tests/core/Unit/Models/CartTest.phplocally, all 32 pass (1 pre-existing skip).