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): Line items operations #6066

Merged
merged 15 commits into from
Jan 16, 2024
Merged

Conversation

olivermrbl
Copy link
Contributor

@olivermrbl olivermrbl commented Jan 11, 2024

awaiting #6012

What

Add line items

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

Update line items

// selector based approach
await cartModuleService.updateLineItems({ variant_id: "var_1234" }, { thumbnail: "test" })
await cartModuleService.updateLineItems("line_1234", { title: "test", unit_price: 100 })
// bulk selector based approach
await cartModuleService.updateLineItems([{ selector: { cart_id: "cart_1234" } , data: { title: "test", unit_price: 100 }}])

Remove line items

// selector based approach
await cartModuleService.removeLineItems({ variant_id: "var_1234" })
await cartModuleService.removeLineItems("cali_1234")
await cartModuleService.removeLineItems(["cali_1234", "cali_4321"])

The first is a selector-based removal. In this example, we want to remove all line items that have variant_id=var_1234. Imagine you accidentally published a product that was not supposed to go live for another two months. The selector-based approach handles this scenario very elegantly.


Additionally, the PR comes with tests for all and a few typings updates.

Copy link

changeset-bot bot commented Jan 11, 2024

⚠️ No Changeset found

Latest commit: a709906

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

packages/types/src/cart/mutations.ts Show resolved Hide resolved
packages/cart/src/services/line-item.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/line-item.ts Outdated Show resolved Hide resolved
packages/types/src/cart/service.ts Outdated Show resolved Hide resolved
packages/cart/src/models/line-item.ts Outdated Show resolved Hide resolved
packages/cart/src/repositories/line-item.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/line-item.ts Outdated Show resolved Hide resolved
packages/cart/src/types/line-item.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues left a comment

Choose a reason for hiding this comment

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

Will you update all the joiner-config file reflecting all the entities when the module is done?

@olivermrbl
Copy link
Contributor Author

olivermrbl commented Jan 16, 2024

Will you update all the joiner-config file reflecting all the entities when the module is done?

@carlos-r-l-rodrigues, yes – my idea was to add all the "configurational" bits and pieces as well as the migration in the end to avoid having to re-review it numerous times as things change. OK with you?

@adrien2p
Copy link
Member

I think it is ok. I quite like the incremental implementation approach you have used so far. But indeed, we should not forget some part in the end. Maybe when doing this approach we should have a check list of what should be included in the module development process. Cause it is nice to have smaller reviews, but it is also easy to forget something in between the first and last pr

packages/cart/src/models/line-item.ts Outdated Show resolved Hide resolved
packages/cart/src/models/line-item.ts Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/types/line-item.ts Outdated Show resolved Hide resolved
packages/types/src/cart/common.ts Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
packages/cart/src/services/cart-module.ts Outdated Show resolved Hide resolved
@olivermrbl
Copy link
Contributor Author

Any final comments?

Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

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

LGTM strong work 💪

@olivermrbl olivermrbl merged commit a5e8bf0 into develop Jan 16, 2024
16 checks passed
@olivermrbl olivermrbl deleted the feat/cart-module-item-ops branch January 16, 2024 14:44
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