Resolve cart item availability on retrieval - #534
Merged
Merged
Conversation
…ld out IsSellable and SellableQuantity are derived, not stored, so the cart repository returns them as the Go zero value. CartUsecase never filled them in the way ProductUsecase and VariantUsecase do, so every cart line serialised isSellable: false — the order app badged each one "Habis" and disabled checkout with "Checkout belum tersedia", regardless of whether the product tracked availability at all. Resolve availability for each cart item's variant on every cart the use case returns, and cover the positive case in the order-web e2e suite, which until now only asserted the badge appears. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MaYhWTShADmUCUm3AGMbXa
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Compute and populate the
IsSellableandSellableQuantityfields on cart variants when the cart is retrieved, since these derived fields cannot be read directly from the database.Changes
resolveCartAvailability()helper that computes availability for all items in a cart by calling the existingresolveVariantAvailability()functionGetCurrentCart()UpdateCartTable()AddCartItem()UpdateCartItem()RemoveCartItem()ClearCart()soldOutVariant()to test suite for creating unavailable variantsTestCartUsecase_ResolvesItemAvailability()— validates availability computation for untracked, variant-tracked, product-tracked, and sold-out variantsTestCartUsecase_RemoveCartItem_ResolvesRemainingItemAvailability()— ensures remaining items have availability resolved after removalImplementation Details
The
resolveVariantAvailability()function already existed and handles the logic for determining sellability based on tracking type and inventory counts. This change ensures it is consistently applied whenever a cart is returned to the client, making the availability state always accurate and visible in the UI.https://claude.ai/code/session_01MaYhWTShADmUCUm3AGMbXa