feat: support freezeCart and unfreezeCart on carts - #419
Merged
Conversation
🦋 Changeset detectedLatest commit: b90ad05 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
mvantellingen
approved these changes
Aug 27, 2026
mvantellingen
approved these changes
Aug 27, 2026
cartState could never become Frozen, so freezing a cart while a payment is in flight was untestable. The damaging case is the negative one: a test asserting that a code path refuses before touching the cart passed whether or not the guard existed, because the freeze would not have happened anyway. freezeCart requires Active and unfreezeCart requires Frozen; both raise InvalidOperation otherwise, rather than silently accepting a transition that commercetools rejects. Freezing locks in prices, so while frozen the update actions that would change what the cart costs are rejected. The check runs per action through a new beforeAction hook on AbstractUpdateHandler rather than up front, so unfreezeCart followed by addLineItem in one request behaves the way commercetools applies actions: in sequence. Fixes #414
korsvanloon
force-pushed
the
feat/cart-freeze
branch
from
August 27, 2026 14:05
987448c to
b90ad05
Compare
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.
Fixes #414.
src/repositories/cart/actions.tsimplemented neither action, socartState: "Frozen"was unreachable.Behaviour
freezeCartsetscartStatetoFrozen,unfreezeCartreturns it toActive.InvalidOperation(400) otherwise, rather than silently accepting a transition commercetools rejects.InvalidOperation. Actions that leave the price alone (setCustomerEmail,setCustomField, addresses, …) still apply.The set of blocked actions follows the documented purpose of freezing — "update actions that can change the price of (Custom) Line Items are not allowed" — and is a single
PRICE_CHANGING_ACTIONSset next to the handler, so it is easy to adjust if you want it wider or narrower. That list is the one judgment call in this PR; happy to change it.The
beforeActionhookThe frozen check runs per action, not up front, through a new no-op
beforeActionhook onAbstractUpdateHandler. That way[unfreezeCart, addLineItem]in one request behaves the way commercetools applies actions — in sequence — instead of being rejected on the cart's starting state. There is a test for exactly that.Coverage
Seven tests in
cart.test.ts: freeze, unfreeze, freeze-when-frozen, unfreeze-when-active, a frozen cart rejectingaddLineItem(and staying at the same version), a frozen cart acceptingsetCustomerEmail, and unfreeze-then-add in one request.Full suite: 797 passing.
Note:
addPaymentfrom #415 is the other half of the payment-first flow described in that issue and is handled in a separate PR.