-
Notifications
You must be signed in to change notification settings - Fork 373
[2025-10] Add cartGiftCardCodesAdd mutation and remove Update filtering #3284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
juanpprieto
wants to merge
8
commits into
2025-10-api-update
Choose a base branch
from
feat-3271-gift-card-codes-add
base: 2025-10-api-update
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
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
Tests verify requirements for new Add mutation: - Add single gift card code - Add multiple codes in one call - Handle empty array - Override cartFragment - Mutation includes userErrors, warnings, @incontext - NO duplicate filtering (thin wrapper pattern) Test Results: FAILING (expected) Error: Failed to resolve import "./cartGiftCardCodesAddDefault" Reason: Module doesn't exist yet (TDD RED phase) Tests include validation that implementation does NOT contain: - unique filtering - filter() calls - indexOf() duplicate checking This follows thin wrapper pattern per investigation-3271.md findings that Add mutations should delegate to API. Related: #3271
Implementation: - Thin wrapper pattern (no duplicate filtering per investigation) - Follows cartGiftCardCodesRemove structure - JSDoc explains append vs replace semantics - Uses giftCardCodes (strings) not IDs Architectural decision: - NO duplicate filtering (API handles case-insensitive normalization) - Consistent with cartLinesAdd, cartDeliveryAddressesAdd patterns - All Add mutations are thin wrappers (0/3 filter) - Documented in investigation-3271.md Test Results: All 7 tests passing ✅ - Basic functionality (single/multiple codes) - Empty array handling - CartFragment override - Mutation structure validation - Duplicate codes pass through (no filtering) TypeScript: ✅ Clean Related: #3271
Tests verify that: - Duplicate codes pass through to API without filtering - Case-insensitive codes handled by API (GIFT123 vs gift123) - Aligns with API 2025-10 behavior (case-insensitive normalization) Related: investigation-3271.md E-016, E-017, E-019
Breaking change for API 2025-10: - Removes client-side unique code filtering - Passes codes directly to Storefront API - API handles case-insensitive normalization - Consistent with Add/Remove mutations (thin wrapper pattern) - Updated JSDoc to document behavior change Evidence: - API schema describes codes as 'case-insensitive' - No DUPLICATE_GIFT_CARD error exists in CartErrorCode/CartWarningCode - Filtering was copy-paste from discount codes (E-016) - All Add/Remove mutations delegate to API without filtering Closes part of #3271
Complete integration of addGiftCardCodes: - Added CartForm action type GiftCardCodesAdd - Exported addGiftCardCodes from createCartHandler - Added doc file with related mutations - Added JS/TS example files - Exported function from package index - Updated all test assertions Tests: ✅ All 447 passing TypeScript: ✅ Clean Related: #3271
Contributor
|
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
Changes: - Added AddGiftCardForm component (uses GiftCardCodesAdd action) - Updated cart.tsx to handle GiftCardCodesAdd action - Changed gift card input form to use Add instead of Update - Keeps UpdateGiftCardForm for backward compatibility Users can now add gift cards without replacing existing ones in skeleton. Related: #3271
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.
WHY are these changes introduced?
Fixes #3271
Storefront API 2025-10 added
cartGiftCardCodesAddmutation for appending gift card codes without replacing existing ones. Hydrogen only implementedcartGiftCardCodesRemovein PR #3128, leaving users without a way to add codes incrementally. Since the API only returns the last 4 digits of applied gift cards (security constraint), users cannot fetch existing codes to preserve them when using the Update mutation.This PR also removes legacy duplicate filtering from
cartGiftCardCodesUpdateto align with API 2025-10 thin wrapper architecture.WHAT is this pull request doing?
New Feature: cartGiftCardCodesAdd
Adds thin wrapper for
cartGiftCardCodesAddmutation following the established Add mutation pattern.Files created:
cartGiftCardCodesAddDefault.ts- Core implementation (no duplicate filtering)cartGiftCardCodesAddDefault.test.ts- 7 comprehensive testscartGiftCardCodesAddDefault.doc.ts- Documentation metadatacartGiftCardCodesAddDefault.example.js/ts- Usage examplesIntegration:
createCartHandlerasaddGiftCardCodesCartForm.ACTIONS.GiftCardCodesAddaction typeUsage:
Breaking Change: cartGiftCardCodesUpdate
Removed client-side duplicate code filtering to align with thin wrapper pattern.
Before:
After:
Architecture Decision:
Migration: If you need client-side deduplication:
HOW to test your changes?
🎩 Top Hat
Prerequisites
Testing Steps
Feature 1: Add Gift Card Codes
app/routes/test-gift-cards.tsx):app/routes/api.gift-cards.tsx):Feature 2: Update No Longer Filters
Edge Cases to Test
Validation Checklist
Checklist
Summary of Changes
New:
cart.addGiftCardCodes(codes)- Append codes without replacingCartForm.ACTIONS.GiftCardCodesAdd- Form actionBreaking:
cart.updateGiftCardCodes(codes)- No longer filters duplicates client-sideFiles: 13 files, +400/-9 lines
Tests: 7 new tests, all passing
Architecture: 100% thin wrapper consistency (was 78%)