Skip to content

feat: support freezeCart and unfreezeCart on carts - #419

Merged
korsvanloon merged 1 commit into
mainfrom
feat/cart-freeze
Aug 27, 2026
Merged

feat: support freezeCart and unfreezeCart on carts#419
korsvanloon merged 1 commit into
mainfrom
feat/cart-freeze

Conversation

@korsvanloon

Copy link
Copy Markdown
Collaborator

Fixes #414.

src/repositories/cart/actions.ts implemented neither action, so cartState: "Frozen" was unreachable.

Behaviour

  • freezeCart sets cartState to Frozen, unfreezeCart returns it to Active.
  • Each requires the opposite state and raises InvalidOperation (400) otherwise, rather than silently accepting a transition commercetools rejects.
  • While a cart is frozen, update actions that would change what it costs are rejected with 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_ACTIONS set 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 beforeAction hook

The frozen check runs per action, not up front, through a new no-op beforeAction hook on AbstractUpdateHandler. 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 rejecting addLineItem (and staying at the same version), a frozen cart accepting setCustomerEmail, and unfreeze-then-add in one request.

Full suite: 797 passing.

Note: addPayment from #415 is the other half of the payment-first flow described in that issue and is handled in a separate PR.

@changeset-bot

changeset-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b90ad05

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@labdigital/commercetools-mock Minor

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

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
korsvanloon merged commit f5bfb3a into main Aug 27, 2026
10 checks passed
@korsvanloon
korsvanloon deleted the feat/cart-freeze branch August 27, 2026 14:08
@github-actions github-actions Bot mentioned this pull request Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cart: freezeCart and unfreezeCart actions are not implemented

2 participants