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

feat(cart): Shipping methods operations #6075

Closed
wants to merge 85 commits into from

Conversation

olivermrbl
Copy link
Contributor

@olivermrbl olivermrbl commented Jan 12, 2024

Awaiting #6066

What

Add shipping methods

There are three ways to add shipping methods to a cart; the operations differ slightly in behavior:

await cartModuleService.addShippingMethods("cart_1234", [{ unit_price: 100 }])
await cartModuleService.addShippingMethods([{ unit_price: 100, cart_id: "cart_1234" }])
await cartModuleService.addShippingMethods({ unit_price: 100, cart_id: "cart_1234" })

The first comes with cart validation, while as the two others do not.

In the two latter methods, we naively attempt to add one or more shipping methods to carts with whatever data you have passed. In case you are missing required data (e.g. cart_id or unit_price), or the cart of the passed cart_id does not exist, we throw a generic error:

Failed to create shipping methods. Ensure you are passing valid data, including valid cart id(s)

Remove shipping methods

There are three ways to remove shipping methods from a cart:

await cartModuleService.removeShippingMethods({ provider_id: "manual" })
await cartModuleService.removeShippingMethods("casm_1234")
await cartModuleService.removeShippingMethods(["casm_1234", "casm_4321"])

The first is a selector-based removal. In this example, we want to remove all shipping methods that have provider_id=manual.

Copy link

changeset-bot bot commented Jan 12, 2024

⚠️ No Changeset found

Latest commit: 1e3f57e

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 Jan 12, 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 Jan 16, 2024 4:47pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2024 4:47pm
docs-ui ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2024 4:47pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2024 4:47pm

@@ -47,7 +50,7 @@ export default class LineItem {
@Property({ columnType: "text", nullable: true })
thumbnail?: string | null

@Property({ columnType: "text" })
@Property({ columnType: "integer" })
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to support float as quantity.

Copy link
Member

Choose a reason for hiding this comment

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

should we use numeric and serializer?

@@ -31,7 +31,7 @@
"prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json",
"build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json",
"test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts",
"test:integration": "jest --runInBand --forceExit -- integration-tests/**/__tests__/**/*.ts",
"test:integration": "jest --runInBand --forceExit -- integration-tests/__tests__/services/cart-module/*.ts",
Copy link
Member

Choose a reason for hiding this comment

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

todo: should we revert that?

@@ -47,7 +50,7 @@ export default class LineItem {
@Property({ columnType: "text", nullable: true })
thumbnail?: string | null

@Property({ columnType: "text" })
@Property({ columnType: "integer" })
Copy link
Member

Choose a reason for hiding this comment

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

should we use numeric and serializer?

@olivermrbl
Copy link
Contributor Author

Closing in favor of #6101

@olivermrbl olivermrbl closed this Jan 16, 2024
@olivermrbl
Copy link
Contributor Author

Addressed all comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants