Skip to content

Cache subTotalDiscounted on the cart (#2229) - #2646

Open
wakqasahmed wants to merge 1 commit into
lunarphp:1.xfrom
wakqasahmed:fix/issue-2229-cart-cached-totals
Open

Cache subTotalDiscounted on the cart (#2229)#2646
wakqasahmed wants to merge 1 commit into
lunarphp:1.xfrom
wakqasahmed:fix/issue-2229-cart-cached-totals

Conversation

@wakqasahmed

Copy link
Copy Markdown
Contributor

Closes #2229.

Cart::$cachableProperties lists the dynamic totals that get cached in Blink for the rest of the request, but subTotalDiscounted was never added to it even though Calculate sets it every time the cart is calculated. So a fresh fetch of the cart within the same request (e.g. via refresh()/retrieved) restores subTotal, total, etc. from the cache but leaves subTotalDiscounted uncalculated, forcing a full recalculation just to get that one property.

Added subTotalDiscounted next to subTotal in 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 in ApplyShipping's guard against re-setting the shipping address totals (can get same draft order when cart does not change starts 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.php locally, all 32 pass (1 pre-existing skip).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Cart missing some cached totals

2 participants