Skip to content

feat: add isGift field to StoreOffer type and resolvers - SFS-3040 - #3220

Merged
eduardoformiga merged 2 commits into
devfrom
feat/use-is-gift-flag-to-consider-gift-SFS-3040
Apr 23, 2026
Merged

eduardoformiga merged 2 commits into
devfrom
feat/use-is-gift-flag-to-consider-gift-SFS-3040

Conversation

@eduardoformiga

@eduardoformiga eduardoformiga commented Feb 23, 2026 •

Copy link
Copy Markdown
Member

What's the purpose of this pull request?

This PR aims to make possible the use of isGift from the orderForm item instead of price = 0 when dealing with gift.For that, you should use the flag useIsGiftFromOrderForm as true.

  • When true, use the orderForm's isGift field to detect gift items.
  • When false or unset, use the legacy behavior (item.price === 0).

How it works?

  • Introduced an optional isGift field in the StoreOffer type to indicate if an offer is a gift.
  • Updated GraphQL schema and resolvers to handle the new isGift field.
  • Modified the cart validation mutation to include the isGift property for cart items.
  • Adjusted the isGift logic in the cart SDK to utilize the new field when applicable.

(see the gift icon and the free tag in the minicart)

Flag false / default flag true
Screenshot 2026-02-23 at 18 09 09 Screenshot 2026-02-23 at 18 19 48

How to test it?

...

Starters Deploy Preview

References

Checklist

You may erase this after checking them all 😉

PR Title and Commit Messages

  • PR title and commit messages follow the Conventional Commits specification
    • Available prefixes: feat, fix, chore, docs, style, refactor, ci and test

PR Description

  • Added a label according to the PR goal - breaking change, bug, contributing, performance, documentation..

Dependencies

  • Committed the pnpm-lock.yaml file when there were changes to the packages

Documentation

  • PR description
  • For documentation changes, ping @Mariana-Caetano to review and update (Or submit a doc request)

Summary by CodeRabbit

  • New Features
    • Cart items now include gift detection and an isGift flag to mark promotional/complimentary items.
    • An experimental configuration option controls how gifts are detected (store-provided flag vs. price-based).
    • Checkout totals and item lists account for gifts, enabling proper splitting between gifts and regular items.
    • Cart state exposes a flag to support conditional item-splitting behavior.

- Introduced an optional `isGift` field in the `StoreOffer` type to indicate if an offer is a gift.
- Updated GraphQL schema and resolvers to handle the new `isGift` field.
- Modified the cart validation mutation to include the `isGift` property for cart items.
- Adjusted the `isGift` logic in the cart SDK to utilize the new field when applicable.
@eduardoformiga
eduardoformiga requested a review from a team as a code owner February 23, 2026 21:31
@eduardoformiga
eduardoformiga requested review from emersonlaurentino and lariciamota and removed request for a team February 23, 2026 21:31
@coderabbitai

coderabbitai Bot commented Feb 23, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds an optional isGift boolean to StoreOffer, exposes it in the API schema and resolver (VTEX order form), introduces an experimental flag to read the flag from order form, and updates core cart SDK types and gift-detection logic to consume the new field.

Changes

Cohort / File(s) Summary
StoreOffer Schema & Resolver
packages/api/src/typeDefs/offer.graphql, packages/api/src/platforms/vtex/resolvers/offer.ts
Added isGift: Boolean to StoreOffer and a resolver that returns root.isGift ?? false for OrderFormItem, otherwise null.
Feature Configuration
packages/core/discovery.config.default.js
Added experimental flag useIsGiftFromOrderForm: false to control whether to trust isGift from order form.
Cart SDK Integration
packages/core/src/sdk/cart/index.ts
Exposed isGift in CartItem fragment and public CartItem type; updated gift-detection to use item.isGift when feature flag enabled (fallback: price === 0); added shouldSplitItem?: boolean to Cart interface and adjusted totals/item-list logic.
sequenceDiagram
  participant Client
  participant API as GraphQL API
  participant VTEX as VTEX OrderForm
  participant Core as Core SDK (cart)

  Client->>API: Query cart / offers
  API->>VTEX: Fetch order form
  VTEX-->>API: OrderForm item (may include isGift)
  API->>Core: Resolve CartItem with isGift (respecting experimental flag)
  Core-->>API: Computed cart totals, items split by isGift
  API-->>Client: Return cart with isGift on StoreOffer
Loading

🎯 3 (Moderate) | ⏱️ ~15 minutes

🎁 A tiny flag whispers from order form to cart,
Schema, resolver, and SDK link every part,
Feature-flagged logic decides what is a gift,
Types align, totals split — a neat little lift! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: adding an isGift field to the StoreOffer type and its resolvers, directly reflected in the actual code changes across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/use-is-gift-flag-to-consider-gift-SFS-3040

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/core/src/sdk/cart/index.ts`:
- Around line 92-97: The helper function isGift unnecessarily uses optional
chaining on a non-nullable CartItem and its name collides with the
CartItem.isGift field; rename the function to isGiftItem, change the
implementation to return item.isGift ?? false when
storeConfig.experimental?.useIsGiftFromOrderForm is true (and keep the existing
price === 0 fallback), and update all call sites that reference isGift to use
isGiftItem so the code no longer uses item?.isGift and avoids the naming
collision.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 362358b and aed39f0.

⛔ Files ignored due to path filters (3)
  • packages/api/src/__generated__/schema.ts is excluded by !**/__generated__/** and included by packages/**
  • packages/core/@generated/gql.ts is excluded by !**/@generated/**, !**/@generated/** and included by packages/**
  • packages/core/@generated/graphql.ts is excluded by !**/@generated/**, !**/@generated/** and included by packages/**
📒 Files selected for processing (4)
  • packages/api/src/platforms/vtex/resolvers/offer.ts
  • packages/api/src/typeDefs/offer.graphql
  • packages/core/discovery.config.default.js
  • packages/core/src/sdk/cart/index.ts

Comment on lines +92 to +97
const isGift = (item: CartItem) => {
if (storeConfig.experimental?.useIsGiftFromOrderForm) {
return item?.isGift ?? false
}
return item.price === 0
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Two small issues in the isGift helper.

1. Unnecessary optional chain on item: item is typed as CartItem (non-nullable), so item?.isGift is redundant — use item.isGift ?? false directly.

2. Naming collision with the CartItem.isGift field: The local function shares its name with the GraphQL field it reads, which can be confusing during future maintenance. Consider renaming to isGiftItem.

♻️ Proposed fix
-const isGift = (item: CartItem) => {
+const isGiftItem = (item: CartItem) => {
   if (storeConfig.experimental?.useIsGiftFromOrderForm) {
-    return item?.isGift ?? false
+    return item.isGift ?? false
   }
   return item.price === 0
 }

Then update all three call sites:

-      totals.totalItems += isGift(curr) ? 0 : quantityMultiplier
+      totals.totalItems += isGiftItem(curr) ? 0 : quantityMultiplier
...
-      gifts: cart.items.filter((item) => isGift(item)),
-      items: cart.items.filter((item) => !isGift(item)),
+      gifts: cart.items.filter((item) => isGiftItem(item)),
+      items: cart.items.filter((item) => !isGiftItem(item)),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/sdk/cart/index.ts` around lines 92 - 97, The helper
function isGift unnecessarily uses optional chaining on a non-nullable CartItem
and its name collides with the CartItem.isGift field; rename the function to
isGiftItem, change the implementation to return item.isGift ?? false when
storeConfig.experimental?.useIsGiftFromOrderForm is true (and keep the existing
price === 0 fallback), and update all call sites that reference isGift to use
isGiftItem so the code no longer uses item?.isGift and avoids the naming
collision.

- Modified the CartItem interface to omit the 'isGift' field from CartItemFragment and added it as an optional property.
- This change allows for better flexibility in handling gift items within the cart.
@codesandbox-ci

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
packages/core/src/sdk/cart/index.ts (1)

96-101: Same isGift helper concerns as earlier review (optional chain + naming collision).
Line 96–101: this duplicates the previously reported issue about item?.isGift and the helper name colliding with the field.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/sdk/cart/index.ts` around lines 96 - 101, The helper
function isGift duplicates the CartItem.isGift field and uses optional chaining
on item (item?.isGift) causing a naming collision and unclear null handling;
rename the helper (e.g., isItemGift) and change the logic so you explicitly
check the item object and field existence instead of optional chaining: when
storeConfig.experimental?.useIsGiftFromOrderForm is enabled, return a boolean
based on the explicit presence/value of item.isGift (e.g., item && ('isGift' in
item) ? Boolean(item.isGift) : ...), otherwise fall back to the existing price
check (item.price === 0); update any callers of isGift to use the new helper
name.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/core/src/sdk/cart/index.ts`:
- Around line 96-101: The helper function isGift duplicates the CartItem.isGift
field and uses optional chaining on item (item?.isGift) causing a naming
collision and unclear null handling; rename the helper (e.g., isItemGift) and
change the logic so you explicitly check the item object and field existence
instead of optional chaining: when
storeConfig.experimental?.useIsGiftFromOrderForm is enabled, return a boolean
based on the explicit presence/value of item.isGift (e.g., item && ('isGift' in
item) ? Boolean(item.isGift) : ...), otherwise fall back to the existing price
check (item.price === 0); update any callers of isGift to use the new helper
name.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aed39f0 and b9ecd85.

📒 Files selected for processing (1)
  • packages/core/src/sdk/cart/index.ts

@eduardoformiga eduardoformiga changed the title feat: add isGift field to StoreOffer type and resolvers feat: add isGift field to StoreOffer type and resolvers - SFS-3040 Apr 10, 2026

@lemagnetic lemagnetic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@hellofanny

Copy link
Copy Markdown
Contributor

@eduardoformiga I believe we will need a doc to mention this new flag useIsGiftFromOrderForm?
Or it is a very specific case for odp?

@eduardoformiga
eduardoformiga merged commit e10fc92 into dev Apr 23, 2026
4 checks passed
@eduardoformiga
eduardoformiga deleted the feat/use-is-gift-flag-to-consider-gift-SFS-3040 branch April 23, 2026 14:20
@coderabbitai coderabbitai Bot mentioned this pull request May 4, 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.

3 participants