Skip to content
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

fix: Handle region updates on cart (1/n) #9369

Merged
merged 19 commits into from
Oct 4, 2024
Merged

Conversation

olivermrbl
Copy link
Contributor

@olivermrbl olivermrbl commented Sep 29, 2024

What

On cart creation:

  • If region only has one country -> create cart with country code

On cart updates:

  • If shipping address country code is provided in input ->
    • If cart region doesn't include that country -> throw
    • If cart includes the country -> update shipping address
  • If region is provided in input and is different from the one currently on the cart ->
    • If there is a shipping address on the cart -> clear the address
      • If the region only has one country -> set country code of address
    • If there is not a shipping address on the cart ->
      • If the region only has one country -> set country code of address

Closes CC-545

Copy link

changeset-bot bot commented Sep 29, 2024

⚠️ No Changeset found

Latest commit: 9cf1653

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Sep 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 9:40am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Oct 4, 2024 9:40am
api-reference-v2 ⬜️ Ignored (Inspect) Visit Preview Oct 4, 2024 9:40am
docs-ui ⬜️ Ignored (Inspect) Visit Preview Oct 4, 2024 9:40am
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Oct 4, 2024 9:40am
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Oct 4, 2024 9:40am
resources-docs ⬜️ Ignored (Inspect) Visit Preview Oct 4, 2024 9:40am

@@ -316,6 +316,49 @@ medusaIntegrationTestRunner({
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are all tests of the HTTP layer, so I'll move these to integration-tests/http before merging. Keeping them as is, because the diff would otherwise be off

@olivermrbl olivermrbl changed the title fix: Region cart management fix: Handle region updates on cart (1/n) Oct 1, 2024
@olivermrbl olivermrbl marked this pull request as ready for review October 1, 2024 18:46
@olivermrbl olivermrbl requested a review from a team as a code owner October 1, 2024 18:46
Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
Copy link
Contributor

@riqwan riqwan left a comment

Choose a reason for hiding this comment

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

noice!

Comment on lines +320 to +324
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
countries: ["us"],
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
countries: ["us"],
})
const region = (await api.post(
`/admin/regions`,
{
name: "US",
currency_code: "usd",
countries: ["us"],
},
adminHeaders
)).data.region

Comment on lines +799 to 803
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
automatic_taxes: false,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const region = await regionModule.createRegions({
name: "US",
currency_code: "usd",
automatic_taxes: false,
})
const region = (await api.post(
`/admin/regions`,
{
name: "US",
currency_code: "usd",
automatic_taxes: false
},
adminHeaders
)).data.region

@kodiakhq kodiakhq bot merged commit a114f90 into develop Oct 4, 2024
23 checks passed
@kodiakhq kodiakhq bot deleted the fix/update-region-on-cart branch October 4, 2024 11:33
panalgin pushed a commit to vennyx-org/medusa that referenced this pull request Oct 7, 2024
**What**

On cart creation:
- If region only has one country -> create cart with country code

On cart updates:
- If shipping address country code is provided in input ->
  - If cart region doesn't include that country -> throw
  - If cart includes the country -> update shipping address
- If region is provided in input and is different from the one currently on the cart -> 
  - If there is a shipping address on the cart -> clear the address
    - If the region only has one country -> set country code of address
  - If there is not a shipping address on the cart ->
    - If the region only has one country -> set country code of address


Closes CC-545
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.

4 participants