Skip to content

fix(promotion): handle fixed discount type in buy-get promotions#14939

Merged
kodiakhq[bot] merged 2 commits intomedusajs:developfrom
pitzegluck:fix/buyget-fixed-discount
Apr 10, 2026
Merged

fix(promotion): handle fixed discount type in buy-get promotions#14939
kodiakhq[bot] merged 2 commits intomedusajs:developfrom
pitzegluck:fix/buyget-fixed-discount

Conversation

@pitzegluck
Copy link
Copy Markdown
Contributor

@pitzegluck pitzegluck commented Mar 25, 2026

What

Fix buy-get promotions ignoring the fixed discount type.

Why

A merchant setting up "Buy 2, get $5 off the 3rd item" gets a $5 discount treated as 5,000% off instead. The engine ignores application_method.type and always runs the percentage formula, despite the promotion model and API supporting the fixed type for buy-get promotions.

How

Branch on ApplicationMethodType.FIXED in applyPromotionToTargetItems to apply the correct calculation per type, consistent with how shipping-methods.ts handles the same logic. Rename applicablePercentage to promotionValue to match sibling file naming (shipping-methods.ts, line-items.ts). Default fallback for missing value changed from 100 to 0 to align with sibling conventions.

Testing

Added 3 integration tests: basic fixed discount, cap at item price, multi-quantity application. All 89 existing compute-actions tests pass.

Note

The JSDoc examples in service.ts for createPromotions show buyget with type: "fixed" and no value field. These examples should be updated separately.

Fixes #14934

@pitzegluck pitzegluck requested a review from a team as a code owner March 25, 2026 19:52
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 25, 2026

🦋 Changeset detected

Latest commit: ea9132a

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

This PR includes changesets to release 77 packages
Name Type
@medusajs/promotion Patch
@medusajs/medusa Patch
integration-tests-http Patch
@medusajs/test-utils Patch
@medusajs/medusa-oas-cli Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/caching Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/rbac Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/translation Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/draft-order Patch
@medusajs/oas-github-ci Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/caching-redis Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/core-flows Patch
@medusajs/framework Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/types Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/http-types-generator Patch
@medusajs/cli Patch
@medusajs/deps Patch
@medusajs/telemetry Patch
@medusajs/admin-bundler Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/dashboard Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
medusa-dev-cli Patch
@medusajs/ui Patch

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

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 25, 2026

@pitzegluck is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

@pitzegluck pitzegluck force-pushed the fix/buyget-fixed-discount branch from dd20096 to a51d21d Compare March 25, 2026 21:50
@pitzegluck pitzegluck force-pushed the fix/buyget-fixed-discount branch from a51d21d to 1248119 Compare March 26, 2026 14:37
@medusa-os-bot
Copy link
Copy Markdown

medusa-os-bot bot commented Apr 9, 2026

Thank you for your contribution! 🎉

After an initial review, this PR looks good to us. Here's a summary:

✅ PR template is complete
✅ Linked to a verified issue (#14934)
✅ Follows contribution guidelines
✅ Changeset included with correct patch bump type
✅ Fix follows the established pattern from shipping-methods.ts

Notes:

The 3 new integration tests cover allocation: "once" with fixed type for standard item promotions — which is useful coverage, but doesn't directly exercise the bug being fixed. There's no positive-case test that verifies a BUYGET promotion with type: "fixed" applies the correct dollar amount (e.g., create a promo with value: 500, satisfy the buy rules, and assert the adjustment is 500, not 50000 or 0). Adding one would specifically guard against regressions in the applyPromotionToTargetItems path.

A team member will do a final review before this is merged. We appreciate your patience!

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 10, 2026

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Copy link
Copy Markdown
Member

@shahednasser shahednasser left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Buy-get promotion ignores application_method.type, fixed amount discount calculates as percentage

2 participants