fix(currency,payment,pricing,region,order,store,cart,core-flows,medusa,utils): repo wide currency_code normalization#13975
Conversation
🦋 Changeset detectedLatest commit: d4e784e The changes in this PR will be included in the next version bump. This PR includes changesets to release 77 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 9 Skipped Deployments
|
adrien2p
left a comment
There was a problem hiding this comment.
I believe we are missing a migration script to update all currency code in the database that are not lower cased no?
Oh forgot about that, will include it. |
|
@adrien2p Hey could you check the migration script? We basically need to migrate |
adrien2p
left a comment
There was a problem hiding this comment.
Should we also check other modules that are using currency_code? this pr primarely focuse on the pricing and it might be the objective but just want to throw it outloud
packages/medusa/src/migration-scripts/migrate-normalize-currency-codes-normalization.ts
Outdated
Show resolved
Hide resolved
packages/modules/pricing/integration-tests/__tests__/services/pricing-module/price-set.spec.ts
Show resolved
Hide resolved
I checked all other modules, and the problematic one is the Pricing module. For other usages, what I did is replace the direct manipulation with the new common dedicated util |
I was more thinking of cart, order, payment etc, they dont need that or it was in a separate pr? |
|
@adrien2p With the latest update i did to the test, this would now be breaking right? Since existing filters using The thing is tricky, since i know we can hook the normalization probably in |
I can see two options:
wdyt? |
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
|
This PR was closed because it has been stalled for 5 days with no activity. |
|
Thank you for your contribution! After reviewing this PR, there is one open concern that needs to be resolved before we can move forward: Required changes:
Notes:
|
Summary
What — What changes are introduced in this PR?
Introduces new util function
normalizeCurrencyCodeto be used across the project were currency codes are stored and used for filters. Replaces existent isolated normalizations with the function and adds the missing normalization when handling currency codes in the PricingModule.Why — Why are these changes relevant or necessary?
The objective is to have consistency across currency code handling and avoid potential bugs for storing the currency codes as uppercase in some places and lowercase in others.
How — How have these changes been implemented?
New
normalizeCurrencyCodefunction acts as the centralized place to normalize the currency codes and should be used whenever storing and or searching a currency code.Testing — How have these changes been tested, or how can the reviewer test the feature?
Added unit tests for the function + updated existent integration tests.
Examples
Provide examples or code snippets that demonstrate how this feature works, or how it can be used in practice.
This helps with documentation and ensures maintainers can quickly understand and verify the change.
// Example usageChecklist
Please ensure the following before requesting a review:
yarn changesetand follow the promptsAdditional Context
Add any additional context, related issues, or references that might help the reviewer understand this PR.
fixes #13956
Note
Centralizes currency code lowercasing via
normalizeCurrencyCode, applies it across services and queries, adds a DB migration to lowercase existing data, and updates tests to expect lowercase codes.normalizeCurrencyCode(lowercases codes) with unit tests and export.packages/medusa/src/migration-scripts/migrate-normalize-currency-codes-normalization.tslowercasescurrency_codeincart,payment_collection,payment_session,payment,order,order_transaction,price,region,store_currency.calculatePrices, service price hashing/upsert/constraints), propagate lowercase in price lists/sets/preferences.currency_codeon order creation and order transactions.currency_code; trim/name handling unchanged.supported_currencies[].currency_codeon create/update.normalizeCurrencyCodeforvariant_price_*parsing.codefilter in list/retrieve.currency_codethroughout (pricing, payment, indexing/search).Written by Cursor Bugbot for commit b07bb4e. This will update automatically on new commits. Configure here.