-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix(currency,payment,pricing,region,order,store,cart,core-flows,medusa,utils): repo wide currency_code normalization #13975
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
Merged
shahednasser
merged 28 commits into
develop
from
fix/currency-code-repo-wide-normalization
Apr 10, 2026
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
45aca2a
Unified utility normalizeCurrencyCode function
NicolasGorga 0e4e1c4
Use new utility function to replace current isolated currency code no…
NicolasGorga 57dc443
Update arg type
NicolasGorga 41797b6
Add missing currency code normalization in pricing module
NicolasGorga 27b8795
New util function tests
NicolasGorga 5a11104
Update previous pricing module tests to include lowercased currency c…
NicolasGorga c2e2852
Add changeset
NicolasGorga a9981bb
Update arg type and throw if something else is provided
NicolasGorga 02a3a51
Migration script v1
NicolasGorga de16984
Include in transaction for compensation
NicolasGorga 20e272f
Merge branch 'develop' into fix/currency-code-repo-wide-normalization
NicolasGorga 6400928
Merge branch 'develop' into fix/currency-code-repo-wide-normalization
NicolasGorga 3762010
Remove unnecessary workflow, execute knex directly inside script
NicolasGorga d63b9fc
Review fixes
NicolasGorga 9c7d26f
Add missing currency_code normalization to modules
NicolasGorga f0013d2
Avoid overriding currency_code when not provided
NicolasGorga 0942b4d
Update tests
NicolasGorga 95330ad
Updated changeset
NicolasGorga dfc0256
Update script to normalize all potentially affected tables
NicolasGorga 922aba2
Keep one changeset
NicolasGorga ba64c97
Merge branch 'develop' into fix/currency-code-repo-wide-normalization
NicolasGorga 568d7d9
Merge branch 'develop' into fix/currency-code-repo-wide-normalization
NicolasGorga ec56874
Merge remote-tracking branch 'origin/develop' into fix/currency-code-…
NicolasGorga dc5c936
Update tests
NicolasGorga b07bb4e
Update test
NicolasGorga f00689e
Merge branch 'develop' into fix/currency-code-repo-wide-normalization
NicolasGorga ac96c89
Merge branch 'develop' into fix/currency-code-repo-wide-normalization
NicolasGorga d4e784e
Migration to normalize prices ingested by index module
NicolasGorga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| "@medusajs/currency": patch | ||
| "@medusajs/core-flows": patch | ||
| "@medusajs/payment": patch | ||
| "@medusajs/pricing": patch | ||
| "@medusajs/region": patch | ||
| "@medusajs/order": patch | ||
| "@medusajs/store": patch | ||
| "@medusajs/cart": patch | ||
| "@medusajs/utils": patch | ||
| "@medusajs/medusa": patch | ||
| --- | ||
|
|
||
| fix(currency,payment,pricing,region,order,store,cart,core-flows,medusa,utils): repo wide currency_code normalization | ||
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
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
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
21 changes: 21 additions & 0 deletions
21
packages/core/utils/src/common/__tests__/normalize-currency-code.spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { normalizeCurrencyCode } from "../normalize-currency-code" | ||
|
|
||
| describe("normalizeCurrencyCode", () => { | ||
| it("returns lowercased currency code", () => { | ||
| const uppercased = "USD" | ||
| const result = normalizeCurrencyCode(uppercased) | ||
|
|
||
| expect(result).toEqual("usd") | ||
| }) | ||
|
|
||
| it("throws when value is not a string", () => { | ||
| const errorMessage = "Currency code needs to be a string" | ||
|
|
||
| expect(() => { | ||
| normalizeCurrencyCode(1 as unknown as string) | ||
| }).toThrow(errorMessage) | ||
| expect(() => { | ||
| normalizeCurrencyCode(undefined as unknown as string) | ||
| }).toThrow(errorMessage) | ||
| }) | ||
| }) |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { MedusaError, MedusaErrorTypes } from "./errors" | ||
| import { isString } from "./is-string" | ||
|
|
||
| /** | ||
| * Normalizes `currencyCode` by transforming it to lowercase | ||
| */ | ||
| export function normalizeCurrencyCode(currencyCode: string) { | ||
| if (!isString(currencyCode)) { | ||
| throw new MedusaError(MedusaErrorTypes.INVALID_ARGUMENT, "Currency code needs to be a string") | ||
| } | ||
|
|
||
| return currencyCode.toLowerCase() | ||
| } |
38 changes: 38 additions & 0 deletions
38
packages/medusa/src/migration-scripts/migrate-normalize-currency-codes-normalization.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { ContainerRegistrationKeys } from "@medusajs/framework/utils" | ||
| import { ExecArgs } from "@medusajs/types" | ||
|
|
||
| export default async function migrateNormalizeCurrencyCodes({ | ||
| container, | ||
| }: ExecArgs) { | ||
| const knex = container.resolve(ContainerRegistrationKeys.PG_CONNECTION) | ||
|
|
||
| await knex.transaction(async (trx) => { | ||
| const tables = [ | ||
| "cart", | ||
| "payment_collection", | ||
| "payment_session", | ||
| "payment", | ||
| "order", | ||
| "order_transaction", | ||
| "price", | ||
| "region", | ||
| "store_currency", | ||
| ] | ||
|
|
||
| for (const table of tables) { | ||
| await trx(table) | ||
| .whereNotNull("currency_code") | ||
| .update({ | ||
| currency_code: knex.raw("LOWER(currency_code)"), | ||
| }) | ||
| } | ||
|
|
||
| await trx.raw(` | ||
| UPDATE index_data | ||
| SET data = jsonb_set(data, '{currency_code}', to_jsonb(LOWER(data->>'currency_code'))) | ||
| WHERE name = 'Price' | ||
| AND data->>'currency_code' IS NOT NULL | ||
| AND data->>'currency_code' <> LOWER(data->>'currency_code') | ||
| `) | ||
| }) | ||
| } |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.