Skip to content

Conversation

@fPolic
Copy link
Contributor

@fPolic fPolic commented Oct 17, 2025

Summary

What
Add support for defining custom campaign budget attributes alongside predefined customer_id, customer_email etc.


CLOSES CORE-1222


Note

Adds custom campaign budget attributes via workflow hooks and budget_context, updates promotion handling, exposes UI to set custom keys, and adds tests.

  • Backend/Core:
    • Add hooks getCustomCampaignBudgetAttributes and getCustomCampaignBudgetAttributesForRegistration in update-cart-promotions and complete-cart to inject custom attributes.
    • Pass merged budget_context into promotion computation and usage registration; include customer_id/customer_email fallbacks.
    • Draft orders: refresh-draft-order-adjustments now builds budget_context via hook.
    • Promotion service: for USE_BY_ATTRIBUTE budgets, read attribute from applicationContext.budget_context, validate presence, and compute budget-exceeded accordingly; remove reliance on prior context util.
  • Types:
    • Extend CampaignBudgetUsageContext to accept arbitrary keys; add budget_context to ComputeActionContext.
  • Admin Dashboard:
    • Campaign form: toggle to use a custom attribute key (with Switch + text input) alongside predefined options.
    • Add related i18n schema/strings (customAttribute*).
  • Tests:
    • New integration tests validating per-attribute budget tracking/enforcement and multi-attribute scenarios; update promotion compute-actions tests to include budget_context.

Written by Cursor Bugbot for commit 6fed832. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Oct 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

8 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
api-reference Ignored Ignored Nov 17, 2025 9:47am
api-reference-v2 Ignored Ignored Preview Nov 17, 2025 9:47am
cloud-docs Ignored Ignored Preview Nov 17, 2025 9:47am
docs-ui Ignored Ignored Preview Nov 17, 2025 9:47am
docs-v2 Ignored Ignored Preview Nov 17, 2025 9:47am
medusa-docs Ignored Ignored Preview Nov 17, 2025 9:47am
resources-docs Ignored Ignored Preview Nov 17, 2025 9:47am
user-guide Ignored Ignored Preview Nov 17, 2025 9:47am

@changeset-bot
Copy link

changeset-bot bot commented Oct 17, 2025

🦋 Changeset detected

Latest commit: 6fed832

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

This PR includes changesets to release 74 packages
Name Type
@medusajs/promotion Patch
@medusajs/dashboard Patch
@medusajs/core-flows Patch
@medusajs/types Patch
@medusajs/medusa Patch
integration-tests-http Patch
@medusajs/admin-bundler Patch
@medusajs/draft-order Patch
@medusajs/framework Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/medusa-oas-cli Patch
@medusajs/test-utils Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/caching Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis 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/region Patch
@medusajs/sales-channel Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-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/oas-github-ci Patch
@medusajs/cli Patch
@medusajs/deps Patch
@medusajs/telemetry Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin 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

@fPolic fPolic changed the title wip: custom campaign attributes feat: custom campaign attributes Oct 20, 2025
@fPolic fPolic marked this pull request as ready for review October 20, 2025 18:34
@fPolic fPolic requested a review from a team as a code owner October 20, 2025 18:34
cursor[bot]

This comment was marked as outdated.

@willbouch
Copy link
Contributor

/snapshot-this

@github-actions
Copy link
Contributor

🚀 A snapshot release has been made for this PR

Test the snapshots by updating your package.json with the newly published versions:

yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]

Latest commit: c6e58e5

@willbouch
Copy link
Contributor

CleanShot 2025-10-21 at 08 08 28@2x I think it could be useful to give an example here when the custom attribute switch is toggled? Maybe a small use case would be great? I assume I could put `customer_name` in there?

cursor[bot]

This comment was marked as outdated.

})

// TODO: can we move this inside when-then
const customCampaignBudgetAttributesHook = createHook(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

self-review: would be good to move this inside "when" block so this is not executed for already completed carts

@cursor
Copy link

cursor bot commented Oct 23, 2025

Bug: Budget Hook Executes Unnecessarily

The custom campaign budget attributes hook is created outside the when("create-order", ...) conditional block, which means it will execute even for carts that are already completed. As mentioned in the PR discussion and the TODO comment at line 147, this should be moved inside the "when" block to avoid unnecessary execution for already completed carts.

Fix in Cursor Fix in Web

@cursor
Copy link

cursor bot commented Oct 23, 2025

Bug: Unnecessary Hook Execution in Complete-Cart Workflow

The customCampaignBudgetAttributesHook executes unconditionally in the complete-cart workflow. Since its result is only used when creating a new order, this causes unnecessary processing and performance overhead for already completed carts.

Fix in Cursor Fix in Web

cursor[bot]

This comment was marked as outdated.

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.

3 participants